我正在尝试将GUI中的无线电按钮的切换状态设置为“已检查”或“未检查”。
我写了一个方法来检查元素是否被切换,如下所示:
public Form1()
{
timer1.Interval = SystemInformation.DoubleClickTime;
}
bool double_click = false;
//
DataGridViewCellEventArgs sendedEvent = null;
private void DatagridView1_CellDoubleClick(object sender, DataGridViewCellEventArgs e)
{
double_click = true;
sendedEvent = e;
}
private void DatagridView1_CellClick(object sender, DataGridViewCellEventArgs e)
{
sendedEvent = e;
//
timer1.Enabled = true;
//
timer1.Start();
}
private void timer1_Tick(object sender, EventArgs e)
{
if (!double_click)
{
// DO your simple click stuff and USE sendedEvent if needed
}
else
{
double_click = false;
// DO your Doubleclick stuff and USE sendedEvent if needed
}
timer1.Stop();
timer1.Enabled = false;
}
我认为我的Set切换状态方法看起来像这样:
private bool IsElementToggledOn(AutomationElement element) {
if (element == null) {
throw new Exception("Value pattern can not be found");
}
Object objPattern;
TogglePattern togPattern;
if (true == element.TryGetCurrentPattern(TogglePattern.Pattern, out objPattern)) {
togPattern = objPattern as TogglePattern;
return togPattern.Current.ToggleState == ToggleState.On;
}
return false;
}