Page 1 of 1

How to do massroll over buttons and mass handlers. Many people may wonder how to theme your aplications in Visual Basic.N Rate Topic: -----

#1 Ändrew   User is offline

  • D.I.C Regular
  • member icon

Reputation: 25
  • View blog
  • Posts: 312
  • Joined: 21-April 08

Post icon  Posted 26 April 2009 - 12:56 AM

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.

Posted Image

Make 3 buttons.

Posted Image

Now dubble click on the form and in the forms load put this 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.

	'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.

	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

Posted 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?

Is This A Good Question/Topic? 1
  • +

Replies To: How to do massroll over buttons and mass handlers.

#2 noorahmad   User is offline

  • Untitled
  • member icon

Reputation: 209
  • View blog
  • Posts: 2,290
  • Joined: 12-March 09

Posted 23 May 2009 - 12:29 AM

nice tutorial dear.
Was This Post Helpful? 1
  • +
  • -

#3 LeisureProgrammer   User is offline

  • N00by VB.NET Developer
  • member icon

Reputation: 110
  • View blog
  • Posts: 588
  • Joined: 06-September 09

Posted 19 November 2009 - 12:52 PM

TY so much for this tutorial! It'll save me hours!
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1