I'm working on an app for a mobile device and would like to make a datagrid scrollbar button larger to enhance the touch screen usability. I do not want to alter the system settings windows开发者_运维问答 display properties as this will affect the device as a whole.
Is there an easy way to alter the width of the scrollbar on a datagrid view?
FieldInfo fi = dataGridView1.GetType().GetField( "m_sbVert", BindingFlags.NonPublic | BindingFlags.GetField | BindingFlags.Instance );
( ( VScrollBar ) fi.GetValue( dataGridView1 ) ).Width = 50;
fi = ultraGrid1.GetType().GetField( "m_sbHorz", BindingFlags.NonPublic | BindingFlags.GetField | BindingFlags.Instance );
( ( HScrollBar ) fi.GetValue( ultraGrid1 ) ).Height = 0;
Where 50 is the vertical scrollbar width and 0 is the horizontal scrollbar height.
using System.Reflection;
all at the beginning of your form.
It works for WinCE 5.0
.
i think you'll have to roll your own. Not to worry though, it shouldn't be that hard. i say shouldn't because it's been a while since i've done .NET CF UI (shooting from the hip) but have implemented a custom scroller for a .NET 2.0 touch screen UI.
That said, here's what you need to do:
- Hide the scroll bars in the grid view
- Create a custom control which hosts two buttons, one top, one bottom
- Handle the clicks on those buttons and forward them as scroll up/down calls to the grid view
That's the simple way. You don't get the dragging and stuff but that's rarely useful in such a tiny UI anyway. You could also put in later if you want.
Caveat: The grid view might not have ScrollUp/Down APIs exposed. In that case you'll need to overlay your custom control on top of the grid view which will have the scroll bars shown. You hide the built-in scroll bars with your custom control and instead of calling ScrollUp/Down you post windows messages to the area behind your custom control to "fake" clicks and get the grid view to move around the way you like.
Hmm. i was assuming .NET Compact Framework since you mentioned it's for a mobile device... Is it CF? If not, everything ought to be a little easier.
EDIT
Basic sample of custom grid scrolling here!
精彩评论