.NET Compact framework - make scrollbars wider

落花浮王杯 提交于 2019-12-01 06:28:48

I haven´t checked that, because I have no device but rumor has it that you can change the Size per Regstry Settings:

[HKEY_LOCAL_MACHINE\SYSTEM\GWE]

cyHScr=13 - Default height of horizontal scrollbar

cxVScr=13 - Default width of vertical scrollbar

Kind Regards

Thomas

yossi abramovitz

Here is my take on this:

  1. .net (and the cf version) gives you access to the control collection of the datagrid/listbox... so you can get to the control i.e. the scrollbar via the control array. For instance mydatagrid.Contorls[0] would be the horizontal scrollbar. This can be done byname maybe I'll post a more elaborate solution later.
  2. Once you've reached the correct control, it is simply a matter of updating the Height property of the scrollbar, right?...wrong!! Remember the scrollbar is an element within the datagrid/listbox...therefore it's original location (painting position) is set at a point which would enable the element to be seen at the height value it was initialized at... so your code will have to deal with the repositioning of the scrollbar location within the original rectangle.

    myDataGrid.Controls[0].Height = myDataGrid.Controls[0].Height + 60;
    myDataGrid.Controls[0].Location = new Point(myDataGrid.Controls[0].Location.X, myDataGrid.Controls[0].Location.Y - 60);
    

Finally things to consider: When you play around with the scrollbar size, you need to remember other parts of the element depend on the scrollbar, for instance if the scrollbar ends up hiding some rows on the grid, they won't be reachable...

VB version:

'Increase size of the Vertical scrollbar of your DataGrid'
For Each vBar As VScrollBar In yourDG.Controls.OfType(Of VScrollBar)()
    vBar.Width = 25
Next

'Increase size of the Horizontal scrollbar of your DataGrid'
For Each hBar As HScrollBar In yourDG.Controls.OfType(Of HScrollBar)()
    hBar.Height = 25
Next

All the thx goes to Yahoo Serious.

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<VScrollBar>(c, "m_sbVert");
            lGridVerticScrollBar.Width = w;
        }
        catch
        {
            // fail soft
        }
    }

    public DataGridForm()
    {
        SetVerticalScrollbarWidth(dataGrid, 30);
    }

    public static T GetNonPublicFieldByReflection<T>(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() );
    }
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!