private void InitializeDrawMode()
{
this.fCustomDraw = Application.RenderWithVisualStyles && TabRenderer.IsSupported;
this.SetStyle(ControlStyles.UserPaint | ControlStyles.AllPaintingInWmPaint |
ControlStyles.OptimizedDoubleBuffer, this.fCustomDraw);
this.UpdateStyles();
if (this.fCustomDraw) //custom drawing will be used
{
if (this.fSysFont == IntPtr.Zero) this.fSysFont = this.Font.ToHfont();
NativeMethods.SendMessage(this.Handle, NativeMethods.WM_SETFONT, this.fSysFont, (IntPtr)1);
}
else //default drawing will be used
{
/* Note that in the SendMessage call below we do not delete HFONT passed to control. If we do
* so we can see ugly system font. I think in this case the control deletes this font by itself
* when disposing or finalizing.*/
NativeMethods.SendMessage(this.Handle, NativeMethods.WM_SETFONT, this.Font.ToHfont(), (IntPtr)1);
//but we need to delete the font(if any) created when being in custom drawing mode
if (this.fSysFont != IntPtr.Zero)
{
NativeMethods.DeleteObject(this.fSysFont);
this.fSysFont = IntPtr.Zero;
}
}
}