Code, Design and Applications
Controls Collection Changes
Private Sub button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles button1.Click
Dim textBox1 As New System.Windows.Forms.TextBox
textBox1.Text = "Hello"
Me.Controls.Add(textBox1)
If Me.Controls.Count > 1 Then
MsgBox(Me.Controls(Me.Controls.IndexOf(textBox1)).Text)
End If
Me.Controls.Remove(button1)
End sub
' Resizes the form to 640 pixels wide by 480 pixels high.
Me.Size = New System.Drawing.Size(640, 480)
' Visual Basic .NET
' Move and resize to 120 by 80 pixels.
button1.SetBounds(0, 0, 120, 80)
' Move and retain original size.
button2.SetBounds(20, 10, 0, 0, BoundsSpecified.X Or BoundsSpecified.Y)
' Visual Basic .NET
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
' Dropping must be enabled before the dragging occurs.
TextBox2.AllowDrop = True
End Sub
Private Sub TextBox1_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles TextBox1.MouseDown
TextBox1.Text = "Hello World"
' Begin dragging by calling the DoDragDrop method.
' OLEStartDrag is replaced by arguments on the method.
TextBox1.DoDragDrop(TextBox1.Text, DragDropEffects.Copy)
End Sub
Private Sub TextBox2_DragEnter(ByVal sender As Object, ByVal e As System.Windows.Forms.DragEventArgs) Handles TextBox2.DragEnter
' Make sure that the format is text.
If (e.Data.GetDataPresent(DataFormats.Text)) Then
' Allow drop.
e.Effect = DragDropEffects.Copy
Else
' Do not allow drop.
e.Effect = DragDropEffects.None
End If
End Sub
Private Sub TextBox2_DragDrop(ByVal sender As Object, ByVal e As System.Windows.Forms.DragEventArgs) Handles TextBox2.DragDrop
' Copy the text to the second TextBox.
TextBox2.Text = e.Data.GetData(DataFormats.Text).ToString
End Sub
' Assign a Font object — Name and Size are required.label1.Font = New System.Drawing.Font("Arial", 10)
' Assign additional attributes.
label1.Font = New System.Drawing.Font(label1.Font, FontStyle.Bold __ Or FontStyle.Italic)
Dim ff as FontFamily
For Each ff In System.Drawing.FontFamily.Families
listBox1.Items.Add(ff.Name)
Next
Private Sub Form1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Click
' Create a Pen object.
Dim pen As New Drawing.Pen(System.Drawing.Color.Red, 1)
Me.CreateGraphics.DrawEllipse(pen, 0, 0, 100, 100)
Pen.Dispose
End Sub
' Visual Basic .NET
button1.Cursor = New System.Windows.Forms.Cursor("C:\mypath\mycursor.cur")
Private Sub MixedControls_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click, Button2.Click, CheckBox1.Click
Select Case sender.TabIndex
Case 0
MsgBox("Button 1")
Case 1
MsgBox("Button 2")
Case 2
MsgBox("CheckBox 1")
End Select
End Sub
' Assumes a picture has been assigned to the BackgroundImage property.
Dim g As New System.Drawing.Bitmap(Button1.BackGroundImage)
g.MakeTransparent(System.Drawing.Color.White)
Button1.BackgroundImage = g
Dim Month() As Integer = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12}
Structure Employee
Public EmpNumber As Integer ' Must declare access, even if Public.
Dim EmpOfficePhone As String ' Still defaults to Public access.
Private EmpHomePhone As String ' Can be made Private inside Structure.
End Structure
Dim N As Long = 0 ' N is declared outside the block and has procedure scope.
For I As Integer = 1 To 10
N = N + Incr(I)
Next I
W = Base ^ N ' N is visible outside the block but I is not.