Results 1 to 9 of 9

Thread: Button Help[resolved]

  1. #1

    Thread Starter
    Hyperactive Member imadthemad's Avatar
    Join Date
    May 2005
    Posts
    344

    Resolved Button Help[resolved]

    ok i have 30 buttons on a calculator form
    i want to make a function so when the mouse is over each button, it changes back color

    how can i do that without writing a mousemove or code for each of them?

    tx in advance,
    imad akel
    Last edited by imadthemad; Jun 6th, 2005 at 12:11 PM.

  2. #2
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: Button Help

    Place event handlers on the single procedure for all buttons of concern.
    VB Code:
    1. Private Sub Button1_MouseEnter(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.MouseEnter, _
    2.     Button2.MouseEnter, Button3.MouseEnter, Button4.MouseEnter, Button5.MouseEnter
    3.         'All buttons listed in the Handles list will run this procedure
    4.         'Change backcolor to new color
    5.     End Sub
    6.  
    7.     Private Sub Button1_MouseLeave(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.MouseLeave, _
    8.     Button2.MouseEnter, Button3.MouseEnter, Button4.MouseEnter, Button5.MouseEnter
    9.         'All buttons listed in the Handles list will run this procedure
    10.         'Change backcolor to original color
    11.     End Sub
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  3. #3

    Thread Starter
    Hyperactive Member imadthemad's Avatar
    Join Date
    May 2005
    Posts
    344

    Re: Button Help

    prob with that code
    when the mouse is over 1 of these buttons, all 30 of them change backcolor....

    mayb i am doing something wrong?

    alittle more help please...

  4. #4
    Addicted Member
    Join Date
    Apr 2005
    Location
    Croatia
    Posts
    183

    Re: Button Help

    I listed all my buttons. How to change the color now?
    It has been said that something as
    small as the flutter of a butterfly's
    wing can ultimately cause a typhoon
    halfway around the world...


  5. #5
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: Button Help

    You need to convert the sender object so you can determine which control to manipulate.
    VB Code:
    1. CType(sender, Button).BackColor = Color.LightGoldenrodYellow
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  6. #6
    Addicted Member
    Join Date
    Apr 2005
    Location
    Croatia
    Posts
    183

    Re: Button Help

    Thanks!
    It has been said that something as
    small as the flutter of a butterfly's
    wing can ultimately cause a typhoon
    halfway around the world...


  7. #7
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: Button Help

    The Color object can be found in the System.Drawing namespace.
    VB Code:
    1. 'At the top of your class...
    2. Imports System.Drawing
    3.  
    4. 'Or dont use the Imports declaration and just type it all out.
    5. CType(sender, Button).Backcolor = System.Drawing.Color.LightGoldenrodYellow
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  8. #8

    Thread Starter
    Hyperactive Member imadthemad's Avatar
    Join Date
    May 2005
    Posts
    344

    Re: Button Help

    Excellent code
    thanx billions that saves alot of time
    now i know what the sender object is for

    TY

  9. #9
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: Button Help

    Glad you got it working now.

    Ps, dont forget to 'Resolve' your thread so others will know its solved.
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

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