سؤال

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.

هل كانت مفيدة؟

المحلول

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;
        }
    }
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top