所有者绘制的选项卡控件具有更宽的选项卡

发布于 2024-12-01 01:26:57 字数 452 浏览 6 评论 0原文

我正在尝试自定义绘制选项卡控件。当我使用 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); 

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

泡沫很甜 2024-12-08 01:26:58

我在这里找到了一个解决方案: 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();
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文