3

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); 
hrbrmstr
  • 77,368
  • 11
  • 139
  • 205
John_Sheares
  • 1,404
  • 2
  • 21
  • 34

1 Answers1

4

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();
}
John_Sheares
  • 1,404
  • 2
  • 21
  • 34