Click here to Skip to main content
15,880,364 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
How can I change datagridview auto scroll bar width and height?
How can I change Combo box control scroll bar width?

Best Regard,
Theingi Win.
Posted
Updated 3-May-11 22:34pm
v2
Comments
Tarun.K.S 4-May-11 4:21am    
In WPF or Winforms?
Theingi Win 4-May-11 5:45am    
In Winforms

Found this with a google search:

C#
public partial class Form1 : Form    
{
    const int LB_GETHORIZONTALEXTENT = 0x0193;   
    const int LB_SETHORIZONTALEXTENT = 0x0194;    
    const long WS_HSCROLL = 0x00100000L;    
    const int SWP_FRAMECHANGED = 0x0020;   
    const int SWP_NOMOVE = 0x0002;   
    const int SWP_NOSIZE = 0x0001;   
    const int SWP_NOZORDER = 0x0004;    
    const int GWL_STYLE = (-16);        

    public Form1()       
    {          
        InitializeComponent();      
        checkedListBox1.HorizontalScrollbar = true;      
        AddStyle(checkedListBox1.Handle, (uint)WS_HSCROLL);  
        SendMessage(checkedListBox1.Handle, LB_SETHORIZONTALEXTENT, 1000, 0);   
    }

    [DllImport("user32.dll")]
    static extern int SendMessage(IntPtr hwnd, int msg, int wParam, int lParam);        

    [DllImport("user32.dll")]       
    static extern uint GetWindowLong(IntPtr hwnd, int index);        

    [DllImport("user32.dll")]   
    static extern void SetWindowLong(IntPtr hwnd, int index, uint value);    

    [DllImport("user32.dll")]   
    static extern bool SetWindowPos(IntPtr hWnd, IntPtr hWndInsertAfter, int X, int Y, int cx, int cy, uint uFlags);    

     private void AddStyle(IntPtr handle, uint addStyle)   
    {
        // Get current window style          
        uint windowStyle = GetWindowLong(handle, GWL_STYLE);       

        // Modify style          
        SetWindowLong(handle, GWL_STYLE, windowStyle | addStyle);           

        // Let the window know of the changes  
        SetWindowPos(handle, IntPtr.Zero, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOZORDER | SWP_NOSIZE | SWP_FRAMECHANGED);   
    }    
} 


Adapt it to your needs/programming style.
 
Share this answer
 
Comments
Gregory Gadow 4-May-11 11:02am    
I didn't realize this was possible: I've been soaking in the Framework too long. Thanks.
Theingi Win 4-May-11 20:20pm    
Thanks! John Simmons
Your answer is good well but i don't want to get like this.I want to extend scroll bar width means when we can change scroll bar width in window theme .I want to get like this, but i don't want to change in window theme i only want to change in my program only.
To summaries the comments:

WINFORMS!
 
Share this answer
 
Scrollbars are drawn by the controls at a very low level, normally using metrics set within the operating system. Because the standard Winform controls do not have properties where you can override the system metrics, you would need to subclass the DataGridView control and supply your own low level drawing methods.

Even with a simple control, this is an involved process. For a very complex control like DataGridView, it would take a huge amount work and provide only minimal aesthetic change. Not really a good investment, in my opinion.

I think WPF is more flexible, but WinForms.... Unless you have a lot of time to burn and a deep understanding of user-drawn controls, the answer is "You can't."
 
Share this answer
 
Comments
#realJSOP 4-May-11 10:29am    
All he needs are the appropriate winapi functions. A simple google search would have revealed these functions to the OP, but, well, you know...
Gregory Gadow 4-May-11 11:00am    
My understanding is that the API changes the system metrics and so would change every scroll bar, not just the control. It has been a very long time since I have done any API stuff, though.
Theingi Win 4-May-11 20:21pm    
Right! Gregory.Gadow
Now i can't do it. :(
I can change only in Window Theme
Thanks! For Your Answer

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900