I have this method that checks if a service is running and a button which when clicked initaites the method. Although is there a way to "grey out" the button if the service is for example - not installed. ?
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开发者_如何学C installed!");
}
}
private void button14_Click_1(object sender, EventArgs e)
{
StopService("Update Scheduler Service", 20000);
}
WinForms controls have a .Enabled property that when set to False, the control is grayed out like you wish. I assume WPF has the same functionality, but I have never used WPF so I can't say for certain.
精彩评论