C#检查按钮是否被单击 [英] C# Checking if button was clicked
问题描述
我正在制作一个程序,如果给出两个条件,该程序应该继续执行。
I am making a program that should just continue if 2 conditions are given.
第一个,2个 TextBox
带有相同的单词,并带有 Button <单击/ code>,将打开一个新的
表格
。现在,我有了用于完成按钮的事件。
The first one, 2 TextBox
s have the same word in and a Button
was clicked, which opens a new Form
. Now I have the event for the "complete" button.
private void button2_Click(object sender, EventArgs e)
{
if (textBox2.Text == textBox3.Text && ???)
{
StreamWriter myWriter = File.CreateText(@"c:\Program Files\text.txt");
myWriter.WriteLine(textBox1.Text);
myWriter.WriteLine(textBox2.Text);
}
]
我的问题是,我找不到方法
My problem is, I can't find a method that gives something like `button1.Clicked or something similar.
我希望有人可以在这里为我提供帮助。
I hope someone can help me here..
推荐答案
Click
是释放鼠标按钮后立即触发的事件。因此,如果您想签入 button2.Click
的处理程序,如果之前单击过 button1
,您所能做的就是有一个用于 button1.Click
的处理程序,它将您自己制作的布尔标志设置为true。
Click
is an event that fires immediately after you release the mouse button. So if you want to check in the handler for button2.Click
if button1
was clicked before, all you could do is have a handler for button1.Click
which sets a bool flag of your own making to true.
private bool button1WasClicked = false;
private void button1_Click(object sender, EventArgs e)
{
button1WasClicked = true;
}
private void button2_Click(object sender, EventArgs e)
{
if (textBox2.Text == textBox3.Text && button1WasClicked)
{
StreamWriter myWriter = File.CreateText(@"c:\Program Files\text.txt");
myWriter.WriteLine(textBox1.Text);
myWriter.WriteLine(textBox2.Text);
button1WasClicked = false;
}
}
这篇关于C#检查按钮是否被单击的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!