R
raylopez99
I have a form, Form6, that has a bunch of buttons overlaid on it. I
want to be able to click on any arbitrary area of the form, and if
that area of the form is overlaid by a button, I want to change the
color of the button to Coral, and show a MessageBox with the button
name.
So far, I've tried the below event handlers, and the only one that has
worked is of course the named button event click, for a particular
named button (button3 below), but, I don't want to set up such click
events for each button, since the form Form6 has an arbitrary number
of buttons and/or a large number of buttons on it.
Any way to do this in C#?
Thanks
RL
//////////
private void Form6_DoubleClick(object sender, EventArgs e)
{
//double clicking on form will cause this event to
trigger, which checks to see if a particular button clicked
if (sender.GetType() ==
typeof(System.Windows.Forms.Button))
{
Button currentButton = (Button)sender;
currentButton.BackColor = Color.Coral;
MessageBox.Show("Button doubleclicked is: " +
currentButton.Text);
}
}
private void Form6_MouseDoubleClick(object sender,
MouseEventArgs e)
{
//double clicking on form will cause this event to
trigger, which checks to see if a particular button clicked
if (sender.GetType() ==
typeof(System.Windows.Forms.Button))
{
Button currentButton = (Button)sender;
currentButton.BackColor = Color.Coral;
MessageBox.Show("Button doubleclicked is: " +
currentButton.Text);
}
}
private void Form6_MouseMove(object sender, MouseEventArgs e)
{
if (sender.GetType() ==
typeof(System.Windows.Forms.Button))
{
Button currentButton = (Button)sender;
currentButton.BackColor = Color.Coral;
MessageBox.Show("Button MouseMove: " +
currentButton.Text);
}
}
private void button3_Click(object sender, EventArgs e) //only
this event handler works
{
if (sender.GetType() ==
typeof(System.Windows.Forms.Button))
{
Button currentButton = (Button)sender;
currentButton.BackColor = Color.Coral;
MessageBox.Show("Button #3!: " + currentButton.Text);
}
}
private void Form6_MouseDown(object sender, MouseEventArgs e)
{
if (sender.GetType() ==
typeof(System.Windows.Forms.Button))
{
Button currentButton = (Button)sender;
currentButton.BackColor = Color.Coral;
MessageBox.Show("Button MouseDown: " +
currentButton.Text);
}
}
want to be able to click on any arbitrary area of the form, and if
that area of the form is overlaid by a button, I want to change the
color of the button to Coral, and show a MessageBox with the button
name.
So far, I've tried the below event handlers, and the only one that has
worked is of course the named button event click, for a particular
named button (button3 below), but, I don't want to set up such click
events for each button, since the form Form6 has an arbitrary number
of buttons and/or a large number of buttons on it.
Any way to do this in C#?
Thanks
RL
//////////
private void Form6_DoubleClick(object sender, EventArgs e)
{
//double clicking on form will cause this event to
trigger, which checks to see if a particular button clicked
if (sender.GetType() ==
typeof(System.Windows.Forms.Button))
{
Button currentButton = (Button)sender;
currentButton.BackColor = Color.Coral;
MessageBox.Show("Button doubleclicked is: " +
currentButton.Text);
}
}
private void Form6_MouseDoubleClick(object sender,
MouseEventArgs e)
{
//double clicking on form will cause this event to
trigger, which checks to see if a particular button clicked
if (sender.GetType() ==
typeof(System.Windows.Forms.Button))
{
Button currentButton = (Button)sender;
currentButton.BackColor = Color.Coral;
MessageBox.Show("Button doubleclicked is: " +
currentButton.Text);
}
}
private void Form6_MouseMove(object sender, MouseEventArgs e)
{
if (sender.GetType() ==
typeof(System.Windows.Forms.Button))
{
Button currentButton = (Button)sender;
currentButton.BackColor = Color.Coral;
MessageBox.Show("Button MouseMove: " +
currentButton.Text);
}
}
private void button3_Click(object sender, EventArgs e) //only
this event handler works
{
if (sender.GetType() ==
typeof(System.Windows.Forms.Button))
{
Button currentButton = (Button)sender;
currentButton.BackColor = Color.Coral;
MessageBox.Show("Button #3!: " + currentButton.Text);
}
}
private void Form6_MouseDown(object sender, MouseEventArgs e)
{
if (sender.GetType() ==
typeof(System.Windows.Forms.Button))
{
Button currentButton = (Button)sender;
currentButton.BackColor = Color.Coral;
MessageBox.Show("Button MouseDown: " +
currentButton.Text);
}
}