开发者

Trackbar Thumb Dimensions

Does anyone know whether it is possible to programmatically determine the dimensions of the thumb of a System.Windows.Forms.TrackBar. (By thumb I mean the bit you drag around!)

I know you can get things like scrollbar widths from the System.Windows.Forms.开发者_如何学PythonSystemInfo class but there doesn't seem to be anything for trackbars.

Thanks.


The thumb size can be obtained by sending the TBM_GETTHUMBRECT message to the TrackBar control. There is no way to do that directly from C#, but you can define the appropriate Win32 structures and p/invoke SendMessage():

[StructLayout(LayoutKind.Sequential)]
public struct RECT
{
     public int Left;
     public int Top;
     public int Right;
     public int Bottom;
}

[DllImport("user32.dll")]
static extern void SendMessage(IntPtr hwnd, uint msg, IntPtr wp, ref RECT lp);

private const uint TBM_GETTHUMBRECT = 0x419;

// Implemented as an extension method.
public static RECT GetThumbRect(this TrackBar trackBar)
{
    RECT rc = new RECT();
    SendMessage(trackBar.Handle, TBM_GETTHUMBRECT, IntPtr.Zero, ref rc);
    return rc;
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜