public static MemService AddService(int port) { var name = string.Format("{0} {1}", servicePreName, port); var service = new MemService(name); return(service); }
private void RefreshService() { var ms = MemService.GetMemService(); this.cmbBoxPort.Items.AddRange(ms); if (ms.Length > 0) { this.cmbBoxPort.SelectedIndex = 0; } }
private void btnAdd_Click(object sender, EventArgs e) { var add = new AddFrom(); if (add.ShowDialog() == DialogResult.OK) { int port = add.Port; int mem = add.MaxMem; var s = MemService.GetMemService().FirstOrDefault(item => item.Port == port); if (s != null) { MessageBox.Show("此端口的服务已经存在...", "提示"); return; } s = MemService.AddService(port); s.Start(mem, port); this.cmbBoxPort.Items.Add(s); this.cmbBoxPort.SelectedItem = s; } }
private void btnDelete_Click(object sender, EventArgs e) { if (MessageBox.Show("删除服务会带来数据丢,确定要继续吗?", "提示", MessageBoxButtons.YesNo) == DialogResult.No) { return; } if (this.currentService != null) { this.currentService.Delete(); } var item = this.currentService; this.currentService = null; this.cmbBoxPort.Items.Remove(item); if (this.cmbBoxPort.Items.Count > 0) { this.cmbBoxPort.SelectedIndex = 0; } this.BindingStatus(); }
/// <summary> /// 选择变化 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void cmbBoxPort_SelectedIndexChanged(object sender, EventArgs e) { this.currentService = this.cmbBoxPort.SelectedItem as MemService; this.BindingStatus(); }