//点击退出系统
private void btn_Exit_Click(object sender, EventArgs e)
{
if (MessageBox.Show("您确定要退出吗?", "退出系统对话框", MessageBoxButtons.OKCancel) == DialogResult.OK)
{
//添加日志
dao.AddLog("软件关闭");
System.Environment.Exit(0);//不管什么线程都会关闭
}
}
//在lst_operate列表框中记录日志 往ListBox里写入 this.AddLog("连接PLC:"+AppConfig.PLCIP);
private void AddLog(String msg)
{
if (this.lst_operate.InvokeRequired)//当前线程不是创建控件的线程时为真
{
this.lst_operate.Invoke(new EventHandler(delegate
{
this.lst_operate.Items.Add(msg);
this.lst_operate.SelectedIndex = this.lst_operate.Items.Count - 1;
}));
}
else
{
this.lst_operate.Items.Add(msg);
this.lst_operate.SelectedIndex = this.lst_operate.Items.Count - 1;
}
}
//this.groupBox1.Paint += groupBox_Paint;
//为GroupBox设置边框颜色
public void groupBox_Paint(object sender, PaintEventArgs e)
{
GroupBox gbox = (GroupBox)sender;
e.Graphics.Clear(gbox.BackColor);
e.Graphics.DrawString(gbox.Text, gbox.Font, Brushes.Black, 10, 1);
var vSize = e.Graphics.MeasureString(gbox.Text, gbox.Font);
e.Graphics.DrawLine(Pens.Black, 1, vSize.Height / 2, 8, vSize.Height / 2);
e.Graphics.DrawLine(Pens.Black, vSize.Width + 8, vSize.Height / 2, gbox.Width - 2, vSize.Height / 2);
e.Graphics.DrawLine(Pens.Black, 1, vSize.Height / 2, 1, gbox.Height - 2);
e.Graphics.DrawLine(Pens.Black, 1, gbox.Height - 2, gbox.Width - 2, gbox.Height - 2);
e.Graphics.DrawLine(Pens.Black, gbox.Width - 2, vSize.Height / 2, gbox.Width - 2, gbox.Height - 2);
}