C#工控上位机
第一部分:UI模块
先点击一下Panel,在点击一下屏幕。
先选中Panel,在进行属性设置。
图标连接
嵌入式窗体
设置按键的事件
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;
using MetroFramework.Forms;namespace _01_UITest
{public partial class Form1 : MetroForm{public Form1(){InitializeComponent();}//第一个按钮的点击事件private void Form1_Load(object sender, EventArgs e){}//第二个按钮的点击事件private void btnHome_Click(object sender, EventArgs e){OpenForm(new Form2());}private void btnSet_Click(object sender, EventArgs e){OpenForm(new Form3());}//定义一个开窗的方法private void OpenForm(Form frm)//传入一个参数,参数为窗口的名字{frm.TopLevel = false;frm.TopMost = false;this.panelMain.Controls.Clear();this.panelMain.Controls.Add(frm);frm.Show();}}
}
修改一下背景颜色。
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;
using MetroFramework.Forms;namespace _01_UITest
{public partial class Form1 : MetroForm{public Form1(){InitializeComponent();}//第一个按钮的点击事件private void Form1_Load(object sender, EventArgs e){}//第二个按钮的点击事件private void btnHome_Click(object sender, EventArgs e){OpenForm(new Form2());ShowBar(sender as Button);}private void btnSet_Click(object sender, EventArgs e){OpenForm(new Form3());ShowBar(sender as Button);}//定义一个开窗的方法private void OpenForm(Form frm)//传入一个参数,参数为窗口的名字{frm.TopLevel = false;frm.TopMost = false;this.panelMain.Controls.Clear();this.panelMain.Controls.Add(frm);frm.Show();}//让蓝色的框框下移private void ShowBar(Button btn){this.panelBar.Location = new Point(btn.Location.X - 10,btn.Location.Y );//12表示宽度}}
}
另一种布局