所有者绘制的tabcontrol具有更宽的选项卡(Owner drawn tabcontrol has wider tabs)

编程入门 行业动态 更新时间:2024-10-07 06:51:08
所有者绘制的tabcontrol具有更宽的选项卡(Owner drawn tabcontrol has wider tabs)

我正在尝试自定义绘制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(); }

更多推荐

本文发布于:2023-07-17 10:07:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1142740.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:所有者   选项卡   tabcontrol   Owner   wider

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!