我正在TabControl用 C# 编写一个自定义绘制的类。
我的InitializeComponent方法(由构造函数调用)的行为如下,以便自定义绘制控件:
private void InitializeComponent()
{
    this.SetStyle(ControlStyles.UserPaint, true);
    this.SetStyle(ControlStyles.AllPaintingInWmPaint, true);
    this.SetStyle(ControlStyles.ResizeRedraw, true);
    this.SetStyle(ControlStyles.OptimizedDoubleBuffer, true);
    this.UpdateStyles();
    this.DrawMode = TabDrawMode.OwnerDrawFixed;
}
TabControl 使用两个矩形表面;
- 其中ClientRectangle包含整个控件
- 这DisplayRectangle是控件中显示TabPage内容的部分
当我想调整 时DisplayRectangle,我已经覆盖了它的属性(仅限获取):
public override Rectangle DisplayRectangle
{
    get
    {
        return this.displayRectangle; // points to a local rectangle, rather than base.DisplayRectangle
    }
}
然后我重写OnSizeChanged了以更新显示矩形大小:
protected override void OnSizeChanged(EventArgs e)
{
    base.OnSizeChanged(e);
    this.displayRectangle = this.ClientRectangle;
    this.displayRectangle.Y += this.ItemSize.Height + 4;
    this.displayRectangle.Height -= this.ItemSize.Height + 4;
}
我遇到的问题是,当TabControl重新调整大小时,DisplayRectangle工作并相应地重新调整大小,但是当父窗体最大化/最小化(从而改变控件大小)时,显示矩形不会更新。
我应该如何解决这个问题?是否有手动管理显示矩形的指南?