我的界面是这样的,①里面是用户控件,特别是点击系统管理的时候最容易卡死(系统管理是Form窗体)其余大多数是用户控件。
主程序为
public FormMain()
{
InitializeComponent();
ThreadStart myTs = new ThreadStart(RSSMS);
Thread mytd = new Thread(myTs);
mytd.Start();
}
public void RSSMS()
{
while (true)
{
try
{
//读取短信
}catch
{
}
}
点击系统管理—>权限管理的代码是
if (checkchildFrmExist("权限管理") == true) { return; }
FormUserManage form1 = new FormUserManage();
form1.ShowDialog();
权限管理界面里的代码
public FormUserManage()
{
InitializeComponent();
sql = "select AreaID,DeviceDesc,DeviceID from RemoteDevices";
DataSet myds4 = dataBase.RunProcReturn(sql);
for (int f = 0; f < myds4.Tables[0].Rows.Count; f++)
{
CheckBox chkDevice = new CheckBox();
chkDevice.Name = "chkDesc" + myds4.Tables[0].Rows[f]["DeviceID"].ToString();
chkDevice.Text = myds4.Tables[0].Rows[f]["DeviceDesc"].ToString();
panelLiaoNing.Controls.Add(chkDevice);
}
}
点击【叹号】图标加载用户控件代码
try
{
if (((ToolStripButton)sender).Checked) return;
for (int i = 0; i < this.toolBar.Items.Count; i++)
{
if (toolBar.Items[i].GetType().Equals(typeof(ToolStripButton)))
{
if (toolBar.Items[i] != sender)
((ToolStripButton)toolBar.Items[i]).Checked = false;
else
((ToolStripButton)toolBar.Items[i]).Checked = true;
}
}
if (DisplayControl != null)
{
DisplayControl.Dispose();
}
DisplayControl = new ControlAlarmList();
DisplayControl.Parent = panelView;
DisplayControl.Dock = System.Windows.Forms.DockStyle.Fill;
((ControlAlarmList)DisplayControl).TargetID = TargetID;
((ControlAlarmList)DisplayControl).btnQuery_Click(sender, e);
selectMenu = "AlarmList";
}
catch
{
}
用户控件中更换列表中的红色和黄色图片
btnQuery_Click(object sender, EventArgs e)
{
if (dgvInfo.Rows.Count > 0)
{
//更新图片
for (int i = 0; i < dgvInfo.Rows.Count; i++)
{
string rank = dgvInfo["Rank", i].Value.ToString();
if (rank == "紧急")
dgvInfo["RankColor", i].Value = (Image)Properties.Resources.ResourceManager.GetObject("hong");
else
dgvInfo["RankColor", i].Value = (Image)Properties.Resources.ResourceManager.GetObject("huang");
}
}
}