4

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 people with not-small fingers.

EDIT:

The problem is with built-in scrollbars in components like ListView, DataGrid, etc...

Windows Mobile 6.0, .NET Compact Framework 3.5

Thanks.

TcKs
  • 25,849
  • 11
  • 66
  • 104
  • I don't know the compact framework, but I assume you've checked for a "thickness" property. – ChrisF Jun 08 '09 at 09:19
  • @ChrisF: Where I should search for "thickness" property? – TcKs Jun 08 '09 at 09:40
  • I used "thickness" as you want the "width" property of vertical bars, and the "height" property of horizontal bars. – ChrisF Jun 08 '09 at 09:58
  • Ok, my mistake, I wasn't specific enough. I want to change scrollbar width in components like DataGrid, ListView, etc... – TcKs Jun 08 '09 at 10:22
  • I know of no way to do this on a application specific way. Personally, I'm hoping Silverlight for Mobile fixes some of these UI issues. – Chris Brandsma Jun 08 '09 at 15:40
  • If your application is single-purpose (such as an embedded device in a factory) the solution from `CaptnCrash` works well. – AlainD Sep 05 '17 at 10:37

4 Answers4

2

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

  • 2
    But it affects all applications in device. It can break UI layout of another applications. – TcKs Jun 08 '09 at 09:39
  • Since Scrollbars are Systemwide in Use and not Control specific, you will have to create your own controls with your own scrollbar. –  Jun 08 '09 at 09:57
  • I think I´m wrong, check the ScrollBar Class in System.Windows.Controls.Primitives –  Jun 08 '09 at 10:09
  • Have a look in the System.Windows.Forms namespace. There is a ScrollBar class there. – Tom van Enckevort Jun 08 '09 at 11:18
  • @tmolog: I know System.Windows.Forms.ScrollBar class. But what should do I with it? – TcKs Jun 08 '09 at 11:59
1

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.

Febraiz
  • 31
  • 4
1

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...

  • 1
    Did you try it? Did you solved the problem with overpainted rows? – TcKs Feb 10 '11 at 09:05
  • 1
    How about selecting the right type with the Linq's TypeOf: `foreach (VScrollBar lBar in dataGrid.Controls.OfType()) { lBar.Width = w; }` I think that would be much cleaner than just iterating over all controls (or my own answer with reflection) – Yahoo Serious Mar 24 '11 at 11:34
0

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() );
    }
Yahoo Serious
  • 3,728
  • 1
  • 33
  • 37