.NET Compact framework - make scrollbars wider

前端 未结 4 1224
甜味超标
甜味超标 2021-01-13 18:51

Is there some way, how to make scrollbar wider in winforms for .net compact framework? I want to be application finger-friendly, but the scrollbars are very narrow for peopl

4条回答
  •  灰色年华
    2021-01-13 19:28

    You can use reflection. Inspired by this link, my code would look something like this. (It may be a bit too careful, but I am not so sure how generic this would be with reflection. E.g. the VScrollBar is not found for a TextBox on this form.)

    using System.Reflection;
        //...
        public static void SetVerticalScrollbarWidth(Control c, int w)
        {
            try
            {
                var lGridVerticScrollBar = GetNonPublicFieldByReflection(c, "m_sbVert");
                lGridVerticScrollBar.Width = w;
            }
            catch
            {
                // fail soft
            }
        }
    
        public DataGridForm()
        {
            SetVerticalScrollbarWidth(dataGrid, 30);
        }
    
        public static T GetNonPublicFieldByReflection(object o, string name)
        {
            if (o != null)
            {
                Type lType = o.GetType();
                if (lType != null)
                {
                    var lFieldInfo = lType.GetField(name, BindingFlags.NonPublic | BindingFlags.GetField | BindingFlags.Instance);
                    if (lFieldInfo != null)
                    {
                        var lFieldValue = lFieldInfo.GetValue(o);
                        if (lFieldValue != null)
                        {
                            return (T)lFieldValue;
                        }
                    }
                }
            }
            throw new InvalidCastException("Error in GetNonPublicFieldByReflection for " + o.ToString() );
        }
    

提交回复
热议问题