School Assignment? Project Due Tomorrow? Chat LIVE With A Programming Expert!

Welcome to Dream.In.Code
Become an Expert!

Join 307,148 Programmers for FREE! Get instant access to thousands of experts, tutorials, code snippets, and more! There are 1,735 people online right now. Registration is fast and FREE... Join Now!




How to do massroll over buttons and mass handlers.

 
Reply to this topicStart new topic

> How to do massroll over buttons and mass handlers., Many people may wonder how to theme your aplications in Visual Basic.N

Ändrew
Group Icon



post 25 Apr, 2009 - 11:56 PM
Post #1


Hello there,

Many people may wonder how to theme your aplications in Visual Basic.NET and ill show you how.
First lets start a new project and we will call it themed buttons.

IPB Image

Make 3 buttons.

IPB Image

Now dubble click on the form and in the forms load put this code.

CODE

        'Turns all the buttons into flat ones'
        Button1.FlatStyle = FlatStyle.Flat
        Button2.FlatStyle = FlatStyle.Flat
        Button3.FlatStyle = FlatStyle.Flat
        'Turns all the buttons backcolour to red'
        Button1.BackColor = Color.Red
        Button2.BackColor = Color.Red
        Button3.BackColor = Color.Red


Now thats done we will add this code right under it remember we havent left the form load sub.

CODE

    'Magical code that lets us add handlers'
        For Teller As Integer = 0 To Controls.Count - 1
            Dim Control As Control = Controls(Teller)
            If Not Control.GetType() Is GetType(Button) Then
                Continue For
            End If
            Dim ButtonControl As Button = Control
            AddHandler ButtonControl.MouseEnter, AddressOf MyFunctionToTriggerOnMouseOver
            AddHandler ButtonControl.MouseLeave, AddressOf MyFunctionToTriggerOnMouseLeave
        AddHandler ButtonControl.MouseDown, AddressOf MyFunctionToTriggerOnMouseDown
        AddHandler ButtonControl.MouseUp, AddressOf MyFunctionToTriggerOnMouseUp
        Next


As you see we have errors.
Ok now we leave the sub and add 1 line and now type this code in this will fix the errors.

CODE

    Public Sub MyFunctionToTriggerOnMouseOver(ByVal sender As System.Object, ByVal e As System.EventArgs)
        Dim ButtonControl As Button = Sender
    'Changes the color of the buttons to blue when the mouse is over it'
        ButtonControl.BackColor = Color.Blue
    End Sub

    Public Sub MyFunctionToTriggerOnMouseLeave(ByVal sender As System.Object, ByVal e As System.EventArgs)
        Dim ButtonControl As Button = Sender
    'Changes the color back to red when the mouse leaves.'
        ButtonControl.BackColor = Color.Red
    End Sub

    Public Sub MyFunctionToTriggerOnMouseDown(ByVal sender As System.Object, ByVal e As System.EventArgs)
        Dim ButtonControl As Button = sender
    'Changes the color to green when mouse goes down.'
        ButtonControl.BackColor = Color.Green
    End Sub

    Public Sub MyFunctionToTriggerOnMouseUp(ByVal sender As System.Object, ByVal e As System.EventArgs)
        Dim ButtonControl As Button = sender
    'Changes the color to red when the mouse goes up'
        ButtonControl.BackColor = Color.Red
    End Sub


All the code should look about like this

IPB Image

Now the errors are gone!
Well now lets try this press the arrow on the quickbar to debug the program.

Now you can see and use this code in many ways to add handlers.

Credits:
Ändrew
Goethals
and any one else that I think helped me?
Go to the top of the page
+Quote Post


Register to Make This Ad Go Away!

noorahmad
Group Icon



post 22 May, 2009 - 11:29 PM
Post #2
nice tutorial dear.
Go to the top of the page
+Quote Post

LeisureProgrammer
**



post 19 Nov, 2009 - 11:52 AM
Post #3
TY so much for this tutorial! It'll save me hours!
Go to the top of the page
+Quote Post


Fast ReplyReply to this topicStart new topic
1 User(s) are reading this topic (1 Guests and 0 Anonymous Users)
0 Members:

 


Lo-Fi Version Time is now: 11/21/09 04:08PM

Live Help!

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter Fan Us On Facebook

Tutorials

Programming

Web Development

Reference Sheets

Code Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month