Let me start with example:
I have Form
with one button named "btnTest" and added _click
event for it.
private void btnTest_Click(object sender, EventArgs e)
{
MessageBox.Show("button click");
}
Now I want to dynamically generate another _click
event for this button
using Control
class and therefore override the existing event_hendler
, so my form would look something like this:
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
Control[] controls = Controls.Find("btnTest", true); //find control by name
controls[0].Click += Form1_Click; //generate button click
}
private void Form1_Click(object sender, EventArgs e)
{
MessageBox.Show("control click"); //want to be displayed
}
private void btnTest_Click(object sender, EventArgs e)
{
MessageBox.Show("button click"); //don't want to be displayed
}
}
So my goal is to enable Form1_Click
and to ignore btnTest_Click
and to do so dynamically in code.
Done some research, but couldn't get the answer.
Why am i doing this?
My main goal is to navigate through controls using ENTER keyword instead of TAB, so when I stumble on button I just want to move forward without triggering original event.
Note that btnTest_Click
event is triggered before Form1_Click
event and also bad solution would be to do something directly inbtnTest_Click
because I have limited amount of controls that I want to navigate using ENTER and hat is changeable, so the buttons I want to ignore would be in controls
array.
Any suggestion is helpful, thank you for your time.