Home VB.NET 1 VB.NET 2 VB.NET 3 VB.NET 4 VB.NET 5 VB.NET 6 VB.NET 7 VB.NET 8 VB.NET 9 VB.NET 10 VB.NET 11 VB.NET 12 VB.NET 13 VB.NET 14 VB.NET 15 VB.NET 16 VB.NET 17 About

VB.NET 9

Code, Design and Applications


VISUAL BASIC .NET CONCEPTS

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

Coordinate System Changes in Visual Basic .Net

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

Drag and Drop Changes

' 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

Font Changes

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

Enumerating Font

Dim ff as FontFamily

For Each ff In System.Drawing.FontFamily.Families

listBox1.Items.Add(ff.Name)

Next

Graphic Changes

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

MousePointer Changes

' Visual Basic .NET

button1.Cursor = New System.Windows.Forms.Cursor("C:\mypath\mycursor.cur")

Control Array Changes

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

MaskColor Changes

' 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

Initializing Elements of Arrays

Dim Month() As Integer = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12}

Structure Declaration Changes

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

Variable Scope Changes

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.