Note that there are some explanatory texts on larger screens.

plurals
  1. POFlickering when showing a translucend custom Form via ShowDialog()
    text
    copied!<p>I need to show a dialog form (<code>MessageForm</code>) over the main Form (<code>ParentForm</code>). The <code>MessageForm</code> contains a panel (<code>mainPanel</code>) on which I add some controls on runtime (the close button and many Labels and LinkLabels). MessageForm has a specific behavior: it must be translucent and, on show, the ParentForm must be inactive:</p> <pre><code>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 &gt; 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); } } } </code></pre> <p>The function that shows the MessageForm:</p> <pre><code>public void Show() { LinkLabel newLinkLabel; Label newLabel; int lastItemBottom = 0; if (Items.Count &gt; 0) { for (int i = 0; i &lt; 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); } } </code></pre> <p>'Items' is alist of specific structures that already contains all the text for Label and <code>LinkLabel</code> controls. Well, now the problem: when I Call the <code>Show</code> function from <code>ParentForm</code>, my <code>MessageForm</code> is flickering, and it is enough visiblie for eyes disturbing. How can I eliminate this flickering? </p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload