Remove horizontal scrollbar in a ListView
https://stackoverflow.com/a/2500089/1908746
My take:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public const int GWL_STYLE = -16; | |
public const int WS_HSCROLL = 0x00100000; | |
public const int WS_VSCROLL = 0x00200000; | |
[ DllImport( "user32.dll", EntryPoint = "GetWindowLong", CharSet = CharSet.Auto ) ] | |
public static extern IntPtr GetWindowLong32( IntPtr hWnd, int nIndex ); | |
[ DllImport( "user32.dll", EntryPoint = "GetWindowLongPtr", CharSet = CharSet.Auto ) ] | |
public static extern IntPtr GetWindowLongPtr64( IntPtr hWnd, int nIndex ); | |
[ DllImport( "user32.dll", EntryPoint = "SetWindowLong", CharSet = CharSet.Auto ) ] | |
public static extern IntPtr SetWindowLongPtr32( IntPtr hWnd, int nIndex, int dwNewLong ); | |
[ DllImport( "user32.dll", EntryPoint = "SetWindowLongPtr", CharSet = CharSet.Auto ) ] | |
public static extern IntPtr SetWindowLongPtr64( IntPtr hWnd, int nIndex, int dwNewLong ); | |
public static int GetWindowLong( IntPtr hWnd, int nIndex ) | |
{ | |
if( IntPtr.Size == 4 ) | |
{ | |
return (int)GetWindowLong32( hWnd, nIndex ); | |
} | |
else | |
{ | |
return (int)(long)GetWindowLongPtr64( hWnd, nIndex ); | |
} | |
} | |
public static int SetWindowLong( IntPtr hWnd, int nIndex, int dwNewLong ) | |
{ | |
if( IntPtr.Size == 4 ) | |
{ | |
return (int)SetWindowLongPtr32( hWnd, nIndex, dwNewLong ); | |
} | |
else | |
{ | |
return (int)(long)SetWindowLongPtr64( hWnd, nIndex, dwNewLong ); | |
} | |
} | |
protected override void WndProc( ref Message m ) | |
{ | |
switch( m.Msg ) | |
{ | |
case WM_NCCALCSIZE: | |
{ | |
var style = (int)GetWindowLong( this.Handle, GWL_STYLE ); | |
if( ( style & WS_HSCROLL ) == WS_HSCROLL ) | |
{ | |
SetWindowLong( Handle, GWL_STYLE, style & ~WindowsNative.WS_HSCROLL ); | |
} | |
break; | |
} | |
} | |
base.WndProc( ref m ); | |
} |
Comments
Post a Comment