无法将.Net面板设置为可见 [英] Can't set .Net panel to visible

查看:50
本文介绍了无法将.Net面板设置为可见的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用面板设计多页窗口表单.

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.

这是按钮的代码:

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!

屏幕截图:登录屏幕: http://img641.imageshack.us/img641/9310/loginscreenj.jpg

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

空窗口: http://img163.imageshack.us/img163/1376/emptyx.jpg

推荐答案

标准错误是您不小心将主面板放入登录面板.因此,当使loginpanel不可见时,主面板将永远变得不可见.这种事故在设计人员中很常见,它不会让您将两个面板彼此叠放.您可以使用查看+"(其他Windows)+文档大纲"对其进行修复.拖放主面板并将其放在表单上.您必须通过在属性"窗口中对其进行编辑,而不是使用鼠标来移动面板,来修复位置"属性.

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.

一种完全不同的方法是使用TabControl.在设计人员中很容易,您只需要在运行时隐藏选项卡即可.代码在此处.

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.

或使用两个UserControls.

Or use two UserControls.

这篇关于无法将.Net面板设置为可见的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆