Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
572 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 Reply

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...