Results 1 to 4 of 4

Thread: [2.0][3.0] OnMouseEvent for Buttons[RESOLVED]

  1. #1

    Thread Starter
    Hyperactive Member Rattlerr's Avatar
    Join Date
    Jul 2005
    Location
    FloralCity,Florida
    Posts
    269

    Smile [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:
    1. private void button1_OnMouseEnter(object sender, MouseEventArgs e)
    2.         {
    3.             base.OnMouseEnter(e);
    4.             if (button1.BackColor == Color.Black)
    5.                 button1.BackColor = Color.DarkBlue;
    6.             else
    7.                 base.OnMouseLeave(e);
    8.             button1.BackColor = Color.Black;
    9.         }
    10. // I'v tried this serveral different ways version 2
    11.  
    12. protected override void OnMouseEnter(EventArgs e)
    13.  
    14. {
    15.  
    16. base.OnMouseEnter(e);
    17.  
    18. button1.BackColor = Color.DarkBlue;
    19.  
    20.  
    21. }
    22.  
    23.  
    24. protected override void OnMouseLeave(EventArgs e)
    25.  
    26. {
    27.  
    28. base.OnMouseLeave(e);
    29.  
    30. button1.BackColor = Color.Black;
    31.  
    32. }

    I also tried using the "protected override void"
    Last edited by Rattlerr; Jul 19th, 2006 at 09:20 PM.

  2. #2
    Frenzied Member Fishcake's Avatar
    Join Date
    Feb 2001
    Location
    Derby, UK
    Posts
    1,092

    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;
    		}

  3. #3
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    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;
        }
    }
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  4. #4

    Thread Starter
    Hyperactive Member Rattlerr's Avatar
    Join Date
    Jul 2005
    Location
    FloralCity,Florida
    Posts
    269

    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
  •  



Click Here to Expand Forum to Full Width