首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >单击仪表板中的菜单时C#表单提示密码

单击仪表板中的菜单时C#表单提示密码
EN

Stack Overflow用户
提问于 2021-03-28 22:34:18
回答 1查看 43关注 0票数 0

我设计了一个包含按钮的仪表板表单。其中一些按钮有子菜单。由于我计划限制对某些子菜单的访问,因此我希望每次用户单击受限制的子菜单时,都会出现一个表单,提示用户在访问受限制的页面之前输入密码。

我已经制作了一个密码表单,并编程当子菜单被点击时,密码表单就会出现。但是,一旦提交了正确的密码,它将如下所示:

我希望当密码正确时,它看起来像这样:

我希望将重叠的表单放置在原始位置/面板上。如何做到这一点?

以下是仪表板的代码:

代码语言:javascript
复制
public CFMenu()
        {
            InitializeComponent();
            customizeDesign();
        }
        private void customizeDesign()
        {
            panelInventory.Visible = false;
            panelSales.Visible = false;
        }
        private void hideSubMenu()
        {
            if(panelInventory.Visible == true)
                panelInventory.Visible = false;
            if(panelSales.Visible == true)
                panelSales.Visible = false;
        }
        private void showSubMenu(Panel subMenu)
        {
            if(subMenu.Visible == false)
            {
                hideSubMenu();
                subMenu.Visible = true;
            }
            else
                subMenu.Visible = false;
        }
        private void CFMenu_Load(object sender, EventArgs e)
        {
            // TODO: This line of code loads data into the 'casaFrancaDataSet.Sales' table. You can move, or remove it, as needed.
            this.salesTableAdapter.Fill(this.casaFrancaDataSet.Sales);
            timer1.Start();
            label4.Text = DateTime.Now.ToLongTimeString();
            label5.Text = DateTime.Now.ToLongDateString();
        }
        private void btnInventory_Click(object sender, EventArgs e)
        {
            showSubMenu(panelInventory);
        }
        private void btnSales_Click(object sender, EventArgs e)
        {
            showSubMenu(panelSales);
        }
        private void button1_Click(object sender, EventArgs e)
        {
            openPanelForm(new CFInventoryAdd());
            hideSubMenu();
        }
        private void button2_Click(object sender, EventArgs e)
        {
            openPanelForm(new PasswordInventView());
            hideSubMenu();


            //string password = Interaction.InputBox("Enter Password: ", "Inventory View");
            //if(password == "hello")
            //{
            //    openPanelForm(new CFInventoryView());
            //    hideSubMenu();
            //}
            //else
            //{
            //    MessageBox.Show("Incorrect Password!");
            //}  
        }
        private void button3_Click(object sender, EventArgs e)
        {
            openPanelForm(new CFInventoryUpdate());
            hideSubMenu();
        }
        private void button7_Click(object sender, EventArgs e)
        {
            openPanelForm(new CFSalesAdd());
            hideSubMenu();
        }
        private void button6_Click(object sender, EventArgs e)
        {
            openPanelForm(new CFSalesView());
            hideSubMenu();
        } 
        private void button8_Click(object sender, EventArgs e)
        {
            openPanelForm(new CFCalculate());
            hideSubMenu();
        }
        private void button5_Click(object sender, EventArgs e)
        {
            openPanelForm(new CFSalesUpdate());
            hideSubMenu();
        } 
        private void button9_Click(object sender, EventArgs e)
        {
            openPanelForm(new CFReport());
            hideSubMenu();
        }
        private void timer1_Tick(object sender, EventArgs e)
        {
            label4.Text = DateTime.Now.ToLongTimeString();
            timer1.Start();
        }
        private Form activeForm = null;
        private void openPanelForm(Form childForm)
        {
            if (activeForm != null)
                activeForm.Close();
            activeForm = childForm;
            childForm.TopLevel = false;
            childForm.FormBorderStyle = FormBorderStyle.None;
            childForm.Dock = DockStyle.Fill;
            panelForm.Controls.Add(childForm);
            panelForm.Tag = childForm;
            childForm.BringToFront();
            childForm.Show();
        }

这是一个需要密码的子菜单:

代码语言:javascript
复制
private void button2_Click(object sender, EventArgs e)
        {
            openPanelForm(new PasswordInventView());
            hideSubMenu();
        }

下面是密码提示表单的代码:

代码语言:javascript
复制
public partial class PasswordInventView : Form
    {
        public PasswordInventView()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            var password = txtPassword.Text;

            if (password == "1234")
            {
                CFInventoryView f2 = new CFInventoryView();
                f2.Show();
                this.Visible = false;
            }
            else
            {
                MessageBox.Show("Username or Password is incorrect!");
                txtPassword.Clear();
            }
        }

在制作密码表单之前,我尝试通过在我的项目中引用VisualBasic中的InputDialog来使用它。我喜欢它,但是我不能设置输入的字体,我希望我的密码在输入时显示为*。这就是为什么我做了自己的密码表。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2021-03-28 23:20:31

代码语言:javascript
复制
public partial class PasswordInventView : Form

将form更改为UserControl。

代码语言:javascript
复制
public partial class PasswordInventView : UserControl

并在主窗体中创建用户控件。

如果不起作用,则创建用户控件并将PasswordInventView复制到UserControl。Ctrl + Alt +L>右键单击项目>添加>新建项>选择用户控件(Windows窗体)>添加。将chield窗体复制到用户控件。并在主窗体中创建用户控件。

搜索有关用户控件的信息。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/66842536

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档