的WinForms - 调整上的CheckedListBox垂直滚动条的宽度 [英] Winforms - Adjust width of vertical scrollbar on CheckedListBox

查看:1589
本文介绍了的WinForms - 调整上的CheckedListBox垂直滚动条的宽度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有我的窗体上的CheckListBox但我想使滚动条较宽,因为用户在使用触摸屏而不是鼠标。

I have a CheckListBox on my form but I want to make the scrollbar wider as users are using touch screens not a mouse.

如何更改滚动条?宽度

编辑:我说的是垂直滚动条

推荐答案

要改变滚动条的物理尺寸,看的这个

To change the physical size of the scrollbar, see this.

这来自于以下页面:的水平滚动列表框中。我修改它的WinForms和它的工作对我来说:

This came from the following page: Horizontal Scrollbar in ListBox. I modified it for Winforms and it worked for me:

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);
      }
   }
}

这篇关于的WinForms - 调整上的CheckedListBox垂直滚动条的宽度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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