Results 1 to 5 of 5

Thread: [RESOLVED] [02/03] Noob Handler question (easy)

  1. #1

    Thread Starter
    Frenzied Member stimbo's Avatar
    Join Date
    Jun 2006
    Location
    UK
    Posts
    1,739

    Resolved [RESOLVED] [02/03] Noob Handler question (easy)

    I've had a look for the answer to this but can't find the answer but I'm sure this has been asked before.

    I have 8 buttons on a form. I have Mouse Enter and Mouse Leave actions that I want to implement for the buttons. The background colour and font size change so that the buttons have a slightly more dynamic behviour. I don't want to write 16 routines (2 for each button) and know there is an easier way to just reference that if the mouse enters the button area to do the required changes just for that button (same for Mouse leaving).

    I did the typical noob thing and got all 8 to change due to having added the handler to all buttons.

    How can i just get one button (the one the mouse enters/leaves) to do the action without them all doing it and not write out the code over and over again?

    Stim.

  2. #2
    Frenzied Member bmahler's Avatar
    Join Date
    Oct 2005
    Location
    Somewhere just west of the Atlantic
    Posts
    1,568

    Re: [02/03] Noob Handler question (easy)

    Here ya go

    VB Code:
    1. Private Sub Button_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click, Button2.Click, Button3.Click, Button4.Click
    2.         Dim btn As Button = CType(sender, Button)
    3.         'now you have the button that was pressed and can do whatever actions you need
    4.         btn.ForeColor = Color.Aqua
    5.     End Sub

    This can be used in any of the button events ie button_mouseover or whatever
    just make sure to add the proper handlers for all the buttons
    Last edited by bmahler; Sep 20th, 2006 at 02:43 PM.
    Boooya
    • Visual Studio 2008 Professional
    • Don't forget to use [CODE]your code here[/CODE] when posting code
    • Don't forget to rate helpful posts!
    • If you're question was answered please mark your thread [Resolved]


    Code Contributions:
    PHP
    PHP Image Gallery v1.0PHP Image Gallery v2.0
    VB 2005
    Find Computers on a networkSimple License EncryptionSQL Server Database Access dllUse Reflection to Return Crystal ReportDocumentSilently Print PDFGeneric Xml Serailizer


    Useful Links: (more to come)
    MSDN (The first and foremost)MSDN Design Guidelines API Reference • Inno Setup CompilerInno Setup PreprocessorISTool - Fairly easy to use GUI for creating inno setup projects • Connection StringsNAnt -Automated BuildsCruise Control .NET - Frontend for automated builds

  3. #3
    Frenzied Member zaza's Avatar
    Join Date
    Apr 2001
    Location
    Borneo Rainforest Habits: Scratching
    Posts
    1,486

    Re: [02/03] Noob Handler question (easy)

    Call a sub and pass it the button that you're using, along the lines of:


    VB Code:
    1. Friend Sub ButtonModSub(ByRef MyButton as Button)
    2.  
    3. MyButton.Colour = Blue
    4.  
    5. End Sub


    Or put it all in one Handler.

    zaza
    I use VB 6, VB.Net 2003 and Office 2010



    Code:
    Excel Graphing | Excel Timer | Excel Tips and Tricks | Add controls in Office | Data tables in Excel | Gaussian random number distribution (VB6/VBA,VB.Net) | Coordinates, Vectors and 3D volumes

  4. #4

    Thread Starter
    Frenzied Member stimbo's Avatar
    Join Date
    Jun 2006
    Location
    UK
    Posts
    1,739

    Re: [02/03] Noob Handler question (easy)

    Thanks guys,

    works a treat.

    Stim.

  5. #5
    Frenzied Member bmahler's Avatar
    Join Date
    Oct 2005
    Location
    Somewhere just west of the Atlantic
    Posts
    1,568

    Re: [RESOLVED] [02/03] Noob Handler question (easy)

    Boooya
    • Visual Studio 2008 Professional
    • Don't forget to use [CODE]your code here[/CODE] when posting code
    • Don't forget to rate helpful posts!
    • If you're question was answered please mark your thread [Resolved]


    Code Contributions:
    PHP
    PHP Image Gallery v1.0PHP Image Gallery v2.0
    VB 2005
    Find Computers on a networkSimple License EncryptionSQL Server Database Access dllUse Reflection to Return Crystal ReportDocumentSilently Print PDFGeneric Xml Serailizer


    Useful Links: (more to come)
    MSDN (The first and foremost)MSDN Design Guidelines API Reference • Inno Setup CompilerInno Setup PreprocessorISTool - Fairly easy to use GUI for creating inno setup projects • Connection StringsNAnt -Automated BuildsCruise Control .NET - Frontend for automated builds

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