我正试图像这样解雇click event
:
bool m=false;
private void button1_Click(object sender, RoutedEventArgs e)
{
MessageBox.Show("button1 clicke!");
button1.Tag = "system";
ButtonAutomationPeer peer = new ButtonAutomationPeer(button1);
IInvokeProvider invokeProv = peer.GetPattern(PatternInterface.Invoke) as IInvokeProvider;
if (m==false)
for (int i = 0; i < 2; i++)
{
invokeProv.Invoke();
m = true;
}
}
我想只显示此MessageBox
3次。它有效但当我再次点击此按钮时,MessageBox
只显示一次。
答案 0 :(得分:2)
试试这段代码:
int i = 1;
private void button1_Click(object sender, RoutedEventArgs e)
{
MessageBox.Show("button1 clicked!");
ButtonAutomationPeer peer = new ButtonAutomationPeer(button1);
IInvokeProvider invokeProv = peer.GetPattern(PatternInterface.Invoke) as IInvokeProvider;
i++;
if (i != 4)
{
invokeProv.Invoke();
}
else
{
i = 1;
}
}