1、登录实现
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace LoginApp
{
public partial class LoginForm : Form
{
public LoginForm()
{
InitializeComponent();
}
private void BtnLogin_Click(object sender, EventArgs e)
{
if(this.tbUsername.Text.Equals("engineer") && this.tbPassword.Text.Equals("123456"))
{
MainForm mainForm = new MainForm();
this.Hide();
mainForm.ShowDialog();
this.Close();
}
}
}
}
2、工具栏切换
using LoginApp.ToolUs;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace LoginApp
{
public partial class MainForm : Form
{
public MainForm()
{
InitializeComponent();
}
private void BtnComponent_Click(object sender, EventArgs e)
{
Button btn = (Button)sender;
UserControl userControl = new UserControl();
switch(btn.Text)
{
case "器件":
userControl = new Device();
break;
case "连接":
userControl = new Connection();
break;
}
userControl.BackColor = Color.White;
userControl.Dock = DockStyle.Fill;
tableLayoutPanel2.Controls.Add(userControl, 1, 0);
}
}
}
3、运行