【发布时间】:2011-02-16 08:45:45
【问题描述】:
我的表单包含一个选项卡控件。在一个选项卡上,我有三个组框。每个分组框的高度必须是选项卡高度的三分之一。
现在我在选项卡控件的布局事件上有这段代码:
// Determine the position of the group panels (gp)
this.SuspendLayout();
int oneThird = (tabPanel.Height - 5) / 3;
if (_currentQuestion != null && _currentQuestion.QuestionTypes == QuestionTypes.Infofield)
{
gpExplanation.Visible = false;
gpFillInHelp.Visible = false;
gpFillInQuestion.Height = oneThird * 3;
}
else
{
gpExplanation.Visible = true;
gpFillInHelp.Visible = true;
gpFillInQuestion.Height = oneThird;
gpExplanation.Height = oneThird;
gpFillInHelp.Height = oneThird;
}
// Determine position of the appointment and achievement group panels
int height = tabPanel.Height - 30;
int half = height / 2;
pnlAppointment.Height = half;
this.ResumeLayout();
我的表单的构造函数中也有这段代码:
// Set styles which prevent screen flickering
this.SetStyle(ControlStyles.OptimizedDoubleBuffer | ControlStyles.AllPaintingInWmPaint | ControlStyles.UserPaint, true);
this.DoubleBuffered = true;
在您看来,设置组框高度的最佳方式是什么?当窗体调整大小时,组框高度必须是面板高度的三分之一。
我还希望尽可能减少屏幕上的闪烁。
【问题讨论】:
-
它们似乎总是保持相同的相对大小,那么为什么不简单地在设计器中设置 Anchor 和/或 Dock 属性呢?您也可以使用 FlowLayoutPanel。
标签: c#