更改垂直和水平ScrollBarHeight [英] Change Vertical and Horizontal ScrollBarHeight

查看:86
本文介绍了更改垂直和水平ScrollBarHeight的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何更改datagridview自动滚动条的宽度和高度?
如何更改组合框控件滚动条的宽度?

最好的问候,
Theingi Win.

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.

推荐答案

通过Google搜索发现了此内容:

Found this with a google search:

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.


总结评论:

WINFORMS!
To summaries the comments:

WINFORMS!


滚动条是由控件以非常低的级别绘制的,通常使用操作系统中设置的指标.因为标准Winform控件没有可覆盖系统指标的属性,所以您需要对DataGridView控件进行子类化,并提供自己的低级绘制方法.

即使使用简单的控制,这也是一个复杂的过程.对于像DataGridView这样的非常复杂的控件,将需要进行大量工作并且仅提供最小的外观更改.我认为这并不是一项很好的投资.

我认为WPF更为灵活,但WinForms却....除非您有很多时间需要花时间并且对用户绘制的控件有深入的了解,否则答案是您不能."
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."


这篇关于更改垂直和水平ScrollBarHeight的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆