Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Controls not being drawn at the same time

I have a form which I'm bringing up using ShowDialog which contains a couple of text boxes, labels and a button. The problem I'm having is that the text boxes are being drawn before the form itself and the other controls are drawn.

I am overriding the OnPaint method I'm not sure if this could be causing the problem:

protected override void OnPaint(PaintEventArgs e)
{
    ControlPaint.DrawBorder(e.Graphics, e.ClipRectangle, Color.Black, ButtonBorderStyle.Solid);
    base.OnPaint(e);
}

It's only a slight delay but it's visible and annoying. Thank you.

The form is double buffered by the way.

EDIT: I have pinpointed the issue to be the fact that the form does not have a FormBorderStyle. With the FormBorderStyle set to Sizable, this issue does not occur. However please note that having FormBorderStyle.None as my border style is necessary, so I have not found a solution yet.

like image 741
Jurgen Camilleri Avatar asked Nov 13 '22 06:11

Jurgen Camilleri


1 Answers

Try adding this to the dialog box form:

    protected override CreateParams CreateParams
    {
        get
        {
            // Activate double buffering at the form level.  All child controls will be double buffered as well.

            CreateParams cp = base.CreateParams;

            cp.ExStyle |= 0x02000000;   // WS_EX_COMPOSITED

            return cp;
        }
    }
like image 194
Gojira Avatar answered Nov 14 '22 23:11

Gojira