Module Module1
Sub Main()
Dim obj1 As New yourClass("AAA")
Dim obj2 As New yourClass("BBB")
obj1.displayMessage()
Console.WriteLine(obj2.yourName)
Console.ReadLine()
End Sub
End Module
Public Class yourClass
Private yourNameValue As String
'constructor initializes course name with String supplied as an argument
Public Sub New(ByVal Name As String)
yourNameValue = Name 'initialize yourNameValue via property
End Sub
'property yourName
Public Property yourName() As String
Get 'retrieve yourNameValue
Return yourNameValue
End Get
Set(ByVal value As String)
yourNameValue = value 'store the course name in the object
End Set
End Property 'set
Public Sub displayMessage()
Console.WriteLine("Welcome " & yourName & "!")
End Sub
End Class
Here is a tutorial on cycling through a forms controls
Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles actRed.Click
UpdateAllLabels(Color.Red)
End Sub
Private Sub updateAllLabels(ByVal withColor As Drawing.Color)
'scan all controls as control in me.controls
For Each scanControls As Control In Me.Controls
If (TypeOf scanControls Is Label) Then
scanControls.BackColor = withColor
End If
Next scanControls
End Sub
Private Sub actNormal_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles actNormal.Click
updateAllLabels(SystemColors.Control)
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
End Sub
End Class
Here is a tutorial for sharing event-handler logic among many controls
Private Sub MultipleEvents(ByVal sender As Object, ByVal e As System.EventArgs) Handles _
TextBox1.Enter, TextBox2.Enter, TextBox3.Enter, _
TextBox1.TextChanged, TextBox2.TextChanged, TextBox3.TextChanged
' --- Report the current status of this field
Dim activeControl As TextBox
activeControl = CType(sender, TextBox)
ShowInfo.Text = "Field #" & _
Microsoft.VisualBasic.Right(activeControl.Name, 1) & _
", " & activeControl.Text.Length & " character(s)"
End Sub
Here is another tutorial
Public Class Form1
Public WithEvents ColorList As ListBox
Dim listBoxMaker As bBuilder
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
listBoxMaker = New bBuilder
listBoxMaker.position()
listBoxMaker.add()
listBoxMaker.giveName("listbox1")
ColorList = Me.Controls("listbox1")
Me.Controls.Add(ColorList)
ColorList.Items.Add("Red")
ColorList.items.add("Orange")
ColorList.Items.Add("Yellow")
ColorList.Items.Add("Green")
ColorList.Items.add("Blue")
ColorList.Items.add("Indigo")
ColorList.Items.Add("Violet")
End Sub
Private Sub form1_Paint(ByVal sender As Object, _
ByVal e As System.Windows.Forms.PaintEventArgs)
' --- draw an ellipse on the form.
e.Graphics.DrawEllipse(Pens.Black, 10, 10, _
Me.ClientRectangle.Width - 20, _
Me.ClientRectangle.Height - 20)
End Sub
Private Sub XButton_Paint(ByVal sender As Object, _
ByVal e As System.Windows.Forms.PaintEventArgs) _
Handles xbutton.paint
' ---- draw a big x in a rectangle on the button surface
Dim usePen As Pen
'Provide a neutral background
e.Graphics.Clear(SystemColors.Control)
'----- draw the outline box.
usePen = New Pen(SystemColors.ControlText, 3)
e.Graphics.DrawRectangle(usePen, XButton.ClientRectangle)
'---Draw the
e.Graphics.DrawLine(usePen, 0, 0, _
XButton.Width, XButton.Height)
e.Graphics.DrawLine(usePen, 0, _
XButton.Height, XButton.Width, 0)
usePen.Dispose()
End Sub
Public Sub ColorList_DrawItem(ByVal sender As Object, _
ByVal e As System.Windows.Forms.DrawItemEventArgs) _
Handles ColorList.DrawItem
' --- Draw the color instead of the text
' ---- personal note: added withEvents to the colorList listbox
Dim useBrush As Brush
'--- check for a nonselected item
If (e.Index = -1) Then Return
'--- Set the neutral background
e.DrawBackground()
' ----- fill in the color
useBrush = New SolidBrush(Color.FromName(CStr(ColorList.Items(e.Index))))
e.Graphics.FillRectangle(useBrush, _
e.Bounds.Left + 2, e.Bounds.Top + 2, _
e.Bounds.Width - 4, e.Bounds.Height - 4)
useBrush.Dispose()
'---- Surround the color with a black rectangle.
e.Graphics.DrawRectangle(Pens.Black, _
e.Bounds.Left + 2, e.Bounds.Top + 2, _
e.Bounds.Width - 4, e.Bounds.Height - 4)
'show the item selected if needed
e.DrawFocusRectangle()
End Sub
Private Sub XButton_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles XButton.Click
MsgBox("Button clicked.")
End Sub
End Class
No comments:
Post a Comment