|
-
Jul 19th, 2006, 11:54 AM
#1
Thread Starter
Hyperactive Member
[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"
Last edited by Rattlerr; Jul 19th, 2006 at 09:20 PM.
-
Jul 19th, 2006, 12:38 PM
#2
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;
}
-
Jul 19th, 2006, 07:10 PM
#3
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;
}
}
-
Jul 19th, 2006, 09:20 PM
#4
Thread Starter
Hyperactive Member
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...
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|