如何灰显依赖于特定实例的C#窗体上的按钮
本文关键字:窗体 按钮 实例 何灰显 依赖于 | 更新日期: 2023-09-27 17:58:23
我有一个检查服务是否正在运行的方法,以及一个按钮,当单击该按钮时启动该方法。尽管如果服务没有安装,有没有办法"灰显"按钮?
public static void StopService(string serviceName, int timeoutMilliseconds)
{
ServiceController service = new ServiceController(serviceName);
try
{
TimeSpan timeout = TimeSpan.FromMilliseconds(timeoutMilliseconds);
service.Stop();
service.WaitForStatus(ServiceControllerStatus.Stopped, timeout);
MessageBox.Show("The service was successfully turned on");
}
catch
{
MessageBox.Show("Service is not installed!");
}
}
private void button14_Click_1(object sender, EventArgs e)
{
StopService("Update Scheduler Service", 20000);
}
WinForms控件有一个.Enabled属性,当设置为False时,该控件将显示为灰色。我认为WPF具有相同的功能,但我从未使用过WPF,所以我不能肯定。