Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
568 views
in Technique[技术] by (71.8m points)

winforms - Can't set .Net panel to visible

I am designing a multipage windows form using panels.

I'm displaying a login form and validating the button click, and want to hide the login panel and show the main panel.

However, when I click the button, the login panel disappears alright, but the main panel does not appear. since there is nothing to display, the form window shrinks to just the minimize/maximize/close buttons.

Here's the code for the button:

private void btn_login_Click(object sender, EventArgs e)
{
    if (pwdBox.Text == optopwd)
    {
        MessageBox.Show("Good Morning!!");
        loginpanel.Visible = false;
        mainpanel.Visible = true;
    }
    else MessageBox.Show("Incorrect password!");

    pwdBox.Text = "";      
}

Please let me know what I have missed/misunderstood. Thanks!

Edit: Screenshots: Login Screen: http://img641.imageshack.us/img641/9310/loginscreenj.jpg

Empty window: http://img163.imageshack.us/img163/1376/emptyx.jpg

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

The standard mistake is that you accidentally put the mainpanel inside the loginpanel. So when you make loginpanel invisible, the mainpanel can never become visible. This accident is common in the designer, it won't let you put two panels on top of each other. You fix it with View + (Other Windows) + Document Outline. Drag mainpanel and drop it on the form. You'll have to fix the Location property by editing it in the Properties window instead of moving the panel with the mouse.

An entirely different approach is to use a TabControl. Easy in the designer, you just need to hide the tabs at runtime. Code is here.

Or use two UserControls.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...