我的表单上有一个 CheckListBox,但我想使滚动条更宽,因为用户使用的是触摸屏而不是鼠标。
如何改变滚动条的宽度?
编辑:我说的是垂直滚动条的宽度
最佳答案
要更改滚动条的物理大小,请参阅 this .
这来自以下页面:Horizontal Scrollbar in ListBox .我为 Winforms 修改了它,它对我有用:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Runtime.InteropServices;
namespace CheckedListBoxScrollBarsWidth
{
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);
}
}
}
关于c# - Winforms - 调整 CheckedListBox 上垂直滚动条的宽度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1819462/