private void textBox2_TextChanged(object sender, EventArgs e) { if (DriverAPIInterface.GetStatus(ServiceName).ToInt32() != 0 && string.Compare(textBox2.Text, ServiceName) != 0) { if (MessageBox.Show($"当前正在操作【{ServiceName}】驱动,是否取消操作!", "警告", MessageBoxButtons.OKCancel, MessageBoxIcon.Asterisk) == DialogResult.OK) { DriverAPIInterface.Close(); } else { } return; } if (!string.IsNullOrEmpty(ServiceName)) { if (DriverAPIInterface.Open(ServiceName).ToInt32() == 0) { if (MessageBox.Show($"驱动【{ServiceName}】已存在,是否要操作此驱动?", "警告", MessageBoxButtons.OKCancel, MessageBoxIcon.Asterisk) == DialogResult.Cancel) { DriverAPIInterface.Close(); } RefreshStatus(); } } }
private void RefreshStatus() { bool bCreate = false, bStart = false, bStop = false, bDelete = false; switch (dwDriverStatus = DriverAPIInterface.GetStatus(ServiceName).ToInt64()) { case DriverAPIInterface.DRIVER_CLOSED: bCreate = true; this.Invoke(new Action(() => { label5.Text = "已关闭"; label5.ForeColor = Color.Red; })); break; case DriverAPIInterface.DRIVER_OPENED: bStart = true; bDelete = true; this.Invoke(new Action(() => { label5.Text = "已指定驱动"; label5.ForeColor = Color.Blue; })); break; case DriverAPIInterface.DRIVER_STARTED: bStop = true; this.Invoke(new Action(() => { label5.Text = "驱动运行中"; label5.ForeColor = Color.Green; })); break; case DriverAPIInterface.DRIVER_PAUSED: bStop = true; this.Invoke(new Action(() => { label5.Text = "驱动已被暂停"; label5.ForeColor = Color.Yellow; })); break; case DriverAPIInterface.DRIVER_BUSY: this.Invoke(new Action(() => { label5.Text = "驱动正忙"; label5.ForeColor = Color.RoyalBlue; })); break; } this.Invoke(new Action(() => button1.Enabled = bCreate)); this.Invoke(new Action(() => button2.Enabled = bStart)); this.Invoke(new Action(() => button3.Enabled = bStop)); this.Invoke(new Action(() => button4.Enabled = bDelete)); }