开发者

Borderless form shows borders for a moment when shown inside an mdi container

Update (2011-01-17):

I am creating a form with FormBorderStyle=None inside an MdiContainer. When I show the first form, even if it has already been created, for a fraction of a second it appears with the blue border of a normal form, then it's reverted.

With the following sample, clicking once and again on button1, it will show this behavior from time to time, although it's for a very brief lapse of time, so i guess it will be hard to see in a very fast machine; however, in my production code with 3rd party .net controls, it's shown for a lot more time.

To try this, just create a new project, and a windows form called Form2, add a button to Form1, add the events Form1_Load and button1_Click, and paste the code. Then, click button1 for a while.

public 开发者_C百科partial class Form1 : Form
{
    Form2 form;
    public Form1()
    {
        InitializeComponent();
    }

    private void button1_Click(object sender, EventArgs e)
    {
        form.Visible = !form.Visible;
        form.MdiParent = this;

    }

    private void Form1_Load(object sender, EventArgs e)
    {
        this.IsMdiContainer = true;
        form = new Form2();
        form.FormBorderStyle = FormBorderStyle.None;
    }
}

This is language agnostic, so, please, don't change my tags without a good reason.


If there's something slowing down your main UI thread, Windows will paint the form using default values (At least in the DVM world of Vista/Windows 7) until your thread becomes responsive again. Check to make sure your UI thread isn't waiting on some other threads or doing some heavy processing when the form is first shown.


I had the same issue in my application and I added the following line as the first line in Form-Load Function to fix the problem

this.FormBorderStyle = FormBorderStyle.None;


It may depend wether you are changing the FormBorderStyle on Load, in a constructor, or on Shown. Best to do it in constructor (InitializeComponents method).

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜