简体   繁体   中英

C# Windows Forms application showing background when opening new form

I am currently making a full-screen application in C# but I have a bit of a problem. I have a overview form which shows buttons. When you click a button it will open a new form. (Overview form and new form are both full-screen). The problem is when the new form opens it will show nothing for a second (It doesnt really look to good in a full screen application). So does anyone know how to fix this? You can find the code here:

Code for opening new form:

void NewForm(Form form)
{
    form.FormClosing += new FormClosingEventHandler(form_Closed);
    form.Show();
    Hide();
}

void form_Closed(Object sender, EventArgs e)
{
    Show();
}

One of the opened forms:

public AdminPanelForm()
{
     InitializeComponent();
     SetStyle(ControlStyles.UserPaint, true);
     SetStyle(ControlStyles.AllPaintingInWmPaint, true);
     SetStyle(ControlStyles.DoubleBuffer, true);
}

private void AdminPanelForm_Shown(object sender, EventArgs e)
{
     List<User> users = User.GetAllUsers();
     foreach(User user in users)
     {
         ListViewItem lvi = new ListViewItem(user.UserName);
         lvi.SubItems.Add(user.Role);
         listUsers.Items.Add(lvi);
     }
}

private void btnBack_Click(object sender, EventArgs e)
{
    Close();
}

Thanks in Advance!

After form.Show() add form.Update() . Otherwise, the real form redraw will be done with delay. It may be better to call Hide first.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM