The following code uses SPI_SETNONCLIENTMETRICS to change the system width of the scroll bar. Please note that it will change all applications in the system not only by one. You should probably make this a configuration item so that you can change the width to the default if you need to.
[DllImport("user32", CharSet = CharSet.Auto)] private static extern int SystemParametersInfo(int uAction, int uParam, ref NONCLIENTMETRICS lpvParam, int fuWinIni); private const int LF_FACESIZE = 32; [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Auto)] private struct LOGFONT { public int lfHeight; public int lfWidth; public int lfEscapement; public int lfOrientation; public int lfWeight; public byte lfItalic; public byte lfUnderline; public byte lfStrikeOut; public byte lfCharSet; public byte lfOutPrecision; public byte lfClipPrecision; public byte lfQuality; public byte lfPitchAndFamily;
Then you can use this code to see the current value of the scrollbar width
NONCLIENTMETRICS metrics = new NONCLIENTMETRICS(); metrics.cbSize = Marshal.SizeOf(metrics); SystemParametersInfo(SPI_GETNONCLIENTMETRICS, 0, ref metrics, 0); MessageBox.Show(metrics.iScrollWidth.ToString());
Then you can use this code to resize the scrollbar ...
NONCLIENTMETRICS metrics = new NONCLIENTMETRICS(); metrics.cbSize = Marshal.SizeOf(metrics); metrics.iScrollWidth = 17; SystemParametersInfo(SPI_SETNONCLIENTMETRICS, metrics.cbSize, ref metrics, SPIF_SENDCHANGE);
source share