No more!
I'll show you how to achieve the same only using code.
Public Class Form1
Dim myButton1 As Button
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
' Create s new button, associating it with the variable myButton1
myButton1 = New Button
We just created a new button object.
' Assign it some properties
With myButton1
.Left = 0
.Top = 10
.Text = "Press me"
.Width = 100
.Height = 100
.BackColor = Color.White
End With
Assigned it some properties.
Next is giving it the power to do and react to stuff.
' The following tells the control which peice of code to use the that event. ' Format: {Control Name}.{Event Name}, AddressOf {Routine name} AddHandler myButton1.Click, AddressOf Clicked_On_MyButton1 AddHandler myButton1.MouseHover, AddressOf MouseOver_MyButton1 AddHandler myButton1.MouseLeave, AddressOf MouseLeaving_MyButton1 ' Add it to the form Me.Controls.Add(myButton1) End Sub
The line Me.Controls.Add(myButton1) places it on to the form.
Add in the procedure to process the events.
Private Sub Clicked_On_MyButton1(ByVal sender As System.Object, ByVal e As System.EventArgs)
' The user has click on mybutton1, do something
MessageBox.Show("You clicked on myButton1")
End Sub
Private Sub MouseOver_MyButton1(ByVal sender As Object, ByVal e As System.EventArgs)
' mouse is over myButton1, do something
myButton1.BackColor = Color.Blue
End Sub
Private Sub MouseLeaving_MyButton1(ByVal sender As Object, ByVal e As System.EventArgs)
' The mouse is leaving myButton1, something
myButton1.BackColor = Color.White
End Sub
End Class
You may have noticed the difference between gui control code and coded.
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
End Sub
The coded control is missing
Handles Button1.Click
Now you can create controls with using the designer. (Code Ninja Style
This post has been edited by AdamSpeight2008: 28 July 2008 - 11:26 AM





MultiQuote




|