单击仪表板中的菜单时 C# 表单提示密码
Posted
技术标签:
【中文标题】单击仪表板中的菜单时 C# 表单提示密码【英文标题】:C# forms prompt password when clicking a menu in a dashbaord 【发布时间】:2021-06-24 19:02:21 【问题描述】:我设计了一个包含按钮的仪表板表单。其中一些按钮具有子菜单。由于我打算限制对某些子菜单的访问,因此我希望每次用户单击受限子菜单时,都会出现一个表单,提示用户在访问受限页面之前输入密码。
我已经制作了一个密码表并编程,当点击一个子菜单时,密码表就会出现。但是,一旦提交了正确的密码,它将如下所示:
我希望密码正确时它看起来像这样:
我希望将重叠表单放置在原始位置/面板上。该怎么做?
这是仪表板的代码:
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();
这是一个需要密码的子菜单:
private void button2_Click(object sender, EventArgs e)
openPanelForm(new PasswordInventView());
hideSubMenu();
这是密码提示表单的代码:
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 来使用它。我喜欢它,但是我无法设置输入的字体,我希望我的密码在输入时显示为 ********。这就是我制作自己的密码表单的原因。
【问题讨论】:
【参考方案1】:public partial class PasswordInventView : Form
将表单更改为 UserControl。
public partial class PasswordInventView : UserControl
并在主窗体中创建用户控件。
如果这不起作用,请创建用户控件并将 PasswordInventView 复制到 UserControl。 Ctrl + Alt + L > 右键单击项目 > 添加 > 新项目 > 选择用户控件(Windows 窗体)> 添加。将子窗体复制到用户控件。并在主窗体中创建用户控件。
搜索用户控制。
【讨论】:
以上是关于单击仪表板中的菜单时 C# 表单提示密码的主要内容,如果未能解决你的问题,请参考以下文章
将数据发布到站点并将其加载到 iframe 中的另一个站点(角度和 c#)