/// <summary> /// 修改按钮 /// </summary> /// <param name="section"></param> public void updateButton(String section) { Button btn = (Button)flowLayoutPanel.Controls[section]; MonitorSections.MonitorSection monitorSection = MonitorSections.getMonitorByKey(section); String title = monitorSection.title; btn.Text = title; }
private void UpdateForm_Load(object sender, EventArgs e) { MonitorSections.MonitorSection monitorSection = MonitorSections.getMonitorByKey(section); String title = monitorSection.title; String url = monitorSection.url; String warn = monitorSection.warn; UpdateForm_Title_TextBox.Text = title; UpdateForm_Url_TextBox.Text = url; UpdateForm_Warn_RichTextBox.Text = warn; }
/** * 右键停止按钮点击事件 * */ private void BtnRightStopClick(Object sender, EventArgs e) { ToolStripMenuItem menuItem = (ToolStripMenuItem)sender; String section = (String)menuItem.Tag; // 停止监听 iniUtils.IniWriteValue(Config.MonitorIniPath, section, "stat", "0"); // 按钮背景置灰 Button button = (Button)ControlUtils.GetControlInstance(flowLayoutPanel, section); setButtonBackColor(button, Color.LightGray); // 缓存数据更新为停止 MonitorSections.MonitorSection monitorSection = MonitorSections.getMonitorByKey(section); monitorSection.stat = "0"; MonitorSections.updateMonitor(section, monitorSection); }
private void BtnMouseHover(Object sender, EventArgs e) { Button currentBtn = (Button)sender; String section = currentBtn.Name; MonitorSections.MonitorSection monitorSection = MonitorSections.getMonitorByKey(section); String title = monitorSection.title; // 设置显示样式 //toolTip1.AutoPopDelay = 5000;//提示信息的可见时间 toolTip1.InitialDelay = 200; //事件触发多久后出现提示 toolTip1.ReshowDelay = 0; //指针从一个控件移向另一个控件时,经过多久才会显示下一个提示框 toolTip1.ShowAlways = true; //是否显示提示框 // 设置伴随的对象. toolTip1.SetToolTip(currentBtn, title); }
private void UpdateForm_Save_Button_Click(object sender, EventArgs e) { String title = UpdateForm_Title_TextBox.Text; String url = UpdateForm_Url_TextBox.Text; String warn = UpdateForm_Warn_RichTextBox.Text; Boolean checkFlag = true; StringBuilder checkMsg = new StringBuilder(); if ("".Equals(title)) { checkFlag = false; checkMsg.Append("名称未填写\r\n"); } if ("".Equals(url)) { checkFlag = false; checkMsg.Append("地址未填写\r\n"); } if (!checkFlag) { MessageBox.Show(checkMsg.ToString(), "错误"); } else { /** 数据正常,修改ini数据,执行StartForm添加按钮和新增rdp文件操作 */ // 生成title iniUtils.IniWriteValue(Config.MonitorIniPath, section, "title", title); iniUtils.IniWriteValue(Config.MonitorIniPath, section, "url", url); iniUtils.IniWriteValue(Config.MonitorIniPath, section, "warn", warn); /* 生成新INI结束 ************************/ // sections缓存数据新增 MonitorSections.MonitorSection monitorSection = MonitorSections.getMonitorByKey(section); monitorSection.title = title; monitorSection.url = url; monitorSection.warn = warn; MonitorSections.updateMonitor(section, monitorSection); /* StartForm中更新服务按钮 *************/ mainForm.updateButton(section); /* 更新服务按钮完成****** *************/ // 关闭新增窗口 UpdateForm_Cancel_Button_Click(sender, e); } }
/// <summary> /// 添加按钮 /// </summary> public void addButton(String section) { String buttonText = iniUtils.IniReadValue(Config.MonitorIniPath, section, "title"); // 监控地址 String url = iniUtils.IniReadValue(Config.MonitorIniPath, section, "url"); // 状态,是暂停还是启动状态 String stat = iniUtils.IniReadValue(Config.MonitorIniPath, section, "stat"); // 预警 String warn = iniUtils.IniReadValue(Config.MonitorIniPath, section, "warn"); Button button = new Button(); button.ImageAlign = System.Drawing.ContentAlignment.TopCenter; button.Location = new System.Drawing.Point(3, 0); button.Name = section; button.Size = new System.Drawing.Size(90, 70); button.TabIndex = 0; if ("0".Equals(stat)) { // 当前任务是暂停(背景色置灰) setButtonBackColor(button, Color.LightGray); } else if ("1".Equals(stat)) { // 当前任务是启动(背景色置浅蓝) setButtonBackColor(button, Color.AliceBlue); } Image image = Image.FromFile(@"resource\icons\computer.ico"); button.BackgroundImageLayout = ImageLayout.None; button.BackgroundImage = image; button.Text = buttonText; button.TextAlign = System.Drawing.ContentAlignment.BottomCenter; button.Font = new Font("微软雅黑", 8); button.MouseHover += new EventHandler(BtnMouseHover); // 右键按钮添加事件 ContextMenuStrip rightMenu = new ContextMenuStrip(); ToolStripMenuItem monitorItem = new ToolStripMenuItem(); monitorItem.Name = section + "MouseRightMenu_Monitor"; monitorItem.Text = "监听"; monitorItem.Tag = section; monitorItem.Click += new EventHandler(BtnRightMonitorClick); rightMenu.Items.Add(monitorItem); ToolStripMenuItem stopItem = new ToolStripMenuItem(); stopItem.Name = section + "MouseRightMenu_Stop"; stopItem.Text = "停止"; stopItem.Tag = section; stopItem.Click += new EventHandler(BtnRightStopClick); rightMenu.Items.Add(stopItem); ToolStripMenuItem updateItem = new ToolStripMenuItem(); updateItem.Name = section + "MouseRightMenu_Update"; updateItem.Text = "修改"; updateItem.Tag = section; updateItem.Click += new EventHandler(BtnRightUpdateClick); rightMenu.Items.Add(updateItem); button.ContextMenuStrip = rightMenu; flowLayoutPanel.Controls.Add(button); // // 数据写进缓存 MonitorSections.MonitorSection monitorSection = new MonitorSections.MonitorSection(); monitorSection.title = buttonText; monitorSection.url = url; monitorSection.stat = stat; monitorSection.warn = warn; MonitorSections.updateMonitor(section, monitorSection); }