Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 507
mankand007 Avatar asked Feb 06 '12 19:02

mankand007


2 Answers

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.

like image 102
Hans Passant Avatar answered Oct 12 '22 20:10

Hans Passant


Looks like your for is automatically resizing. There are 2 properties on the form responsible for auto size:

AutoSize = True;
AutoSizeMode = GrowAndShrink;

If you have the above settings then your form would shrink just to control panel (buttons) if there's nothing else to display.

Let me know if that helps.

UPDATED

also... does your control "pwdBox" belong to main panel?

like image 25
Sebastian Siek Avatar answered Oct 12 '22 19:10

Sebastian Siek