.net panel visibility = true not working

I am designing a multi-page window shape using panels.

I show the login form and check the click of a button and want to hide the login panel and show the main panel.

However, when I click the button, the input panel disappears in order, but the main panel does not appear. since there is nothing to display, the form window shrinks to the Minimize / Maximize / Close buttons.

Here's the button code:

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 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

+4
source share
3 answers

The standard error is that you accidentally place the main panel inside the login panel. Therefore, when you make the loginpanel invisible, the mainpanel will never become visible. This accident is common in the designer, it will not allow you to put two panels on top of each other. You fix it using View + (Other Windows) + Document Outline. Drag the main panel and lower it into the form. You will need to fix the Location property by editing it in the Properties window, rather than moving the panel with the mouse.

A completely different approach is to use TabControl. Easy in designer, you just need to hide tabs at runtime. The code is here .

Or use two UserControls.

+17
source

It looks like you are automatically resizing. There are 2 properties in the form responsible for automatic size:

 AutoSize = True; AutoSizeMode = GrowAndShrink; 

If you have the above settings, your form will be reduced only to the control panel (buttons), if there is nothing that could be displayed.

Let me know if this helps.

UPDATED

also ... does your pwdBox control relate to the main panel?

+1
source

Two suggestions: Try setting the height attribute to 100%

 mainpanel.Height = 100% 

If this does not work, make sure the page is not initialized with mainpanel.visible set to false in the postback.

-one
source

Source: https://habr.com/ru/post/1395081/


All Articles