我正在尝试自定义绘制tabcontrol。 当我使用GetTabRect返回的尺寸绘制标签时,与通常绘制的标签相比,标签的绘制明显更宽。 我以为它试图为图像腾出空间,但我没有为标签定义图像。 为什么GetTabRect返回更大的尺寸?
不知道这是否与它有关,但这里是我如何将它设置为自定义TabControl构造函数中的所有者绘制。
this.SetStyle(ControlStyles.UserPaint | ControlStyles.AllPaintingInWmPaint | ControlStyles.DoubleBuffer | ControlStyles.ResizeRedraw | ControlStyles.SupportsTransparentBackColor, true);I am trying to custom draw a tabcontrol. When I draw the tabs using the dimensions returned by GetTabRect, the tabs are drawn noticeably wider when compared to how they are normally drawn. I thought it was trying to make room for an image, but I have no images defined for the tabs. Why would GetTabRect return a wider size?
Don't know if this has anything to do with it, but here is how I set it to owner draw in the custom TabControl constructor.
this.SetStyle(ControlStyles.UserPaint | ControlStyles.AllPaintingInWmPaint | ControlStyles.DoubleBuffer | ControlStyles.ResizeRedraw | ControlStyles.SupportsTransparentBackColor, true);最满意答案
我在这里找到了一个解决方案: http : //www.codeproject.com/Messages/2707590/Re-Tab-Size.aspx
引用:
当ControlStyle.UserPaint设置为true时,控件不再发送WM_SETFONT消息。 发送FontChange消息所需的代码:
[DllImport("user32.dll")] private static extern IntPtr SendMessage(IntPtr hWnd, int Msg, IntPtr wParam, IntPtr lParam); private const int WM_SETFONT = 0x30; private const int WM_FONTCHANGE = 0x1d; protected override void OnCreateControl() { base.OnCreateControl(); this.OnFontChanged(EventArgs.Empty); } protected override void OnFontChanged(EventArgs e) { base.OnFontChanged(e); IntPtr hFont = this.Font.ToHfont(); SendMessage(this.Handle, WM_SETFONT, hFont, (IntPtr)(-1)); SendMessage(this.Handle, WM_FONTCHANGE, IntPtr.Zero, IntPtr.Zero); this.UpdateStyles(); }I found a solution here: http://www.codeproject.com/Messages/2707590/Re-Tab-Size.aspx
Quote:
When ControlStyle.UserPaint is set to true, the control no longer sends WM_SETFONT messages. The code needed to send the FontChange messages:
[DllImport("user32.dll")] private static extern IntPtr SendMessage(IntPtr hWnd, int Msg, IntPtr wParam, IntPtr lParam); private const int WM_SETFONT = 0x30; private const int WM_FONTCHANGE = 0x1d; protected override void OnCreateControl() { base.OnCreateControl(); this.OnFontChanged(EventArgs.Empty); } protected override void OnFontChanged(EventArgs e) { base.OnFontChanged(e); IntPtr hFont = this.Font.ToHfont(); SendMessage(this.Handle, WM_SETFONT, hFont, (IntPtr)(-1)); SendMessage(this.Handle, WM_FONTCHANGE, IntPtr.Zero, IntPtr.Zero); this.UpdateStyles(); }更多推荐
发布评论