我需要MessageForm
在主窗体 ( ) 上显示一个对话框窗体 ( ParentForm
)。MessageForm
包含一个面板 ( ),我在其mainPanel
上添加了一些运行时控件(关闭按钮和许多标签和链接标签)。MessageForm 有一个特定的行为:它必须是半透明的,并且在显示时,ParentForm 必须是非活动的:
public MessageForm(FrmGlobalStatus _parent)
{
InitializeComponent();
this.TransparencyKey = this.BackColor;
}
protected override void OnPaintBackground(PaintEventArgs pe)
{
var hb = new HatchBrush(HatchStyle.Percent50,
System.Drawing.ColorTranslator.FromHtml(HATCH_BACK_COLOR),
this.TransparencyKey);
pe.Graphics.FillRectangle(hb, this.DisplayRectangle);
}
private void mainPanel_Paint(object sender, PaintEventArgs pe)
{
using (System.Drawing.Pen p = new Pen(new SolidBrush(this.BorderColor)))
{
if (borderRadius > 0)
{
DrawRoundRect(pe.Graphics, p, 0, 0, mainPanel.Width - 1, mainPanel.Height - 1, borderRadius, this.FillColor);
}
else
{
pe.Graphics.DrawRectangle(p, 0, 0, mainPanel.Width - 1, mainPanel.Height - 1);
}
}
}
显示 MessageForm 的函数:
public void Show()
{
LinkLabel newLinkLabel;
Label newLabel;
int lastItemBottom = 0;
if (Items.Count > 0)
{
for (int i = 0; i < Items.Count; i++)
{
if (Items[i].LinkAreaLength != 0)
{
newLinkLabel = new LinkLabel();
newLinkLabel.Location = new Point(LINKLABEL_H_MARGIN, LINKLABEL_V_MARGIN + i * LINKLABEL_STEP);
lastItemBottom = newLinkLabel.Bottom;
newLinkLabel.BackColor = Color.Transparent;
newLinkLabel.Text = Items[i].Text;
newLinkLabel.LinkColor = LinkDefaultColor;
newLinkLabel.ActiveLinkColor = LinkActiveColor;
newLinkLabel.AutoSize = true;
newLinkLabel.Links.Add(Items[i].LinkAreaStart, Items[i].LinkAreaLength, Items[i].URL);
newLinkLabel.VisitedLinkColor = LinkVisitedColor;
newLinkLabel.Name = LINK_LABEL_FAMILY + i.ToString();
newLinkLabel.LinkClicked += new LinkLabelLinkClickedEventHandler(LinkClicked);
newLinkLabel.MouseHover += new EventHandler(Link_MouseHover);
newLinkLabel.MouseLeave += new EventHandler(Link_MouseLeave);
//for max label length calculation
labelsWidth.Add(Convert.ToInt16((newLinkLabel.CreateGraphics().MeasureString(newLinkLabel.Text, newLinkLabel.Font)).Width));
this.mainPanel.Controls.Add(newLinkLabel);
newLinkLabel.BringToFront();
}
else
{
newLabel = new Label();
newLabel.Location = new Point(LINKLABEL_H_MARGIN, LINKLABEL_V_MARGIN + i * LINKLABEL_STEP);
lastItemBottom = newLabel.Bottom;
newLabel.BackColor = Color.Transparent;
newLabel.Text = Items[i].Text;
newLabel.Name = LABEL_FAMILY + i.ToString();
newLabel.AutoSize = true;
//for max label length calculation
labelsWidth.Add(Convert.ToInt16((newLabel.CreateGraphics().MeasureString(newLabel.Text, newLabel.Font)).Width));
this.mainPanel.Controls.Add(newLabel);
newLabel.BringToFront();
}
}
//centering the mainPanel on MessageForm
mainPanel.Width = BOX_WIDTH;
mainPanel.Height = lastItemBottom + 2;// +LINKLABEL_V_MARGIN;
mainPanel.Location = new Point((Width - mainPanel.Width) / 2, (Height - mainPanel.Height) / 2);
ShowDialog(parent);
}
}
LinkLabel
“项目”是已经包含标签和控件的所有文本的特定结构的列表。好吧,现在的问题是:当我从 调用Show
函数时ParentForm
,我MessageForm
的在闪烁,这足以让眼睛感到不安。我怎样才能消除这种闪烁?