[2.0][3.0] OnMouseEvent for Buttons[RESOLVED]
coming across a slight problem with the MouseEnter or MouseHover Events,cant seem to get the code correct...getting the BackColor of the Button to change when the Cursor goes over the button..
VB Code:
private void button1_OnMouseEnter(object sender, MouseEventArgs e)
{
base.OnMouseEnter(e);
if (button1.BackColor == Color.Black)
button1.BackColor = Color.DarkBlue;
else
base.OnMouseLeave(e);
button1.BackColor = Color.Black;
}
// I'v tried this serveral different ways version 2
protected override void OnMouseEnter(EventArgs e)
{
base.OnMouseEnter(e);
button1.BackColor = Color.DarkBlue;
}
protected override void OnMouseLeave(EventArgs e)
{
base.OnMouseLeave(e);
button1.BackColor = Color.Black;
}
I also tried using the "protected override void"
Re: [2.0][3.0] OnMouseEvent for Buttons
Just had a quick play and i have no problem with just doing
Code:
private void button1_MouseLeave(object sender, System.EventArgs e)
{
this.button1.BackColor = System.Drawing.Color.DarkBlue;
}
private void button1_MouseEnter(object sender, System.EventArgs e)
{
this.button1.BackColor = System.Drawing.Color.Black;
}
Re: [2.0][3.0] OnMouseEvent for Buttons
So are you trying to handle the events of a standard Button on a form or are you trying to create a custom Button class? If you're handling events of a standard Button on a form then you should add the code that FishCake posted to the form. If you're trying to create a custom Button class then its code should look something like this:
Code:
class MyButton : System.Windows.Forms.Button
{
protected override void OnMouseEnter(EventArgs e)
{
base.OnMouseEnter(e);
this.BackColor = System.Drawing.Color.Blue;
}
protected override void OnMouseLeave(EventArgs e)
{
base.OnMouseLeave(e);
this.BackColor = System.Drawing.Color.Black;
}
}
Re: [2.0][3.0] OnMouseEvent for Buttons[RESOLVED]
Thxs for the help i was Experimenting using both...Drawing on my own buttons and using the Regular Buttons...