c# - Winforms - 调整 CheckedListBox 上垂直滚动条的宽度

标签 c# winforms checkedlistbox

我的表单上有一个 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/

相关文章:

c# - 无法连接到集线器类

c# - 为什么我的文件从 Angular 上传到 .NET core Web api 不起作用?

c# - 从 C# 控制相机设备

c# - 如何在winform中只验证数字?

c# - 我应该选择什么数据库?

c# - 如何在选中的列表框中获取当前选中的项目

c# - 具有合并单元格的 GridView

c# - 不支持异常 : LINQ to Entities does not recognize the method

c# - 如何在用户选中复选框时仅动态计算 CheckedListBox 中选中的项目?

c# - CheckedListBox 数据绑定(bind)到项目的选中状态