VB.Net by API/System.Windows.Forms/Form

Материал из VB Эксперт
Перейти к: навигация, поиск

Form.AcceptButton

<source lang="vbnet">

Imports System Imports System.Collections Imports System.Data Imports System.IO Imports System.Xml.Serialization Imports System.Windows.Forms Imports System.Drawing Imports System.Drawing.Drawing2D Imports System.Drawing.Text Imports System.Drawing.Printing

Public Class MainClass

   Shared Sub Main()
       Dim myForm As New Form1()
       If myForm.ShowDialog() = DialogResult.Cancel Then
           MessageBox.Show("You pressed the cancel button")
       Else
           MessageBox.Show("You pressed OK.")
       End If
   End Sub

End Class

Public Class Form1

   Inherits System.Windows.Forms.Form
  1. Region " Windows Form Designer generated code "
   Public Sub New()
       MyBase.New()
       "This call is required by the Windows Form Designer.
       InitializeComponent()
       "Add any initialization after the InitializeComponent() call
   End Sub
   "Form overrides dispose to clean up the component list.
   Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
       If disposing Then
           If Not (components Is Nothing) Then
               components.Dispose()
           End If
       End If
       MyBase.Dispose(disposing)
   End Sub
   Friend WithEvents btnOK As System.Windows.Forms.Button
   Friend WithEvents btnCancel As System.Windows.Forms.Button
   Friend WithEvents PictureBox1 As System.Windows.Forms.PictureBox
   "Required by the Windows Form Designer
   Private components As System.ruponentModel.Container
   "NOTE: The following procedure is required by the Windows Form Designer
   "It can be modified using the Windows Form Designer.  
   "Do not modify it using the code editor.
   <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
       Me.PictureBox1 = New System.Windows.Forms.PictureBox()
       Me.btnCancel = New System.Windows.Forms.Button()
       Me.btnOK = New System.Windows.Forms.Button()
       Me.SuspendLayout()
       "
       "PictureBox1
       "
       Me.PictureBox1.Anchor = ((System.Windows.Forms.AnchorStyles.Top Or System.Windows.Forms.AnchorStyles.Left) _
                   Or System.Windows.Forms.AnchorStyles.Right)
       Me.PictureBox1.Location = New System.Drawing.Point(0, 8)
       Me.PictureBox1.Name = "PictureBox1"
       Me.PictureBox1.Size = New System.Drawing.Size(288, 184)
       Me.PictureBox1.SizeMode = System.Windows.Forms.PictureBoxSizeMode.StretchImage
       Me.PictureBox1.TabIndex = 2
       Me.PictureBox1.TabStop = False
       "
       "btnCancel
       "
       Me.btnCancel.Anchor = System.Windows.Forms.AnchorStyles.Bottom
       Me.btnCancel.DialogResult = System.Windows.Forms.DialogResult.Cancel
       Me.btnCancel.Location = New System.Drawing.Point(168, 240)
       Me.btnCancel.Name = "btnCancel"
       Me.btnCancel.Size = New System.Drawing.Size(88, 32)
       Me.btnCancel.TabIndex = 1
       Me.btnCancel.Text = "Cancel"
       "
       "btnOK
       "
       Me.btnOK.Anchor = System.Windows.Forms.AnchorStyles.Bottom
       Me.btnOK.DialogResult = System.Windows.Forms.DialogResult.OK
       Me.btnOK.Location = New System.Drawing.Point(40, 240)
       Me.btnOK.Name = "btnOK"
       Me.btnOK.Size = New System.Drawing.Size(80, 32)
       Me.btnOK.TabIndex = 0
       Me.btnOK.Text = "OK"
       "
       "Form1
       "
       Me.AutoScaleBaseSize = New System.Drawing.Size(6, 15)
       Me.ClientSize = New System.Drawing.Size(292, 288)
       Me.ControlBox = False
       Me.Controls.AddRange(New System.Windows.Forms.Control() {Me.PictureBox1, Me.btnCancel, Me.btnOK})
       Me.MaximizeBox = False
       Me.MinimizeBox = False
       Me.Name = "Form1"
       Me.Text = "Sample Custom dialog box"
       Me.ResumeLayout(False)
   End Sub
  1. End Region
   Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
       Me.Visible = False
       Me.AcceptButton = btnOK
       Me.CancelButton = btnCancel
   End Sub

End Class


 </source>


Form.Activated

<source lang="vbnet"> Imports System.Windows.Forms Module Module1

   Sub Main()
       Application.Run(New Form1)
   End Sub

End Module Public Class Form1

   Inherits System.Windows.Forms.Form
  1. Region " Windows Form Designer generated code "
   Public Sub New()
       MyBase.New()
       "This call is required by the Windows Form Designer.
       InitializeComponent()
       "Add any initialization after the InitializeComponent() call
   End Sub
   "Form overrides dispose to clean up the component list.
   Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
       If disposing Then
           If Not (components Is Nothing) Then
               components.Dispose()
           End If
       End If
       MyBase.Dispose(disposing)
   End Sub
   "Required by the Windows Form Designer
   Private components As System.ruponentModel.IContainer
   "NOTE: The following procedure is required by the Windows Form Designer
   "It can be modified using the Windows Form Designer.  
   "Do not modify it using the code editor.
   Friend WithEvents TabControl1 As System.Windows.Forms.TabControl
   Friend WithEvents TabPage1 As System.Windows.Forms.TabPage
   Friend WithEvents TabPage2 As System.Windows.Forms.TabPage
   Friend WithEvents TabPage3 As System.Windows.Forms.TabPage
   Friend WithEvents TabPage4 As System.Windows.Forms.TabPage
   Friend WithEvents TextBox1 As System.Windows.Forms.TextBox
   Friend WithEvents TextBox2 As System.Windows.Forms.TextBox
   Friend WithEvents TextBox3 As System.Windows.Forms.TextBox
   Friend WithEvents TextBox4 As System.Windows.Forms.TextBox
   <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
       Me.TabControl1 = New System.Windows.Forms.TabControl()
       Me.TabPage1 = New System.Windows.Forms.TabPage()
       Me.TextBox1 = New System.Windows.Forms.TextBox()
       Me.TabPage2 = New System.Windows.Forms.TabPage()
       Me.TextBox2 = New System.Windows.Forms.TextBox()
       Me.TabPage3 = New System.Windows.Forms.TabPage()
       Me.TextBox3 = New System.Windows.Forms.TextBox()
       Me.TabPage4 = New System.Windows.Forms.TabPage()
       Me.TextBox4 = New System.Windows.Forms.TextBox()
       Me.TabControl1.SuspendLayout()
       Me.TabPage1.SuspendLayout()
       Me.TabPage2.SuspendLayout()
       Me.TabPage3.SuspendLayout()
       Me.TabPage4.SuspendLayout()
       Me.SuspendLayout()
       "
       "TabControl1
       "
       Me.TabControl1.Controls.AddRange(New System.Windows.Forms.Control() {Me.TabPage1, Me.TabPage2, Me.TabPage3, Me.TabPage4})
       Me.TabControl1.Location = New System.Drawing.Point(48, 48)
       Me.TabControl1.Name = "TabControl1"
       Me.TabControl1.SelectedIndex = 0
       Me.TabControl1.Size = New System.Drawing.Size(288, 200)
       Me.TabControl1.TabIndex = 0
       "
       "TabPage1
       "
       Me.TabPage1.Controls.AddRange(New System.Windows.Forms.Control() {Me.TextBox1})
       Me.TabPage1.Location = New System.Drawing.Point(4, 22)
       Me.TabPage1.Name = "TabPage1"
       Me.TabPage1.Size = New System.Drawing.Size(280, 174)
       Me.TabPage1.TabIndex = 0
       Me.TabPage1.Text = "Visual Basic .Net"
       "
       "TextBox1
       "
       Me.TextBox1.Location = New System.Drawing.Point(8, 8)
       Me.TextBox1.Multiline = True
       Me.TextBox1.Name = "TextBox1"
       Me.TextBox1.Size = New System.Drawing.Size(264, 160)
       Me.TextBox1.TabIndex = 0
       Me.TextBox1.Text = ""
       "
       "TabPage2
       "
       Me.TabPage2.Controls.AddRange(New System.Windows.Forms.Control() {Me.TextBox2})
       Me.TabPage2.Location = New System.Drawing.Point(4, 22)
       Me.TabPage2.Name = "TabPage2"
       Me.TabPage2.Size = New System.Drawing.Size(280, 174)
       Me.TabPage2.TabIndex = 1
       Me.TabPage2.Text = "C# "
       "
       "TextBox2
       "
       Me.TextBox2.Location = New System.Drawing.Point(8, 8)
       Me.TextBox2.Multiline = True
       Me.TextBox2.Name = "TextBox2"
       Me.TextBox2.Size = New System.Drawing.Size(264, 160)
       Me.TextBox2.TabIndex = 0
       Me.TextBox2.Text = ""
       "
       "TabPage3
       "
       Me.TabPage3.Controls.AddRange(New System.Windows.Forms.Control() {Me.TextBox3})
       Me.TabPage3.Location = New System.Drawing.Point(4, 22)
       Me.TabPage3.Name = "TabPage3"
       Me.TabPage3.Size = New System.Drawing.Size(280, 174)
       Me.TabPage3.TabIndex = 2
       Me.TabPage3.Text = "HTML"
       "
       "TextBox3
       "
       Me.TextBox3.Location = New System.Drawing.Point(8, 8)
       Me.TextBox3.Multiline = True
       Me.TextBox3.Name = "TextBox3"
       Me.TextBox3.Size = New System.Drawing.Size(264, 160)
       Me.TextBox3.TabIndex = 0
       Me.TextBox3.Text = ""
       "
       "TabPage4
       "
       Me.TabPage4.Controls.AddRange(New System.Windows.Forms.Control() {Me.TextBox4})
       Me.TabPage4.Location = New System.Drawing.Point(4, 22)
       Me.TabPage4.Name = "TabPage4"
       Me.TabPage4.Size = New System.Drawing.Size(280, 174)
       Me.TabPage4.TabIndex = 3
       Me.TabPage4.Text = "Upgrading"
       "
       "TextBox4
       "
       Me.TextBox4.Location = New System.Drawing.Point(8, 8)
       Me.TextBox4.Multiline = True
       Me.TextBox4.Name = "TextBox4"
       Me.TextBox4.Size = New System.Drawing.Size(264, 160)
       Me.TextBox4.TabIndex = 0
       Me.TextBox4.Text = ""
       "
       "Form1
       "
       Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
       Me.ClientSize = New System.Drawing.Size(528, 389)
       Me.Controls.AddRange(New System.Windows.Forms.Control() {Me.TabControl1})
       Me.Name = "Form1"
       Me.Text = "TabControlDemo"
       Me.TabControl1.ResumeLayout(False)
       Me.TabPage1.ResumeLayout(False)
       Me.TabPage2.ResumeLayout(False)
       Me.TabPage3.ResumeLayout(False)
       Me.TabPage4.ResumeLayout(False)
       Me.ResumeLayout(False)
   End Sub
  1. End Region
   Private Sub Form1_Activated(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Activated
       TextBox1.Text = "some text"
       TextBox2.Text = "some text"
       TextBox3.Text = "some text"
       TextBox4.Text = "some text"
   End Sub

End Class


 </source>


Form.AddOwnedForm

<source lang="vbnet"> Imports System Imports System.Drawing Imports System.Windows.Forms Imports System.ruponentModel Public Class MainClass

   Shared Sub Main()
       Dim form1 As Form = New Form1
       Application.Run(form1)
   End Sub

End Class Public Class OwnedForm

   Inherits System.Windows.Forms.Form
  1. Region " Windows Form Designer generated code "
   Public Sub New()
       MyBase.New()
       "This call is required by the Windows Form Designer.
       InitializeComponent()
       "Add any initialization after the InitializeComponent() call
   End Sub
   "Form overrides dispose to clean up the component list.
   Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
       If disposing Then
           If Not (components Is Nothing) Then
               components.Dispose()
           End If
       End If
       MyBase.Dispose(disposing)
   End Sub
   Friend WithEvents lblState As System.Windows.Forms.Label
   "Required by the Windows Form Designer
   Private components As System.ruponentModel.Container
   "NOTE: The following procedure is required by the Windows Form Designer
   "It can be modified using the Windows Form Designer.  
   "Do not modify it using the code editor.
   <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
       Me.lblState = New System.Windows.Forms.Label()
       Me.SuspendLayout()
       "
       "lblState
       "
       Me.lblState.Location = New System.Drawing.Point(12, 12)
       Me.lblState.Name = "lblState"
       Me.lblState.Size = New System.Drawing.Size(184, 56)
       Me.lblState.TabIndex = 0
       "
       "OwnedForm
       "
       Me.AutoScaleBaseSize = New System.Drawing.Size(5, 14)
       Me.ClientSize = New System.Drawing.Size(204, 78)
       Me.Controls.AddRange(New System.Windows.Forms.Control() {Me.lblState})
       Me.Font = New System.Drawing.Font("Tahoma", 8.25!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
       Me.Name = "OwnedForm"
       Me.StartPosition = System.Windows.Forms.FormStartPosition.Manual
       Me.Text = "Owned Form"
       Me.ResumeLayout(False)
   End Sub
  1. End Region

End Class

Public Class Form1

   Inherits System.Windows.Forms.Form
  1. Region " Windows Form Designer generated code "
   Public Sub New()
       MyBase.New()
       "This call is required by the Windows Form Designer.
       InitializeComponent()
       "Add any initialization after the InitializeComponent() call
   End Sub
   "Form overrides dispose to clean up the component list.
   Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
       If disposing Then
           If Not (components Is Nothing) Then
               components.Dispose()
           End If
       End If
       MyBase.Dispose(disposing)
   End Sub
   Friend WithEvents cmdAddOwnership As System.Windows.Forms.Button
   Friend WithEvents cmdReleaseOwnership As System.Windows.Forms.Button
   "Required by the Windows Form Designer
   Private components As System.ruponentModel.Container
   "NOTE: The following procedure is required by the Windows Form Designer
   "It can be modified using the Windows Form Designer.  
   "Do not modify it using the code editor.
   Friend WithEvents label1 As System.Windows.Forms.Label
   <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
       Me.cmdAddOwnership = New System.Windows.Forms.Button()
       Me.cmdReleaseOwnership = New System.Windows.Forms.Button()
       Me.label1 = New System.Windows.Forms.Label()
       Me.SuspendLayout()
       "
       "cmdAddOwnership
       "
       Me.cmdAddOwnership.FlatStyle = System.Windows.Forms.FlatStyle.System
       Me.cmdAddOwnership.Location = New System.Drawing.Point(12, 180)
       Me.cmdAddOwnership.Name = "cmdAddOwnership"
       Me.cmdAddOwnership.Size = New System.Drawing.Size(120, 32)
       Me.cmdAddOwnership.TabIndex = 0
       Me.cmdAddOwnership.Text = "Set Ownership"
       "
       "cmdReleaseOwnership
       "
       Me.cmdReleaseOwnership.FlatStyle = System.Windows.Forms.FlatStyle.System
       Me.cmdReleaseOwnership.Location = New System.Drawing.Point(148, 180)
       Me.cmdReleaseOwnership.Name = "cmdReleaseOwnership"
       Me.cmdReleaseOwnership.Size = New System.Drawing.Size(128, 32)
       Me.cmdReleaseOwnership.TabIndex = 1
       Me.cmdReleaseOwnership.Text = "Remove Ownership"
       "
       "label1
       "
       Me.label1.Location = New System.Drawing.Point(40, 32)
       Me.label1.Name = "label1"
       Me.label1.Size = New System.Drawing.Size(216, 80)
       Me.label1.TabIndex = 5
       Me.label1.Text = "Minimize to check the ownership."
       "
       "Owner
       "
       Me.AutoScaleBaseSize = New System.Drawing.Size(5, 14)
       Me.ClientSize = New System.Drawing.Size(288, 222)
       Me.Controls.AddRange(New System.Windows.Forms.Control() {Me.label1, Me.cmdReleaseOwnership, Me.cmdAddOwnership})
       Me.Font = New System.Drawing.Font("Tahoma", 8.25!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
       Me.Name = "Owner"
       Me.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen
       Me.Text = "Basic Form"
       Me.ResumeLayout(False)
   End Sub
  1. End Region
   Private frmOwned As New OwnedForm()
   Private Sub Owner_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
       Me.Show()
       frmOwned.Show()
   End Sub
   Private Sub cmdAddOwnership_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdAddOwnership.Click
       Me.AddOwnedForm(frmOwned)
       frmOwned.lblState.Text = "I"m Owned"
   End Sub
   Private Sub cmdReleaseOwnership_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdReleaseOwnership.Click
       Me.RemoveOwnedForm(frmOwned)
       frmOwned.lblState.Text = "I"m Free!"
   End Sub

End Class


 </source>


Form.AutoScaleBaseSize

<source lang="vbnet"> Imports System.Drawing Imports System.Drawing.Drawing2D Imports System.Windows.Forms public class TextureTransform

  public Shared Sub Main
       Application.Run(New Form1)
  End Sub

End class public class Form1

 Inherits System.Windows.Forms.Form
 Protected Overrides Sub OnPaint(ByVal e As PaintEventArgs)
       Dim g As Graphics = e.Graphics
       Dim str As String = "www.vbex.ru www.vbex.ru www.vbex.ru www.vbex.ru www.vbex.ru www.vbex.ru www.vbex.ru www.vbex.ru www.vbex.ru www.vbex.ru www.vbex.ru www.vbex.ru www.vbex.ru www.vbex.ru www.vbex.ru www.vbex.ru www.vbex.ru www.vbex.ru www.vbex.ru www.vbex.ru www.vbex.ru www.vbex.ru www.vbex.ru www.vbex.ru www.vbex.ru www.vbex.ru www.vbex.ru www.vbex.ru www.vbex.ru www.vbex.ru www.vbex.ru www.vbex.ru www.vbex.ru www.vbex.ru www.vbex.ru www.vbex.ru www.vbex.ru www.vbex.ru www.vbex.ru www.vbex.ru www.vbex.ru www.vbex.ru www.vbex.ru www.vbex.ru www.vbex.ru www.vbex.ru www.vbex.ru www.vbex.ru www.vbex.ru www.vbex.ru www.vbex.ru www.vbex.ru "
       g.ScaleTransform(2, 1)
       g.RotateTransform(45.0F, System.Drawing.Drawing2D.MatrixOrder.Prepend)
       g.TranslateTransform(-20, -70)
       g.DrawString(str, New Font("Verdana", 10), New SolidBrush(Color.Blue), New RectangleF(50, 20, 200, 300))
 End Sub
 Public Sub New()
  
   MyBase.New()
   Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
   Me.ClientSize = New System.Drawing.Size(292, 273)
   Me.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen
 End Sub

End Class


 </source>


Form.AutoScroll

<source lang="vbnet"> Imports System Imports System.Drawing Imports System.Windows.Forms Imports System.ruponentModel Imports System.Drawing.Drawing2D Imports System.IO Public Class MainClass

   Shared Sub Main()
       Dim form1 As Form = New Form1
       Application.Run(form1)
   End Sub

End Class

Public Class Form1

   Inherits System.Windows.Forms.Form
  1. Region " Windows Form Designer generated code "
   Public Sub New()
       MyBase.New()
       "This call is required by the Windows Form Designer.
       InitializeComponent()
       "Add any initialization after the InitializeComponent() call
   End Sub
   "Form overrides dispose to clean up the component list.
   Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
       If disposing Then
           If Not (components Is Nothing) Then
               components.Dispose()
           End If
       End If
       MyBase.Dispose(disposing)
   End Sub
   "Required by the Windows Form Designer
   Private components As System.ruponentModel.IContainer
   "NOTE: The following procedure is required by the Windows Form Designer
   "It can be modified using the Windows Form Designer.  
   "Do not modify it using the code editor.
   Friend WithEvents Panel1 As System.Windows.Forms.Panel
   Friend WithEvents Button1 As System.Windows.Forms.Button
   Friend WithEvents Button2 As System.Windows.Forms.Button
   Friend WithEvents Button3 As System.Windows.Forms.Button
   Friend WithEvents Button4 As System.Windows.Forms.Button
   Friend WithEvents Button5 As System.Windows.Forms.Button
   Friend WithEvents Button6 As System.Windows.Forms.Button
   <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
       Me.Panel1 = New System.Windows.Forms.Panel()
       Me.Button6 = New System.Windows.Forms.Button()
       Me.Button5 = New System.Windows.Forms.Button()
       Me.Button4 = New System.Windows.Forms.Button()
       Me.Button3 = New System.Windows.Forms.Button()
       Me.Button2 = New System.Windows.Forms.Button()
       Me.Button1 = New System.Windows.Forms.Button()
       Me.Panel1.SuspendLayout()
       Me.SuspendLayout()
       "
       "Panel1
       "
       Me.Panel1.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D
       Me.Panel1.Controls.AddRange(New System.Windows.Forms.Control() {Me.Button6, Me.Button5, Me.Button4, Me.Button3, Me.Button2, Me.Button1})
       Me.Panel1.Location = New System.Drawing.Point(8, 8)
       Me.Panel1.Name = "Panel1"
       Me.Panel1.Size = New System.Drawing.Size(260, 232)
       Me.Panel1.TabIndex = 0
       "
       "Button6
       "
       Me.Button6.FlatStyle = System.Windows.Forms.FlatStyle.System
       Me.Button6.Location = New System.Drawing.Point(16, 180)
       Me.Button6.Name = "Button6"
       Me.Button6.Size = New System.Drawing.Size(168, 24)
       Me.Button6.TabIndex = 5
       Me.Button6.Text = "Button6"
       "
       "Button5
       "
       Me.Button5.FlatStyle = System.Windows.Forms.FlatStyle.System
       Me.Button5.Location = New System.Drawing.Point(16, 148)
       Me.Button5.Name = "Button5"
       Me.Button5.Size = New System.Drawing.Size(168, 24)
       Me.Button5.TabIndex = 4
       Me.Button5.Text = "Button5"
       "
       "Button4
       "
       Me.Button4.FlatStyle = System.Windows.Forms.FlatStyle.System
       Me.Button4.Location = New System.Drawing.Point(16, 116)
       Me.Button4.Name = "Button4"
       Me.Button4.Size = New System.Drawing.Size(168, 24)
       Me.Button4.TabIndex = 3
       Me.Button4.Text = "Button4"
       "
       "Button3
       "
       Me.Button3.FlatStyle = System.Windows.Forms.FlatStyle.System
       Me.Button3.Location = New System.Drawing.Point(16, 84)
       Me.Button3.Name = "Button3"
       Me.Button3.Size = New System.Drawing.Size(168, 24)
       Me.Button3.TabIndex = 2
       Me.Button3.Text = "Button3"
       "
       "Button2
       "
       Me.Button2.FlatStyle = System.Windows.Forms.FlatStyle.System
       Me.Button2.Location = New System.Drawing.Point(16, 52)
       Me.Button2.Name = "Button2"
       Me.Button2.Size = New System.Drawing.Size(168, 24)
       Me.Button2.TabIndex = 1
       Me.Button2.Text = "Button2"
       "
       "Button1
       "
       Me.Button1.FlatStyle = System.Windows.Forms.FlatStyle.System
       Me.Button1.Location = New System.Drawing.Point(16, 20)
       Me.Button1.Name = "Button1"
       Me.Button1.Size = New System.Drawing.Size(168, 24)
       Me.Button1.TabIndex = 0
       Me.Button1.Text = "Button1"
       "
       "ScrollableForm
       "
       Me.AutoScaleBaseSize = New System.Drawing.Size(5, 14)
       Me.AutoScroll = True
       Me.ClientSize = New System.Drawing.Size(224, 147)
       Me.Controls.AddRange(New System.Windows.Forms.Control() {Me.Panel1})
       Me.Font = New System.Drawing.Font("Tahoma", 8.25!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
       Me.Name = "ScrollableForm"
       Me.Text = "Scrollable Form"
       Me.Panel1.ResumeLayout(False)
       Me.ResumeLayout(False)
   End Sub
  1. End Region
   Private Sub ScrollableForm_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
       Me.Refresh()
   End Sub

End Class


 </source>


Form.CancelButton

<source lang="vbnet"> Imports System Imports System.Collections Imports System.Data Imports System.IO Imports System.Xml.Serialization Imports System.Windows.Forms Imports System.Drawing Imports System.Drawing.Drawing2D Imports System.Drawing.Text Imports System.Drawing.Printing

Public Class MainClass

   Shared Sub Main()
       Dim myForm As New Form1()
       If myForm.ShowDialog() = DialogResult.Cancel Then
           MessageBox.Show("You pressed the cancel button")
       Else
           MessageBox.Show("You pressed OK.")
       End If
   End Sub

End Class

Public Class Form1

   Inherits System.Windows.Forms.Form
  1. Region " Windows Form Designer generated code "
   Public Sub New()
       MyBase.New()
       "This call is required by the Windows Form Designer.
       InitializeComponent()
       "Add any initialization after the InitializeComponent() call
   End Sub
   "Form overrides dispose to clean up the component list.
   Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
       If disposing Then
           If Not (components Is Nothing) Then
               components.Dispose()
           End If
       End If
       MyBase.Dispose(disposing)
   End Sub
   Friend WithEvents btnOK As System.Windows.Forms.Button
   Friend WithEvents btnCancel As System.Windows.Forms.Button
   Friend WithEvents PictureBox1 As System.Windows.Forms.PictureBox
   "Required by the Windows Form Designer
   Private components As System.ruponentModel.Container
   "NOTE: The following procedure is required by the Windows Form Designer
   "It can be modified using the Windows Form Designer.  
   "Do not modify it using the code editor.
   <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
       Me.PictureBox1 = New System.Windows.Forms.PictureBox()
       Me.btnCancel = New System.Windows.Forms.Button()
       Me.btnOK = New System.Windows.Forms.Button()
       Me.SuspendLayout()
       "
       "PictureBox1
       "
       Me.PictureBox1.Anchor = ((System.Windows.Forms.AnchorStyles.Top Or System.Windows.Forms.AnchorStyles.Left) _
                   Or System.Windows.Forms.AnchorStyles.Right)
       Me.PictureBox1.Location = New System.Drawing.Point(0, 8)
       Me.PictureBox1.Name = "PictureBox1"
       Me.PictureBox1.Size = New System.Drawing.Size(288, 184)
       Me.PictureBox1.SizeMode = System.Windows.Forms.PictureBoxSizeMode.StretchImage
       Me.PictureBox1.TabIndex = 2
       Me.PictureBox1.TabStop = False
       "
       "btnCancel
       "
       Me.btnCancel.Anchor = System.Windows.Forms.AnchorStyles.Bottom
       Me.btnCancel.DialogResult = System.Windows.Forms.DialogResult.Cancel
       Me.btnCancel.Location = New System.Drawing.Point(168, 240)
       Me.btnCancel.Name = "btnCancel"
       Me.btnCancel.Size = New System.Drawing.Size(88, 32)
       Me.btnCancel.TabIndex = 1
       Me.btnCancel.Text = "Cancel"
       "
       "btnOK
       "
       Me.btnOK.Anchor = System.Windows.Forms.AnchorStyles.Bottom
       Me.btnOK.DialogResult = System.Windows.Forms.DialogResult.OK
       Me.btnOK.Location = New System.Drawing.Point(40, 240)
       Me.btnOK.Name = "btnOK"
       Me.btnOK.Size = New System.Drawing.Size(80, 32)
       Me.btnOK.TabIndex = 0
       Me.btnOK.Text = "OK"
       "
       "Form1
       "
       Me.AutoScaleBaseSize = New System.Drawing.Size(6, 15)
       Me.ClientSize = New System.Drawing.Size(292, 288)
       Me.ControlBox = False
       Me.Controls.AddRange(New System.Windows.Forms.Control() {Me.PictureBox1, Me.btnCancel, Me.btnOK})
       Me.MaximizeBox = False
       Me.MinimizeBox = False
       Me.Name = "Form1"
       Me.Text = "Sample Custom dialog box"
       Me.ResumeLayout(False)
   End Sub
  1. End Region
   Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
       Me.Visible = False
       Me.AcceptButton = btnOK
       Me.CancelButton = btnCancel
   End Sub

End Class


 </source>


Form.Click

<source lang="vbnet"> Imports System.Diagnostics Imports System.Windows.Forms public class FormEvents

  public Shared Sub Main
       Application.Run(New Form1)
  End Sub

End class

Public Class Form1

   Inherits System.Windows.Forms.Form
  1. Region " Windows Form Designer generated code "
   Public Sub New()
       MyBase.New()
       "This call is required by the Windows Form Designer.
       InitializeComponent()
       "Add any initialization after the InitializeComponent() call
       Console.WriteLine("New Event Fired")
   End Sub
   "Form overrides dispose to clean up the component list.
   Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
       Console.WriteLine("Dispose Method Executed")
       If disposing Then
           If Not (components Is Nothing) Then
               components.Dispose()
           End If
       End If
       MyBase.Dispose(disposing)
   End Sub
   Friend WithEvents btnLoop As System.Windows.Forms.Button
   Friend WithEvents btnRemember As System.Windows.Forms.Button
   Friend WithEvents Button1 As System.Windows.Forms.Button
   Friend WithEvents Button2 As System.Windows.Forms.Button
   Friend WithEvents Button3 As System.Windows.Forms.Button
   "Required by the Windows Form Designer
   Private components As System.ruponentModel.IContainer
   "NOTE: The following procedure is required by the Windows Form Designer
   "It can be modified using the Windows Form Designer.  
   "Do not modify it using the code editor.
   <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
       Me.btnLoop = New System.Windows.Forms.Button()
       Me.btnRemember = New System.Windows.Forms.Button()
       Me.Button1 = New System.Windows.Forms.Button()
       Me.Button2 = New System.Windows.Forms.Button()
       Me.Button3 = New System.Windows.Forms.Button()
       Me.SuspendLayout()
       "
       "btnLoop
       "
       Me.btnLoop.Location = New System.Drawing.Point(24, 56)
       Me.btnLoop.Name = "btnLoop"
       Me.btnLoop.TabIndex = 0
       Me.btnLoop.Text = "Loop"
       "
       "btnRemember
       "
       Me.btnRemember.Location = New System.Drawing.Point(136, 56)
       Me.btnRemember.Name = "btnRemember"
       Me.btnRemember.Size = New System.Drawing.Size(112, 23)
       Me.btnRemember.TabIndex = 1
       Me.btnRemember.Text = "Remember Position"
       "
       "Button1
       "
       Me.Button1.Location = New System.Drawing.Point(24, 16)
       Me.Button1.Name = "Button1"
       Me.Button1.TabIndex = 2
       Me.Button1.Text = "Button1"
       "
       "Button2
       "
       Me.Button2.Location = New System.Drawing.Point(128, 16)
       Me.Button2.Name = "Button2"
       Me.Button2.TabIndex = 3
       Me.Button2.Text = "Button2"
       "
       "Button3
       "
       Me.Button3.Location = New System.Drawing.Point(224, 16)
       Me.Button3.Name = "Button3"
       Me.Button3.Size = New System.Drawing.Size(72, 24)
       Me.Button3.TabIndex = 4
       Me.Button3.Text = "Button3"
       "
       "Form1
       "
       Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
       Me.ClientSize = New System.Drawing.Size(320, 134)
       Me.Controls.AddRange(New System.Windows.Forms.Control() {Me.Button3, Me.Button2, Me.Button1, Me.btnRemember, Me.btnLoop})
       Me.Name = "Form1"
       Me.Text = "Event-O-Rama"
       Me.ResumeLayout(False)
   End Sub
  1. End Region
   Dim formsize As System.Drawing.Size
   Dim formlocation As System.Drawing.Point
   Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Load
       Console.WriteLine("Load Event Fired")
       formsize = Me.Size
       formlocation = Me.Location
   End Sub
   Private Sub Form1_Activated(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Activated
       Console.WriteLine("Activated Event Fired")
   End Sub
   Private Sub Form1_Closed(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Closed
       Console.WriteLine("Closed Event Fired")
   End Sub
   Private Sub Form1_Closing(ByVal sender As Object, ByVal e As System.ruponentModel.CancelEventArgs) Handles MyBase.Closing
       Console.WriteLine("Closing Event Fired")
       Dim answer As MsgBoxResult
       answer = MsgBox("Do you want to close this window?", MsgBoxStyle.YesNo, "Demonstration of the Closing event")
       If answer = MsgBoxResult.No Then
           e.Cancel = True
       End If
   End Sub
   Private Sub Form1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Click
       Console.WriteLine("Click Event Fired")
   End Sub
   Private Sub Form1_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles MyBase.MouseMove
       Console.WriteLine("MouseMove Event Fired")
   End Sub
   Private Sub Form1_Resize(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Resize
       Console.WriteLine("Resize Event Fired " & Me.Size.Width.ToString())
   End Sub
   Private Sub Form1_Deactivate(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Deactivate
       Console.WriteLine("Deactivate Event Fired")
   End Sub
   Private Sub Form1_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles MyBase.Paint
       Console.WriteLine("Paint Event Fired")
   End Sub
   Private Sub Form1_Leave(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Leave
       Console.WriteLine("Leave Event Fired")
   End Sub
   Private Sub Form1_Enter(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Enter
       Console.WriteLine("Enter Event Fired")
   End Sub
   Private Sub btnLoop_Enter(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnLoop.Enter
       Console.WriteLine("btnLoop Enter Event Fired")
       "btnLoop_Leave(sender, e)
   End Sub
   Private Sub btnLoop_Leave(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnLoop.Leave
       Console.WriteLine("btnLoop Leave Event Fired")
       "btnLoop_Enter(sender, e)
   End Sub
   Private Sub btnRemember_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnRemember.Click
       Me.Size = formsize
       Me.Location = formlocation
   End Sub
   Private Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) _
       Handles Button1.Click, Button2.Click, Button3.Click
     MsgBox(sender.Text & " was clicked!")
   End Sub

End Class


 </source>


Form.ClientSize

<source lang="vbnet"> Imports System.Drawing Imports System.Drawing.Drawing2D Imports System.Windows.Forms public class TextureTransform

  public Shared Sub Main
       Application.Run(New Form1)
  End Sub

End class public class Form1

 Inherits System.Windows.Forms.Form
 Protected Overrides Sub OnPaint(ByVal e As PaintEventArgs)
       Dim g As Graphics = e.Graphics
       Dim str As String = "www.vbex.ru www.vbex.ru www.vbex.ru www.vbex.ru www.vbex.ru www.vbex.ru www.vbex.ru www.vbex.ru www.vbex.ru www.vbex.ru www.vbex.ru www.vbex.ru www.vbex.ru www.vbex.ru www.vbex.ru www.vbex.ru www.vbex.ru www.vbex.ru www.vbex.ru www.vbex.ru www.vbex.ru www.vbex.ru www.vbex.ru www.vbex.ru www.vbex.ru www.vbex.ru www.vbex.ru www.vbex.ru www.vbex.ru www.vbex.ru www.vbex.ru www.vbex.ru www.vbex.ru www.vbex.ru www.vbex.ru www.vbex.ru www.vbex.ru www.vbex.ru www.vbex.ru www.vbex.ru www.vbex.ru www.vbex.ru www.vbex.ru www.vbex.ru www.vbex.ru www.vbex.ru www.vbex.ru www.vbex.ru www.vbex.ru www.vbex.ru www.vbex.ru www.vbex.ru "
       g.ScaleTransform(2, 1)
       g.RotateTransform(45.0F, System.Drawing.Drawing2D.MatrixOrder.Prepend)
       g.TranslateTransform(-20, -70)
       g.DrawString(str, New Font("Verdana", 10), New SolidBrush(Color.Blue), New RectangleF(50, 20, 200, 300))
 End Sub
 Public Sub New()
  
   MyBase.New()
   Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
   Me.ClientSize = New System.Drawing.Size(292, 273)
   Me.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen
 End Sub

End Class


 </source>


Form.Controls

<source lang="vbnet"> Imports System Imports System.ruponentModel Imports System.Windows.Forms Imports System.Data Imports System.Configuration Imports System.Drawing Imports System.Drawing.Drawing2D Imports System.Drawing.Text Imports System.Globalization Imports System.Text Imports System.Collections Public Class MainClass

   Shared Sub Main()
       Dim myform As Form = New Form1()
       Application.Run(myform)
   End Sub

End Class

Public Class Form1

   " Declare the btnHi button WithEvents.
   Private WithEvents buttonHi As Button
   " Make the new buttonHi button.
   Private Sub btnMakeHiButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnMakeHiButton.Click
       buttonHi = New Button
       buttonHi.SetBounds(96, 50, 75, 23)
       buttonHi.Text = "Say Hi"
       Me.Controls.Add(buttonHi)
   End Sub
   " The user clicked the buttonHi button.
   Private Sub buttonHi_Click(ByVal sender As Object, _
    ByVal e As System.EventArgs) Handles buttonHi.Click
       MessageBox.Show("Hi")
   End Sub
   Private Sub btnRemoveHiButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnRemoveHiButton.Click
       Me.Controls.Remove(buttonHi)
       buttonHi = Nothing
   End Sub

End Class

<Global.Microsoft.VisualBasic.rupilerServices.DesignerGenerated()> _ Partial Public Class Form1

   Inherits System.Windows.Forms.Form
   "Form overrides dispose to clean up the component list.
   <System.Diagnostics.DebuggerNonUserCode()> _
   Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
       If disposing AndAlso components IsNot Nothing Then
           components.Dispose()
       End If
       MyBase.Dispose(disposing)
   End Sub
   "Required by the Windows Form Designer
   Private components As System.ruponentModel.IContainer
   "NOTE: The following procedure is required by the Windows Form Designer
   "It can be modified using the Windows Form Designer.  
   "Do not modify it using the code editor.
   <System.Diagnostics.DebuggerStepThrough()> _
   Private Sub InitializeComponent()
       Me.btnMakeHiButton = New System.Windows.Forms.Button
       Me.btnRemoveHiButton = New System.Windows.Forms.Button
       Me.SuspendLayout()
       "
       "btnMakeHiButton
       "
       Me.btnMakeHiButton.Location = New System.Drawing.Point(8, 8)
       Me.btnMakeHiButton.Name = "btnMakeHiButton"
       Me.btnMakeHiButton.Size = New System.Drawing.Size(112, 23)
       Me.btnMakeHiButton.TabIndex = 0
       Me.btnMakeHiButton.Text = "Make Hi Button"
       "
       "btnRemoveHiButton
       "
       Me.btnRemoveHiButton.Location = New System.Drawing.Point(144, 8)
       Me.btnRemoveHiButton.Name = "btnRemoveHiButton"
       Me.btnRemoveHiButton.Size = New System.Drawing.Size(112, 23)
       Me.btnRemoveHiButton.TabIndex = 1
       Me.btnRemoveHiButton.Text = "Remove Hi Button"
       "
       "Form1
       "
       Me.AutoScaleDimensions = New System.Drawing.SizeF(6.0!, 13.0!)
       Me.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font
       Me.ClientSize = New System.Drawing.Size(292, 273)
       Me.Controls.Add(Me.btnRemoveHiButton)
       Me.Controls.Add(Me.btnMakeHiButton)
       Me.Name = "Form1"
       Me.Text = "Form1"
       Me.ResumeLayout(False)
   End Sub
   Friend WithEvents btnMakeHiButton As System.Windows.Forms.Button
   Friend WithEvents btnRemoveHiButton As System.Windows.Forms.Button

End Class


 </source>


Form.Controls.Add

<source lang="vbnet"> Option Strict On Imports System.Drawing Imports System.Windows.Forms Public Class Form1 : Inherits Form

  Private WithEvents cmdClickCtr As Button = New Button()
  Public Sub New()
     Me.cmdClickCtr.Location = New Point(100, 75)
     Me.cmdClickCtr.Size = New Size(100, 50)
     Me.cmdClickCtr.Text = "Click Counter"
     
     Me.Controls.Add(cmdClickCtr)
     Me.Text = "Click Counter"
  End Sub
  
  Private Sub cmdClickCtr_Click(ByVal sender As System.Object, _
              ByVal e As System.EventArgs) _
              Handles cmdClickCtr.Click
     Static ctr As Integer = 1
     MsgBox("Button was clicked " & ctr & " times.")
     ctr += 1
  End Sub
  
  Public Shared Sub Main()
     Dim frm As New Form1()
     frm.ShowDialog()
  End Sub

End Class


 </source>


Form.Controls.AddRange

<source lang="vbnet"> Imports System Imports System.Drawing Imports System.Windows.Forms public class MainClass

  Shared Sub Main()
     Dim form1 As Form = New Form1
     Application.Run(form1)
  End Sub

End Class

Public Class Form1

   Inherits System.Windows.Forms.Form
  1. Region " Windows Form Designer generated code "
   Public Sub New()
       MyBase.New()
       "This call is required by the Windows Form Designer.
       InitializeComponent()
       "Add any initialization after the InitializeComponent() call
   End Sub
   "Form overrides dispose to clean up the component list.
   Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
       If disposing Then
           If Not (components Is Nothing) Then
               components.Dispose()
           End If
       End If
       MyBase.Dispose(disposing)
   End Sub
   Friend WithEvents ctl1 As System.Windows.Forms.ContainerControl
   Friend WithEvents textBox2 As System.Windows.Forms.TextBox
   Friend WithEvents textBox1 As System.Windows.Forms.TextBox
   Friend WithEvents textBox3 As System.Windows.Forms.TextBox
   "Required by the Windows Form Designer
   Private components As System.ruponentModel.IContainer
   "NOTE: The following procedure is required by the Windows Form Designer
   "It can be modified using the Windows Form Designer.  
   "Do not modify it using the code editor.
   <System.Diagnostics.DebuggerStepThroughAttribute()> Private Sub InitializeComponent()
       Me.textBox1 = New System.Windows.Forms.TextBox()
       Me.ctl1 = New System.Windows.Forms.ContainerControl()
       Me.textBox2 = New System.Windows.Forms.TextBox()
       Me.textBox3 = New System.Windows.Forms.TextBox()
       Me.ctl1.SuspendLayout()
       Me.SuspendLayout()
       "
       "textBox1
       "
       Me.textBox1.Location = New System.Drawing.Point(128, 24)
       Me.textBox1.Name = "textBox1"
       Me.textBox1.Size = New System.Drawing.Size(136, 20)
       Me.textBox1.TabIndex = 0
       Me.textBox1.Text = "textBox1"
       "
       "ctl1
       "
       Me.ctl1.AutoScroll = True
       Me.ctl1.BackColor = System.Drawing.Color.DarkBlue
       Me.ctl1.Controls.AddRange(New System.Windows.Forms.Control() {Me.textBox2, Me.textBox1})
       Me.ctl1.Location = New System.Drawing.Point(24, 32)
       Me.ctl1.Name = "ctl1"
       Me.ctl1.Size = New System.Drawing.Size(216, 104)
       Me.ctl1.TabIndex = 0
       "
       "textBox2
       "
       Me.textBox2.Location = New System.Drawing.Point(32, 24)
       Me.textBox2.Name = "textBox2"
       Me.textBox2.Size = New System.Drawing.Size(64, 20)
       Me.textBox2.TabIndex = 1
       Me.textBox2.Text = "textBox2"
       "
       "textBox3
       "
       Me.textBox3.Location = New System.Drawing.Point(176, 168)
       Me.textBox3.Name = "textBox3"
       Me.textBox3.Size = New System.Drawing.Size(72, 20)
       Me.textBox3.TabIndex = 1
       Me.textBox3.Text = "textBox3"
       "
       "Form1
       "
       Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
       Me.ClientSize = New System.Drawing.Size(292, 273)
       Me.Controls.AddRange(New System.Windows.Forms.Control() {Me.textBox3, Me.ctl1})
       Me.Name = "Form1"
       Me.Text = "Form1"
       Me.ctl1.ResumeLayout(False)
       Me.ResumeLayout(False)
   End Sub
  1. End Region

End Class


 </source>


Form.CreateGraphics

<source lang="vbnet">

Imports System.Drawing Imports System.Drawing.Drawing2D Imports System.Windows.Forms public class DrawCircle

  public Shared Sub Main
       Application.Run(New Form1)
  End Sub

End class public class Form1

 Inherits System.Windows.Forms.Form
 Protected Overrides Sub OnPaint(ByVal e As PaintEventArgs)
       Dim a As Graphics =  e.Graphics
       Dim mypen As Pen
       Dim myrect As RectangleF
       mypen = New Pen(System.Drawing.Color.Red, 6)
       a = Me.CreateGraphics
       a.Clear(Me.BackColor)
       a.DrawEllipse(mypen, 100, 100, 50, 50)
       a.DrawEllipse(mypen, 75, 75, 100, 100)
       a.DrawEllipse(mypen, 25, 25, 200, 200)
       a.DrawEllipse(mypen, 0, 0, 250, 250)
       myrect.X = 300
       myrect.Y = 10
       myrect.Width = 250
       myrect.Height = 100
       a.DrawEllipse(mypen, myrect)
       myrect.X = 400
       myrect.Y = 10
       myrect.Width = 100
       myrect.Height = 250
       a.DrawEllipse(mypen, myrect)
       a.Dispose()
       mypen.Dispose()
 End Sub
 Public Sub New()
   MyBase.New()
   Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
   Me.ClientSize = New System.Drawing.Size(292, 273)
   Me.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen
 End Sub

End Class


 </source>


Form.Deactivate

<source lang="vbnet"> Imports System.Diagnostics Imports System.Windows.Forms public class FormEvents

  public Shared Sub Main
       Application.Run(New Form1)
  End Sub

End class

Public Class Form1

   Inherits System.Windows.Forms.Form
  1. Region " Windows Form Designer generated code "
   Public Sub New()
       MyBase.New()
       "This call is required by the Windows Form Designer.
       InitializeComponent()
       "Add any initialization after the InitializeComponent() call
       Console.WriteLine("New Event Fired")
   End Sub
   "Form overrides dispose to clean up the component list.
   Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
       Console.WriteLine("Dispose Method Executed")
       If disposing Then
           If Not (components Is Nothing) Then
               components.Dispose()
           End If
       End If
       MyBase.Dispose(disposing)
   End Sub
   Friend WithEvents btnLoop As System.Windows.Forms.Button
   Friend WithEvents btnRemember As System.Windows.Forms.Button
   Friend WithEvents Button1 As System.Windows.Forms.Button
   Friend WithEvents Button2 As System.Windows.Forms.Button
   Friend WithEvents Button3 As System.Windows.Forms.Button
   "Required by the Windows Form Designer
   Private components As System.ruponentModel.IContainer
   "NOTE: The following procedure is required by the Windows Form Designer
   "It can be modified using the Windows Form Designer.  
   "Do not modify it using the code editor.
   <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
       Me.btnLoop = New System.Windows.Forms.Button()
       Me.btnRemember = New System.Windows.Forms.Button()
       Me.Button1 = New System.Windows.Forms.Button()
       Me.Button2 = New System.Windows.Forms.Button()
       Me.Button3 = New System.Windows.Forms.Button()
       Me.SuspendLayout()
       "
       "btnLoop
       "
       Me.btnLoop.Location = New System.Drawing.Point(24, 56)
       Me.btnLoop.Name = "btnLoop"
       Me.btnLoop.TabIndex = 0
       Me.btnLoop.Text = "Loop"
       "
       "btnRemember
       "
       Me.btnRemember.Location = New System.Drawing.Point(136, 56)
       Me.btnRemember.Name = "btnRemember"
       Me.btnRemember.Size = New System.Drawing.Size(112, 23)
       Me.btnRemember.TabIndex = 1
       Me.btnRemember.Text = "Remember Position"
       "
       "Button1
       "
       Me.Button1.Location = New System.Drawing.Point(24, 16)
       Me.Button1.Name = "Button1"
       Me.Button1.TabIndex = 2
       Me.Button1.Text = "Button1"
       "
       "Button2
       "
       Me.Button2.Location = New System.Drawing.Point(128, 16)
       Me.Button2.Name = "Button2"
       Me.Button2.TabIndex = 3
       Me.Button2.Text = "Button2"
       "
       "Button3
       "
       Me.Button3.Location = New System.Drawing.Point(224, 16)
       Me.Button3.Name = "Button3"
       Me.Button3.Size = New System.Drawing.Size(72, 24)
       Me.Button3.TabIndex = 4
       Me.Button3.Text = "Button3"
       "
       "Form1
       "
       Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
       Me.ClientSize = New System.Drawing.Size(320, 134)
       Me.Controls.AddRange(New System.Windows.Forms.Control() {Me.Button3, Me.Button2, Me.Button1, Me.btnRemember, Me.btnLoop})
       Me.Name = "Form1"
       Me.Text = "Event-O-Rama"
       Me.ResumeLayout(False)
   End Sub
  1. End Region
   Dim formsize As System.Drawing.Size
   Dim formlocation As System.Drawing.Point
   Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Load
       Console.WriteLine("Load Event Fired")
       formsize = Me.Size
       formlocation = Me.Location
   End Sub
   Private Sub Form1_Activated(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Activated
       Console.WriteLine("Activated Event Fired")
   End Sub
   Private Sub Form1_Closed(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Closed
       Console.WriteLine("Closed Event Fired")
   End Sub
   Private Sub Form1_Closing(ByVal sender As Object, ByVal e As System.ruponentModel.CancelEventArgs) Handles MyBase.Closing
       Console.WriteLine("Closing Event Fired")
       Dim answer As MsgBoxResult
       answer = MsgBox("Do you want to close this window?", MsgBoxStyle.YesNo, "Demonstration of the Closing event")
       If answer = MsgBoxResult.No Then
           e.Cancel = True
       End If
   End Sub
   Private Sub Form1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Click
       Console.WriteLine("Click Event Fired")
   End Sub
   Private Sub Form1_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles MyBase.MouseMove
       Console.WriteLine("MouseMove Event Fired")
   End Sub
   Private Sub Form1_Resize(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Resize
       Console.WriteLine("Resize Event Fired " & Me.Size.Width.ToString())
   End Sub
   Private Sub Form1_Deactivate(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Deactivate
       Console.WriteLine("Deactivate Event Fired")
   End Sub
   Private Sub Form1_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles MyBase.Paint
       Console.WriteLine("Paint Event Fired")
   End Sub
   Private Sub Form1_Leave(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Leave
       Console.WriteLine("Leave Event Fired")
   End Sub
   Private Sub Form1_Enter(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Enter
       Console.WriteLine("Enter Event Fired")
   End Sub
   Private Sub btnLoop_Enter(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnLoop.Enter
       Console.WriteLine("btnLoop Enter Event Fired")
       "btnLoop_Leave(sender, e)
   End Sub
   Private Sub btnLoop_Leave(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnLoop.Leave
       Console.WriteLine("btnLoop Leave Event Fired")
       "btnLoop_Enter(sender, e)
   End Sub
   Private Sub btnRemember_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnRemember.Click
       Me.Size = formsize
       Me.Location = formlocation
   End Sub
   Private Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) _
       Handles Button1.Click, Button2.Click, Button3.Click
     MsgBox(sender.Text & " was clicked!")
   End Sub

End Class


 </source>


Form.Enter

<source lang="vbnet"> Imports System.Diagnostics Imports System.Windows.Forms public class FormEvents

  public Shared Sub Main
       Application.Run(New Form1)
  End Sub

End class

Public Class Form1

   Inherits System.Windows.Forms.Form
  1. Region " Windows Form Designer generated code "
   Public Sub New()
       MyBase.New()
       "This call is required by the Windows Form Designer.
       InitializeComponent()
       "Add any initialization after the InitializeComponent() call
       Console.WriteLine("New Event Fired")
   End Sub
   "Form overrides dispose to clean up the component list.
   Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
       Console.WriteLine("Dispose Method Executed")
       If disposing Then
           If Not (components Is Nothing) Then
               components.Dispose()
           End If
       End If
       MyBase.Dispose(disposing)
   End Sub
   Friend WithEvents btnLoop As System.Windows.Forms.Button
   Friend WithEvents btnRemember As System.Windows.Forms.Button
   Friend WithEvents Button1 As System.Windows.Forms.Button
   Friend WithEvents Button2 As System.Windows.Forms.Button
   Friend WithEvents Button3 As System.Windows.Forms.Button
   "Required by the Windows Form Designer
   Private components As System.ruponentModel.IContainer
   "NOTE: The following procedure is required by the Windows Form Designer
   "It can be modified using the Windows Form Designer.  
   "Do not modify it using the code editor.
   <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
       Me.btnLoop = New System.Windows.Forms.Button()
       Me.btnRemember = New System.Windows.Forms.Button()
       Me.Button1 = New System.Windows.Forms.Button()
       Me.Button2 = New System.Windows.Forms.Button()
       Me.Button3 = New System.Windows.Forms.Button()
       Me.SuspendLayout()
       "
       "btnLoop
       "
       Me.btnLoop.Location = New System.Drawing.Point(24, 56)
       Me.btnLoop.Name = "btnLoop"
       Me.btnLoop.TabIndex = 0
       Me.btnLoop.Text = "Loop"
       "
       "btnRemember
       "
       Me.btnRemember.Location = New System.Drawing.Point(136, 56)
       Me.btnRemember.Name = "btnRemember"
       Me.btnRemember.Size = New System.Drawing.Size(112, 23)
       Me.btnRemember.TabIndex = 1
       Me.btnRemember.Text = "Remember Position"
       "
       "Button1
       "
       Me.Button1.Location = New System.Drawing.Point(24, 16)
       Me.Button1.Name = "Button1"
       Me.Button1.TabIndex = 2
       Me.Button1.Text = "Button1"
       "
       "Button2
       "
       Me.Button2.Location = New System.Drawing.Point(128, 16)
       Me.Button2.Name = "Button2"
       Me.Button2.TabIndex = 3
       Me.Button2.Text = "Button2"
       "
       "Button3
       "
       Me.Button3.Location = New System.Drawing.Point(224, 16)
       Me.Button3.Name = "Button3"
       Me.Button3.Size = New System.Drawing.Size(72, 24)
       Me.Button3.TabIndex = 4
       Me.Button3.Text = "Button3"
       "
       "Form1
       "
       Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
       Me.ClientSize = New System.Drawing.Size(320, 134)
       Me.Controls.AddRange(New System.Windows.Forms.Control() {Me.Button3, Me.Button2, Me.Button1, Me.btnRemember, Me.btnLoop})
       Me.Name = "Form1"
       Me.Text = "Event-O-Rama"
       Me.ResumeLayout(False)
   End Sub
  1. End Region
   Dim formsize As System.Drawing.Size
   Dim formlocation As System.Drawing.Point
   Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Load
       Console.WriteLine("Load Event Fired")
       formsize = Me.Size
       formlocation = Me.Location
   End Sub
   Private Sub Form1_Activated(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Activated
       Console.WriteLine("Activated Event Fired")
   End Sub
   Private Sub Form1_Closed(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Closed
       Console.WriteLine("Closed Event Fired")
   End Sub
   Private Sub Form1_Closing(ByVal sender As Object, ByVal e As System.ruponentModel.CancelEventArgs) Handles MyBase.Closing
       Console.WriteLine("Closing Event Fired")
       Dim answer As MsgBoxResult
       answer = MsgBox("Do you want to close this window?", MsgBoxStyle.YesNo, "Demonstration of the Closing event")
       If answer = MsgBoxResult.No Then
           e.Cancel = True
       End If
   End Sub
   Private Sub Form1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Click
       Console.WriteLine("Click Event Fired")
   End Sub
   Private Sub Form1_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles MyBase.MouseMove
       Console.WriteLine("MouseMove Event Fired")
   End Sub
   Private Sub Form1_Resize(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Resize
       Console.WriteLine("Resize Event Fired " & Me.Size.Width.ToString())
   End Sub
   Private Sub Form1_Deactivate(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Deactivate
       Console.WriteLine("Deactivate Event Fired")
   End Sub
   Private Sub Form1_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles MyBase.Paint
       Console.WriteLine("Paint Event Fired")
   End Sub
   Private Sub Form1_Leave(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Leave
       Console.WriteLine("Leave Event Fired")
   End Sub
   Private Sub Form1_Enter(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Enter
       Console.WriteLine("Enter Event Fired")
   End Sub
   Private Sub btnLoop_Enter(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnLoop.Enter
       Console.WriteLine("btnLoop Enter Event Fired")
       "btnLoop_Leave(sender, e)
   End Sub
   Private Sub btnLoop_Leave(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnLoop.Leave
       Console.WriteLine("btnLoop Leave Event Fired")
       "btnLoop_Enter(sender, e)
   End Sub
   Private Sub btnRemember_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnRemember.Click
       Me.Size = formsize
       Me.Location = formlocation
   End Sub
   Private Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) _
       Handles Button1.Click, Button2.Click, Button3.Click
     MsgBox(sender.Text & " was clicked!")
   End Sub

End Class


 </source>


Form.FormBorderStyle

<source lang="vbnet">

Imports System.Drawing Imports System.Drawing.Drawing2D Imports System.Windows.Forms public class FormBackgroundPicture

  public Shared Sub Main
       Application.Run(New Form1)
  End Sub

End class Public Class Form1

   Inherits System.Windows.Forms.Form
  1. Region " Windows Form Designer generated code "
   Public Sub New()
       MyBase.New()
       "This call is required by the Windows Form Designer.
       InitializeComponent()
       "Add any initialization after the InitializeComponent() call
   End Sub
   "Form overrides dispose to clean up the component list.
   Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
       If disposing Then
           If Not (components Is Nothing) Then
               components.Dispose()
           End If
       End If
       MyBase.Dispose(disposing)
   End Sub
   "Required by the Windows Form Designer
   Private components As System.ruponentModel.IContainer
   "NOTE: The following procedure is required by the Windows Form Designer
   "It can be modified using the Windows Form Designer.  
   "Do not modify it using the code editor.
   Friend WithEvents Button1 As System.Windows.Forms.Button
   <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
       Dim resources As System.Resources.ResourceManager = New System.Resources.ResourceManager(GetType(Form1))
       Me.Button1 = New System.Windows.Forms.Button
       Me.SuspendLayout()
       "
       "Button1
       "
       Me.Button1.Location = New System.Drawing.Point(152, 88)
       Me.Button1.Name = "Button1"
       Me.Button1.TabIndex = 0
       Me.Button1.Text = "Close"
       "
       "Form1
       "
       Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
       Me.BackgroundImage = System.Drawing.Image.FromFile("yourfile.jpg")
       Me.ClientSize = New System.Drawing.Size(376, 208)
       Me.Controls.Add(Me.Button1)
       Me.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None
       Me.Name = "Form1"
       Me.Text = "Form1"
       Me.TransparencyKey = System.Drawing.Color.White
       Me.ResumeLayout(False)
   End Sub
  1. End Region
   Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
       Me.Close()
   End Sub

End Class


 </source>


Form.Icon

<source lang="vbnet"> Imports System.Drawing Imports System.Drawing.Drawing2D Imports System.Windows.Forms public class MyResourcesMainFormIcon

  public Shared Sub Main
       Application.Run(New Form1)
  End Sub

End class

Public Class Form1

   Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
       Me.Icon = New Icon("1.ico")
   End Sub

End Class <Global.Microsoft.VisualBasic.rupilerServices.DesignerGenerated()> _ Partial Public Class Form1

   Inherits System.Windows.Forms.Form
   "Form overrides dispose to clean up the component list.
   <System.Diagnostics.DebuggerNonUserCode()> _
   Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
       If disposing AndAlso components IsNot Nothing Then
           components.Dispose()
       End If
       MyBase.Dispose(disposing)
   End Sub
   "Required by the Windows Form Designer
   Private components As System.ruponentModel.IContainer
   "NOTE: The following procedure is required by the Windows Form Designer
   "It can be modified using the Windows Form Designer.  
   "Do not modify it using the code editor.
   <System.Diagnostics.DebuggerStepThrough()> _
   Private Sub InitializeComponent()
       Me.SuspendLayout()
       "
       "Form1
       "
       Me.AutoScaleDimensions = New System.Drawing.SizeF(6.0!, 13.0!)
       Me.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font
       Me.ClientSize = New System.Drawing.Size(292, 273)
       Me.Name = "Form1"
       Me.Text = "Form1"
       Me.ResumeLayout(False)
   End Sub

End Class


 </source>


Form.IsMdiContainer

<source lang="vbnet"> Imports System Imports System.Collections Imports System.Data Imports System.IO Imports System.Xml.Serialization Imports System.Windows.Forms Imports System.Drawing Imports System.Drawing.Drawing2D Imports System.Drawing.Text Imports System.Drawing.Printing

Public Class MainClass

   Shared Sub Main()
      Dim form1 As Form = New Form1()
      Application.Run(form1) 
    End Sub

End Class


Public Class Form1

   Inherits System.Windows.Forms.Form
  1. Region " Windows Form Designer generated code "
   Public Sub New()
       MyBase.New()
       "This call is required by the Windows Form Designer.
       InitializeComponent()
       "Add any initialization after the InitializeComponent() call
   End Sub
   "Form overrides dispose to clean up the component list.
   Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
       If disposing Then
           If Not (components Is Nothing) Then
               components.Dispose()
           End If
       End If
       MyBase.Dispose(disposing)
   End Sub
   "Required by the Windows Form Designer
   Private components As System.ruponentModel.Container
   "NOTE: The following procedure is required by the Windows Form Designer
   "It can be modified using the Windows Form Designer.  
   "Do not modify it using the code editor.
   <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
       "
       "Form1
       "
       Me.AutoScaleBaseSize = New System.Drawing.Size(6, 15)
       Me.ClientSize = New System.Drawing.Size(292, 268)
       Me.Name = "Form1"
       Me.Text = "MDI Example 1"
   End Sub
  1. End Region
   Private Sub Form1_Load(ByVal sender As System.Object, _
  ByVal e As System.EventArgs) _
  Handles MyBase.Load
       Me.Text = "I"m an MDI Parent"
       Me.IsMdiContainer = True
       Dim MyChild As New System.Windows.Forms.Form()
       MyChild.MdiParent = Me
       MyChild.Show()
       MyChild.Text = "MDI Child"
   End Sub

End Class


 </source>


Form.LayoutMdi

<source lang="vbnet"> Imports System Imports System.Drawing Imports System.Collections Imports System.ruponentModel Imports System.Windows.Forms Imports System.Data Imports System.Configuration Imports System.Resources Public Class ChildForm

   Inherits System.Windows.Forms.Form
  1. Region " Windows Form Designer generated code "
   Public Sub New()
       MyBase.New()
       "This call is required by the Windows Form Designer.
       InitializeComponent()
       "Add any initialization after the InitializeComponent() call
   End Sub
   "Form overrides dispose to clean up the component list.
   Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
       If disposing Then
           If Not (components Is Nothing) Then
               components.Dispose()
           End If
       End If
       MyBase.Dispose(disposing)
   End Sub
   "Required by the Windows Form Designer
   Private components As System.ruponentModel.IContainer
   "NOTE: The following procedure is required by the Windows Form Designer
   "It can be modified using the Windows Form Designer.  
   "Do not modify it using the code editor.
   Friend WithEvents mainMenu1 As System.Windows.Forms.MainMenu
   Friend WithEvents menuItem11 As System.Windows.Forms.MenuItem
   Friend WithEvents menuItem1 As System.Windows.Forms.MenuItem
   Friend WithEvents cmdFileClose As System.Windows.Forms.MenuItem
   Friend WithEvents menuItem13 As System.Windows.Forms.MenuItem
   Friend WithEvents menuItem5 As System.Windows.Forms.MenuItem
   Friend WithEvents menuItem4 As System.Windows.Forms.MenuItem
   Friend WithEvents menuItem6 As System.Windows.Forms.MenuItem
   <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
       Me.mainMenu1 = New System.Windows.Forms.MainMenu()
       Me.menuItem11 = New System.Windows.Forms.MenuItem()
       Me.menuItem1 = New System.Windows.Forms.MenuItem()
       Me.cmdFileClose = New System.Windows.Forms.MenuItem()
       Me.menuItem13 = New System.Windows.Forms.MenuItem()
       Me.menuItem5 = New System.Windows.Forms.MenuItem()
       Me.menuItem4 = New System.Windows.Forms.MenuItem()
       Me.menuItem6 = New System.Windows.Forms.MenuItem()
       "
       "mainMenu1
       "
       Me.mainMenu1.MenuItems.AddRange(New System.Windows.Forms.MenuItem() {Me.menuItem11, Me.menuItem13})
       "
       "menuItem11
       "
       Me.menuItem11.Index = 0
       Me.menuItem11.MenuItems.AddRange(New System.Windows.Forms.MenuItem() {Me.menuItem1, Me.cmdFileClose})
       Me.menuItem11.MergeType = System.Windows.Forms.MenuMerge.MergeItems
       Me.menuItem11.Text = "&File"
       "
       "menuItem1
       "
       Me.menuItem1.Index = 0
       Me.menuItem1.MergeOrder = 1
       Me.menuItem1.Text = "&Save"
       "
       "cmdFileClose
       "
       Me.cmdFileClose.Index = 1
       Me.cmdFileClose.MergeOrder = 1
       Me.cmdFileClose.Text = "&Close"
       "
       "menuItem13
       "
       Me.menuItem13.Index = 1
       Me.menuItem13.MenuItems.AddRange(New System.Windows.Forms.MenuItem() {Me.menuItem5, Me.menuItem4, Me.menuItem6})
       Me.menuItem13.MergeOrder = 1
       Me.menuItem13.Text = "&Edit"
       "
       "menuItem5
       "
       Me.menuItem5.Index = 0
       Me.menuItem5.Text = "Cu&t"
       "
       "menuItem4
       "
       Me.menuItem4.Index = 1
       Me.menuItem4.Text = "&Copy"
       "
       "menuItem6
       "
       Me.menuItem6.Index = 2
       Me.menuItem6.Text = "&Paste"
       "
       "ChildForm
       "
       Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
       Me.ClientSize = New System.Drawing.Size(168, 147)
       Me.Menu = Me.mainMenu1
       Me.Name = "ChildForm"
       Me.Text = "MDI Child"
   End Sub
  1. End Region
   Private Sub cmdFileClose_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles cmdFileClose.Click
       Close()
   End Sub

End Class Public Class ParentForm

   Inherits System.Windows.Forms.Form
  1. Region " Windows Form Designer generated code "
   Public Sub New()
       MyBase.New()
       "This call is required by the Windows Form Designer.
       InitializeComponent()
       "Add any initialization after the InitializeComponent() call
   End Sub
   "Form overrides dispose to clean up the component list.
   Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
       If disposing Then
           If Not (components Is Nothing) Then
               components.Dispose()
           End If
       End If
       MyBase.Dispose(disposing)
   End Sub
   "Required by the Windows Form Designer
   Private components As System.ruponentModel.IContainer
   "NOTE: The following procedure is required by the Windows Form Designer
   "It can be modified using the Windows Form Designer.  
   "Do not modify it using the code editor.
   Friend WithEvents cmdCascade As System.Windows.Forms.MenuItem
   Friend WithEvents menuItem7 As System.Windows.Forms.MenuItem
   Friend WithEvents menuItem3 As System.Windows.Forms.MenuItem
   Friend WithEvents cmdWindowArrangeIcons As System.Windows.Forms.MenuItem
   Friend WithEvents cmdWindowTileChildrenVert As System.Windows.Forms.MenuItem
   Friend WithEvents cmdWindowTileChildrenHoriz As System.Windows.Forms.MenuItem
   Friend WithEvents menuItem8 As System.Windows.Forms.MenuItem
   Friend WithEvents statusBar1 As System.Windows.Forms.StatusBar
   Friend WithEvents cmdFileNewChild As System.Windows.Forms.MenuItem
   Friend WithEvents cmdFileExit As System.Windows.Forms.MenuItem
   Friend WithEvents treeView1 As System.Windows.Forms.TreeView
   Friend WithEvents mainMenu1 As System.Windows.Forms.MainMenu
   Friend WithEvents menuItem1 As System.Windows.Forms.MenuItem
   Friend WithEvents menuItem9 As System.Windows.Forms.MenuItem
   Friend WithEvents splitter1 As System.Windows.Forms.Splitter
   <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
       Me.cmdCascade = New System.Windows.Forms.MenuItem()
       Me.menuItem7 = New System.Windows.Forms.MenuItem()
       Me.menuItem3 = New System.Windows.Forms.MenuItem()
       Me.cmdWindowArrangeIcons = New System.Windows.Forms.MenuItem()
       Me.cmdWindowTileChildrenVert = New System.Windows.Forms.MenuItem()
       Me.cmdWindowTileChildrenHoriz = New System.Windows.Forms.MenuItem()
       Me.menuItem8 = New System.Windows.Forms.MenuItem()
       Me.statusBar1 = New System.Windows.Forms.StatusBar()
       Me.cmdFileNewChild = New System.Windows.Forms.MenuItem()
       Me.cmdFileExit = New System.Windows.Forms.MenuItem()
       Me.treeView1 = New System.Windows.Forms.TreeView()
       Me.mainMenu1 = New System.Windows.Forms.MainMenu()
       Me.menuItem1 = New System.Windows.Forms.MenuItem()
       Me.menuItem9 = New System.Windows.Forms.MenuItem()
       Me.splitter1 = New System.Windows.Forms.Splitter()
       Me.SuspendLayout()
       "
       "cmdCascade
       "
       Me.cmdCascade.Index = 1
       Me.cmdCascade.Text = "&Cascade"
       "
       "menuItem7
       "
       Me.menuItem7.Index = 4
       Me.menuItem7.Text = "-"
       "
       "menuItem3
       "
       Me.menuItem3.Index = 1
       Me.menuItem3.MenuItems.AddRange(New System.Windows.Forms.MenuItem() {Me.cmdWindowArrangeIcons, Me.cmdCascade, Me.cmdWindowTileChildrenVert, Me.cmdWindowTileChildrenHoriz, Me.menuItem7, Me.menuItem8})
       Me.menuItem3.MergeOrder = 2
       Me.menuItem3.Text = "&Window"
       "
       "cmdWindowArrangeIcons
       "
       Me.cmdWindowArrangeIcons.Index = 0
       Me.cmdWindowArrangeIcons.Text = "&Arrange Icons"
       "
       "cmdWindowTileChildrenVert
       "
       Me.cmdWindowTileChildrenVert.Index = 2
       Me.cmdWindowTileChildrenVert.Text = "Tile Children &Vertically"
       "
       "cmdWindowTileChildrenHoriz
       "
       Me.cmdWindowTileChildrenHoriz.Index = 3
       Me.cmdWindowTileChildrenHoriz.Text = "Tile Children &Horizontally"
       "
       "menuItem8
       "
       Me.menuItem8.Index = 5
       Me.menuItem8.MdiList = True
       Me.menuItem8.Text = "Window&s"
       "
       "statusBar1
       "
       Me.statusBar1.Location = New System.Drawing.Point(0, 179)
       Me.statusBar1.Name = "statusBar1"
       Me.statusBar1.Size = New System.Drawing.Size(352, 22)
       Me.statusBar1.TabIndex = 4
       Me.statusBar1.Text = "Ready"
       "
       "cmdFileNewChild
       "
       Me.cmdFileNewChild.Index = 0
       Me.cmdFileNewChild.Shortcut = System.Windows.Forms.Shortcut.CtrlN
       Me.cmdFileNewChild.Text = "&New Child"
       "
       "cmdFileExit
       "
       Me.cmdFileExit.Index = 2
       Me.cmdFileExit.MergeOrder = 2
       Me.cmdFileExit.Text = "E&xit"
       "
       "treeView1
       "
       Me.treeView1.Dock = System.Windows.Forms.DockStyle.Left
       Me.treeView1.ImageIndex = -1
       Me.treeView1.Location = New System.Drawing.Point(3, 0)
       Me.treeView1.Name = "treeView1"
       Me.treeView1.Nodes.AddRange(New System.Windows.Forms.TreeNode() {New System.Windows.Forms.TreeNode("Children")})
       Me.treeView1.SelectedImageIndex = -1
       Me.treeView1.Size = New System.Drawing.Size(121, 179)
       Me.treeView1.TabIndex = 5
       "
       "mainMenu1
       "
       Me.mainMenu1.MenuItems.AddRange(New System.Windows.Forms.MenuItem() {Me.menuItem1, Me.menuItem3})
       "
       "menuItem1
       "
       Me.menuItem1.Index = 0
       Me.menuItem1.MenuItems.AddRange(New System.Windows.Forms.MenuItem() {Me.cmdFileNewChild, Me.menuItem9, Me.cmdFileExit})
       Me.menuItem1.MergeType = System.Windows.Forms.MenuMerge.MergeItems
       Me.menuItem1.Text = "&File"
       "
       "menuItem9
       "
       Me.menuItem9.Index = 1
       Me.menuItem9.MergeOrder = 2
       Me.menuItem9.Text = "-"
       "
       "splitter1
       "
       Me.splitter1.Name = "splitter1"
       Me.splitter1.Size = New System.Drawing.Size(3, 179)
       Me.splitter1.TabIndex = 6
       Me.splitter1.TabStop = False
       "
       "ParentForm
       "
       Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
       Me.ClientSize = New System.Drawing.Size(352, 201)
       Me.Controls.AddRange(New System.Windows.Forms.Control() {Me.treeView1, Me.splitter1, Me.statusBar1})
       Me.IsMdiContainer = True
       Me.Menu = Me.mainMenu1
       Me.Name = "ParentForm"
       Me.Text = "MDI Parent"
       Me.ResumeLayout(False)
   End Sub
  1. End Region
   Dim nextChild As Integer = 1
   Public Sub ChildClosed(ByVal sender As Object, ByVal e As EventArgs)
       Dim node As TreeNode
       For Each node In treeView1.Nodes(0).Nodes
           If node.Tag Is sender Then
               treeView1.Nodes(0).Nodes.Remove(node)
               Exit For
           End If
       Next
   End Sub
   Private Sub cmdFileNewChild_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles cmdFileNewChild.Click
       Dim child As Form = New ChildForm()
       child.Text = "Child " & nextChild.ToString()
       AddHandler child.Closed, AddressOf ChildClosed
       nextChild = nextChild + 1
       child.MdiParent = Me
       child.Show()
       Dim node As TreeNode = New TreeNode(child.Text)
       node.Tag = child
       treeView1.Nodes(0).Nodes.Add(node)
       treeView1.Nodes(0).Expand()
   End Sub
   Private Sub cmdFileExit_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles cmdFileExit.Click
       Close()
   End Sub
   Private Sub cmdWindowArrangeIcons_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles cmdWindowArrangeIcons.Click
       Me.LayoutMdi(MdiLayout.ArrangeIcons)
   End Sub
   Private Sub cmdCascade_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles cmdCascade.Click
       Me.LayoutMdi(MdiLayout.Cascade)
   End Sub
   Private Sub cmdWindowTileChildrenVert_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles cmdWindowTileChildrenVert.Click
       Me.LayoutMdi(MdiLayout.TileVertical)
   End Sub
   Private Sub cmdWindowTileChildrenHoriz_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles cmdWindowTileChildrenHoriz.Click
       Me.LayoutMdi(MdiLayout.TileHorizontal)
   End Sub
   Private Sub treeView1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles treeView1.Click
       Dim child As Form
       If TypeOf (treeView1.SelectedNode.Tag) Is Form Then
           child = CType(treeView1.SelectedNode.Tag, Form)
       End If
       If Not child Is Nothing Then child.Activate()
   End Sub

End Class Public Class MainClass

   Shared Sub Main()
       Dim myform As Form = New ParentForm()
       Application.Run(myform)
   End Sub

End Class


 </source>


Form.Leave

<source lang="vbnet"> Imports System.Diagnostics Imports System.Windows.Forms public class FormEvents

  public Shared Sub Main
       Application.Run(New Form1)
  End Sub

End class

Public Class Form1

   Inherits System.Windows.Forms.Form
  1. Region " Windows Form Designer generated code "
   Public Sub New()
       MyBase.New()
       "This call is required by the Windows Form Designer.
       InitializeComponent()
       "Add any initialization after the InitializeComponent() call
       Console.WriteLine("New Event Fired")
   End Sub
   "Form overrides dispose to clean up the component list.
   Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
       Console.WriteLine("Dispose Method Executed")
       If disposing Then
           If Not (components Is Nothing) Then
               components.Dispose()
           End If
       End If
       MyBase.Dispose(disposing)
   End Sub
   Friend WithEvents btnLoop As System.Windows.Forms.Button
   Friend WithEvents btnRemember As System.Windows.Forms.Button
   Friend WithEvents Button1 As System.Windows.Forms.Button
   Friend WithEvents Button2 As System.Windows.Forms.Button
   Friend WithEvents Button3 As System.Windows.Forms.Button
   "Required by the Windows Form Designer
   Private components As System.ruponentModel.IContainer
   "NOTE: The following procedure is required by the Windows Form Designer
   "It can be modified using the Windows Form Designer.  
   "Do not modify it using the code editor.
   <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
       Me.btnLoop = New System.Windows.Forms.Button()
       Me.btnRemember = New System.Windows.Forms.Button()
       Me.Button1 = New System.Windows.Forms.Button()
       Me.Button2 = New System.Windows.Forms.Button()
       Me.Button3 = New System.Windows.Forms.Button()
       Me.SuspendLayout()
       "
       "btnLoop
       "
       Me.btnLoop.Location = New System.Drawing.Point(24, 56)
       Me.btnLoop.Name = "btnLoop"
       Me.btnLoop.TabIndex = 0
       Me.btnLoop.Text = "Loop"
       "
       "btnRemember
       "
       Me.btnRemember.Location = New System.Drawing.Point(136, 56)
       Me.btnRemember.Name = "btnRemember"
       Me.btnRemember.Size = New System.Drawing.Size(112, 23)
       Me.btnRemember.TabIndex = 1
       Me.btnRemember.Text = "Remember Position"
       "
       "Button1
       "
       Me.Button1.Location = New System.Drawing.Point(24, 16)
       Me.Button1.Name = "Button1"
       Me.Button1.TabIndex = 2
       Me.Button1.Text = "Button1"
       "
       "Button2
       "
       Me.Button2.Location = New System.Drawing.Point(128, 16)
       Me.Button2.Name = "Button2"
       Me.Button2.TabIndex = 3
       Me.Button2.Text = "Button2"
       "
       "Button3
       "
       Me.Button3.Location = New System.Drawing.Point(224, 16)
       Me.Button3.Name = "Button3"
       Me.Button3.Size = New System.Drawing.Size(72, 24)
       Me.Button3.TabIndex = 4
       Me.Button3.Text = "Button3"
       "
       "Form1
       "
       Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
       Me.ClientSize = New System.Drawing.Size(320, 134)
       Me.Controls.AddRange(New System.Windows.Forms.Control() {Me.Button3, Me.Button2, Me.Button1, Me.btnRemember, Me.btnLoop})
       Me.Name = "Form1"
       Me.Text = "Event-O-Rama"
       Me.ResumeLayout(False)
   End Sub
  1. End Region
   Dim formsize As System.Drawing.Size
   Dim formlocation As System.Drawing.Point
   Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Load
       Console.WriteLine("Load Event Fired")
       formsize = Me.Size
       formlocation = Me.Location
   End Sub
   Private Sub Form1_Activated(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Activated
       Console.WriteLine("Activated Event Fired")
   End Sub
   Private Sub Form1_Closed(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Closed
       Console.WriteLine("Closed Event Fired")
   End Sub
   Private Sub Form1_Closing(ByVal sender As Object, ByVal e As System.ruponentModel.CancelEventArgs) Handles MyBase.Closing
       Console.WriteLine("Closing Event Fired")
       Dim answer As MsgBoxResult
       answer = MsgBox("Do you want to close this window?", MsgBoxStyle.YesNo, "Demonstration of the Closing event")
       If answer = MsgBoxResult.No Then
           e.Cancel = True
       End If
   End Sub
   Private Sub Form1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Click
       Console.WriteLine("Click Event Fired")
   End Sub
   Private Sub Form1_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles MyBase.MouseMove
       Console.WriteLine("MouseMove Event Fired")
   End Sub
   Private Sub Form1_Resize(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Resize
       Console.WriteLine("Resize Event Fired " & Me.Size.Width.ToString())
   End Sub
   Private Sub Form1_Deactivate(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Deactivate
       Console.WriteLine("Deactivate Event Fired")
   End Sub
   Private Sub Form1_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles MyBase.Paint
       Console.WriteLine("Paint Event Fired")
   End Sub
   Private Sub Form1_Leave(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Leave
       Console.WriteLine("Leave Event Fired")
   End Sub
   Private Sub Form1_Enter(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Enter
       Console.WriteLine("Enter Event Fired")
   End Sub
   Private Sub btnLoop_Enter(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnLoop.Enter
       Console.WriteLine("btnLoop Enter Event Fired")
       "btnLoop_Leave(sender, e)
   End Sub
   Private Sub btnLoop_Leave(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnLoop.Leave
       Console.WriteLine("btnLoop Leave Event Fired")
       "btnLoop_Enter(sender, e)
   End Sub
   Private Sub btnRemember_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnRemember.Click
       Me.Size = formsize
       Me.Location = formlocation
   End Sub
   Private Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) _
       Handles Button1.Click, Button2.Click, Button3.Click
     MsgBox(sender.Text & " was clicked!")
   End Sub

End Class


 </source>


Form.Load

<source lang="vbnet"> Imports System.Windows.Forms Module Module1

   Sub Main()
       Application.Run(New Form1)
   End Sub

End Module Public Class Form1

   Inherits System.Windows.Forms.Form
  1. Region " Windows Form Designer generated code "
   Public Sub New()
       MyBase.New()
       "This call is required by the Windows Form Designer.
       InitializeComponent()
       "Add any initialization after the InitializeComponent() call
   End Sub
   "Form overrides dispose to clean up the component list.
   Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
       If disposing Then
           If Not (components Is Nothing) Then
               components.Dispose()
           End If
       End If
       MyBase.Dispose(disposing)
   End Sub
   "Required by the Windows Form Designer
   Private components As System.ruponentModel.IContainer
   "NOTE: The following procedure is required by the Windows Form Designer
   "It can be modified using the Windows Form Designer.  
   "Do not modify it using the code editor.
   Friend WithEvents CheckedListBox1 As System.Windows.Forms.CheckedListBox
   Friend WithEvents Button1 As System.Windows.Forms.Button
   <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
       Me.CheckedListBox1 = New System.Windows.Forms.CheckedListBox()
       Me.Button1 = New System.Windows.Forms.Button()
       Me.SuspendLayout()
       "
       "CheckedListBox1
       "
       Me.CheckedListBox1.Location = New System.Drawing.Point(24, 32)
       Me.CheckedListBox1.Name = "CheckedListBox1"
       Me.CheckedListBox1.Size = New System.Drawing.Size(360, 64)
       Me.CheckedListBox1.TabIndex = 0
       "
       "Button1
       "
       Me.Button1.Location = New System.Drawing.Point(152, 120)
       Me.Button1.Name = "Button1"
       Me.Button1.Size = New System.Drawing.Size(96, 23)
       Me.Button1.TabIndex = 1
       Me.Button1.Text = "Show Choice"
       "
       "Form1
       "
       Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
       Me.ClientSize = New System.Drawing.Size(416, 165)
       Me.Controls.AddRange(New System.Windows.Forms.Control() {Me.Button1, Me.CheckedListBox1})
       Me.Name = "Form1"
       Me.Text = "CheckListBoxDemo"
       Me.ResumeLayout(False)
   End Sub
  1. End Region
   Public List() As String = {"A","B","C","D"}
   Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
       CheckedListBox1.BeginUpdate()
       CheckedListBox1.DataSource = List
       CheckedListBox1.EndUpdate()
   End Sub
   Private Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
       If (CheckedListBox1.SelectedItem <> "") Then
           Dim Entry As Object
           For Each Entry In CheckedListBox1.CheckedItems
               MessageBox.Show(Entry.ToString())
           Next
       Else
           MessageBox.Show("You must select an item")
       End If
   End Sub

End Class


 </source>


Form.MdiParent

<source lang="vbnet">

Imports System Imports System.Collections Imports System.Data Imports System.IO Imports System.Xml.Serialization Imports System.Windows.Forms Imports System.Drawing Imports System.Drawing.Drawing2D Imports System.Drawing.Text Imports System.Drawing.Printing

Public Class MainClass

   Shared Sub Main()
      Dim form1 As Form = New Form1()
      Application.Run(form1) 
    End Sub

End Class


Public Class Form1

   Inherits System.Windows.Forms.Form
  1. Region " Windows Form Designer generated code "
   Public Sub New()
       MyBase.New()
       "This call is required by the Windows Form Designer.
       InitializeComponent()
       "Add any initialization after the InitializeComponent() call
   End Sub
   "Form overrides dispose to clean up the component list.
   Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
       If disposing Then
           If Not (components Is Nothing) Then
               components.Dispose()
           End If
       End If
       MyBase.Dispose(disposing)
   End Sub
   "Required by the Windows Form Designer
   Private components As System.ruponentModel.Container
   "NOTE: The following procedure is required by the Windows Form Designer
   "It can be modified using the Windows Form Designer.  
   "Do not modify it using the code editor.
   <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
       "
       "Form1
       "
       Me.AutoScaleBaseSize = New System.Drawing.Size(6, 15)
       Me.ClientSize = New System.Drawing.Size(292, 268)
       Me.Name = "Form1"
       Me.Text = "MDI Example 1"
   End Sub
  1. End Region
   Private Sub Form1_Load(ByVal sender As System.Object, _
  ByVal e As System.EventArgs) _
  Handles MyBase.Load
       Me.Text = "I"m an MDI Parent"
       Me.IsMdiContainer = True
       Dim MyChild As New System.Windows.Forms.Form()
       MyChild.MdiParent = Me
       MyChild.Show()
       MyChild.Text = "MDI Child"
   End Sub

End Class


 </source>


Form.Menu

<source lang="vbnet"> Imports System Imports System.Drawing Imports System.Reflection Imports System.Windows.Forms Imports System.IO

public class MainClass

  Shared Sub Main()
     Dim form1 As Form = New Form1
     Application.Run(form1)
  End Sub

End Class


Public Class Form1

   Inherits System.Windows.Forms.Form
  1. Region " Windows Form Designer generated code "
   Public Sub New()
       MyBase.New()
       "This call is required by the Windows Form Designer.
       InitializeComponent()
       "Add any initialization after the InitializeComponent() call
   End Sub
   "Form overrides dispose to clean up the component list.
   Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
       If disposing Then
           If Not (components Is Nothing) Then
               components.Dispose()
           End If
       End If
       MyBase.Dispose(disposing)
   End Sub
   "Required by the Windows Form Designer
   Private components As System.ruponentModel.IContainer
   "NOTE: The following procedure is required by the Windows Form Designer
   "It can be modified using the Windows Form Designer.  
   "Do not modify it using the code editor.
   Friend WithEvents Button1 As System.Windows.Forms.Button
   Friend WithEvents TextBox1 As System.Windows.Forms.TextBox
   <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
       Me.Button1 = New System.Windows.Forms.Button()
       Me.TextBox1 = New System.Windows.Forms.TextBox()
       Me.SuspendLayout()
       "
       "Button1
       "
       Me.Button1.Font = New System.Drawing.Font("Verdana", 11.25!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
       Me.Button1.Location = New System.Drawing.Point(4, 198)
       Me.Button1.Name = "Button1"
       Me.Button1.Size = New System.Drawing.Size(269, 37)
       Me.Button1.TabIndex = 0
       Me.Button1.Text = "Show Menu Structure"
       "
       "TextBox1
       "
       Me.TextBox1.Font = New System.Drawing.Font("Verdana", 9.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
       Me.TextBox1.Location = New System.Drawing.Point(4, 6)
       Me.TextBox1.Multiline = True
       Me.TextBox1.Name = "TextBox1"
       Me.TextBox1.ScrollBars = System.Windows.Forms.ScrollBars.Vertical
       Me.TextBox1.Size = New System.Drawing.Size(272, 186)
       Me.TextBox1.TabIndex = 1
       Me.TextBox1.Text = ""
       "
       "Form1
       "
       Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
       Me.ClientSize = New System.Drawing.Size(280, 257)
       Me.Controls.AddRange(New System.Windows.Forms.Control() {Me.TextBox1, Me.Button1})
       Me.Name = "Form1"
       Me.Text = "Menu Demo"
       Me.ResumeLayout(False)
   End Sub
  1. End Region
   Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
       Dim menu As New MainMenu()
       Dim item As MenuItem
       item = New MenuItem("File")
       item.MenuItems.Add("New", New System.EventHandler(AddressOf Me.MenuClick))
       item.MenuItems.Add("Open", New System.EventHandler(AddressOf Me.MenuClick))
       item.MenuItems.Add("Exit")
       " Add the top-level menu item to the MainMenu component 
       " and set the MainMenu component to be the form"s menu.
       menu.MenuItems.Add(item)
       item = New MenuItem("Edit")
       item.MenuItems.Add("Copy", New System.EventHandler(AddressOf Me.MenuClick))
       item.MenuItems.Add("Cut", New System.EventHandler(AddressOf Me.MenuClick))
       item.MenuItems.Add("Paste", New System.EventHandler(AddressOf Me.MenuClick))
       menu.MenuItems.Add(item)
       item = New MenuItem("Format")
       item.MenuItems.Add("Font")
       item.MenuItems(0).MenuItems.Add("Verdana", New System.EventHandler(AddressOf Me.MenuClick))
       item.MenuItems(0).MenuItems.Add("Tahoma", New System.EventHandler(AddressOf Me.MenuClick))
       item.MenuItems(0).MenuItems.Add("Georgia", New System.EventHandler(AddressOf Me.MenuClick))
       item.MenuItems.Add("Color", New System.EventHandler(AddressOf Me.MenuClick))
       item.MenuItems.Add("Style", New System.EventHandler(AddressOf Me.MenuClick))
       menu.MenuItems.Add(item)
       Me.Menu = menu
       Dim cMenu As New ContextMenu()
       cMenu.MenuItems.Add("Copy", New System.EventHandler(AddressOf Me.MenuClick))
       cMenu.MenuItems.Add("Cut", New System.EventHandler(AddressOf Me.MenuClick))
       cMenu.MenuItems.Add("Paste", New System.EventHandler(AddressOf Me.MenuClick))
       Me.TextBox1.ContextMenu = cMenu
   End Sub
   Sub MenuClick(ByVal sender As Object, ByVal e As System.EventArgs)
       MsgBox("You selected the command " & sender.text & " of the File menu")
   End Sub
   Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
       Dim mItem As MenuItem
       TextBox1.Clear()
       For Each mItem In Me.Menu.MenuItems
           TextBox1.AppendText(mItem.Text & vbCrLf)
           ScanSubItems(mItem)
       Next
   End Sub
   Sub ScanSubItems(ByVal menuItem As MenuItem)
       Dim item As MenuItem
       Static identation As Integer
       identation += 1
       For Each item In menuItem.MenuItems
           TextBox1.AppendText(StrDup(identation, vbTab) & item.Text & vbCrLf)
           If item.IsParent Then ScanSubItems(item)
       Next
       identation -= 1
   End Sub

End Class


 </source>


Form.MouseDown

<source lang="vbnet">

Imports System Imports System.Drawing Imports System.Windows.Forms Public Class MainClass

  Shared Sub Main()
       Dim myform As Form = New FrmPainter()
       Application.Run(myform)
  End Sub " Main

End Class Public Class FrmPainter

  Inherits System.Windows.Forms.Form
  Dim shouldPaint As Boolean = False
  1. Region " Windows Form Designer generated code "
  Public Sub New()
     MyBase.New()
     "This call is required by the Windows Form Designer.
     InitializeComponent()
     "Add any initialization after the InitializeComponent() call
  End Sub
  "Form overrides dispose to clean up the component list.
  Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
     If disposing Then
        If Not (components Is Nothing) Then
           components.Dispose()
        End If
     End If
     MyBase.Dispose(disposing)
  End Sub
  "Required by the Windows Form Designer
  Private components As System.ruponentModel.Container
  "NOTE: The following procedure is required by the Windows Form Designer
  "It can be modified using the Windows Form Designer.  
  "Do not modify it using the code editor.
  <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
     "
     "Form1
     "
     Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
     Me.ClientSize = New System.Drawing.Size(292, 273)
     Me.Name = "Form1"
     Me.Text = "Painter"
  End Sub
  1. End Region
  Private Sub FrmPainter_MouseMove( _
     ByVal sender As System.Object, _
     ByVal e As System.Windows.Forms.MouseEventArgs) _
     Handles MyBase.MouseMove
     If shouldPaint Then
        Dim graphic As Graphics = CreateGraphics()
        graphic.FillRectangle _
           (New SolidBrush(Color.BlueViolet), e.X, e.Y, 4, 4)
     End If
  End Sub
  Private Sub FrmPainter_MouseDown(ByVal sender As Object, _
     ByVal e As System.Windows.Forms.MouseEventArgs) _
     Handles MyBase.MouseDown
     shouldPaint = True
  End Sub 
  Private Sub FrmPainter_MouseUp(ByVal sender As Object, _
     ByVal e As System.Windows.Forms.MouseEventArgs) _
     Handles MyBase.MouseUp
     shouldPaint = False
  End Sub

End Class


 </source>


Form.MouseMove

<source lang="vbnet"> Imports System.Diagnostics Imports System.Windows.Forms public class FormEvents

  public Shared Sub Main
       Application.Run(New Form1)
  End Sub

End class

Public Class Form1

   Inherits System.Windows.Forms.Form
  1. Region " Windows Form Designer generated code "
   Public Sub New()
       MyBase.New()
       "This call is required by the Windows Form Designer.
       InitializeComponent()
       "Add any initialization after the InitializeComponent() call
       Console.WriteLine("New Event Fired")
   End Sub
   "Form overrides dispose to clean up the component list.
   Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
       Console.WriteLine("Dispose Method Executed")
       If disposing Then
           If Not (components Is Nothing) Then
               components.Dispose()
           End If
       End If
       MyBase.Dispose(disposing)
   End Sub
   Friend WithEvents btnLoop As System.Windows.Forms.Button
   Friend WithEvents btnRemember As System.Windows.Forms.Button
   Friend WithEvents Button1 As System.Windows.Forms.Button
   Friend WithEvents Button2 As System.Windows.Forms.Button
   Friend WithEvents Button3 As System.Windows.Forms.Button
   "Required by the Windows Form Designer
   Private components As System.ruponentModel.IContainer
   "NOTE: The following procedure is required by the Windows Form Designer
   "It can be modified using the Windows Form Designer.  
   "Do not modify it using the code editor.
   <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
       Me.btnLoop = New System.Windows.Forms.Button()
       Me.btnRemember = New System.Windows.Forms.Button()
       Me.Button1 = New System.Windows.Forms.Button()
       Me.Button2 = New System.Windows.Forms.Button()
       Me.Button3 = New System.Windows.Forms.Button()
       Me.SuspendLayout()
       "
       "btnLoop
       "
       Me.btnLoop.Location = New System.Drawing.Point(24, 56)
       Me.btnLoop.Name = "btnLoop"
       Me.btnLoop.TabIndex = 0
       Me.btnLoop.Text = "Loop"
       "
       "btnRemember
       "
       Me.btnRemember.Location = New System.Drawing.Point(136, 56)
       Me.btnRemember.Name = "btnRemember"
       Me.btnRemember.Size = New System.Drawing.Size(112, 23)
       Me.btnRemember.TabIndex = 1
       Me.btnRemember.Text = "Remember Position"
       "
       "Button1
       "
       Me.Button1.Location = New System.Drawing.Point(24, 16)
       Me.Button1.Name = "Button1"
       Me.Button1.TabIndex = 2
       Me.Button1.Text = "Button1"
       "
       "Button2
       "
       Me.Button2.Location = New System.Drawing.Point(128, 16)
       Me.Button2.Name = "Button2"
       Me.Button2.TabIndex = 3
       Me.Button2.Text = "Button2"
       "
       "Button3
       "
       Me.Button3.Location = New System.Drawing.Point(224, 16)
       Me.Button3.Name = "Button3"
       Me.Button3.Size = New System.Drawing.Size(72, 24)
       Me.Button3.TabIndex = 4
       Me.Button3.Text = "Button3"
       "
       "Form1
       "
       Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
       Me.ClientSize = New System.Drawing.Size(320, 134)
       Me.Controls.AddRange(New System.Windows.Forms.Control() {Me.Button3, Me.Button2, Me.Button1, Me.btnRemember, Me.btnLoop})
       Me.Name = "Form1"
       Me.Text = "Event-O-Rama"
       Me.ResumeLayout(False)
   End Sub
  1. End Region
   Dim formsize As System.Drawing.Size
   Dim formlocation As System.Drawing.Point
   Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Load
       Console.WriteLine("Load Event Fired")
       formsize = Me.Size
       formlocation = Me.Location
   End Sub
   Private Sub Form1_Activated(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Activated
       Console.WriteLine("Activated Event Fired")
   End Sub
   Private Sub Form1_Closed(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Closed
       Console.WriteLine("Closed Event Fired")
   End Sub
   Private Sub Form1_Closing(ByVal sender As Object, ByVal e As System.ruponentModel.CancelEventArgs) Handles MyBase.Closing
       Console.WriteLine("Closing Event Fired")
       Dim answer As MsgBoxResult
       answer = MsgBox("Do you want to close this window?", MsgBoxStyle.YesNo, "Demonstration of the Closing event")
       If answer = MsgBoxResult.No Then
           e.Cancel = True
       End If
   End Sub
   Private Sub Form1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Click
       Console.WriteLine("Click Event Fired")
   End Sub
   Private Sub Form1_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles MyBase.MouseMove
       Console.WriteLine("MouseMove Event Fired")
   End Sub
   Private Sub Form1_Resize(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Resize
       Console.WriteLine("Resize Event Fired " & Me.Size.Width.ToString())
   End Sub
   Private Sub Form1_Deactivate(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Deactivate
       Console.WriteLine("Deactivate Event Fired")
   End Sub
   Private Sub Form1_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles MyBase.Paint
       Console.WriteLine("Paint Event Fired")
   End Sub
   Private Sub Form1_Leave(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Leave
       Console.WriteLine("Leave Event Fired")
   End Sub
   Private Sub Form1_Enter(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Enter
       Console.WriteLine("Enter Event Fired")
   End Sub
   Private Sub btnLoop_Enter(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnLoop.Enter
       Console.WriteLine("btnLoop Enter Event Fired")
       "btnLoop_Leave(sender, e)
   End Sub
   Private Sub btnLoop_Leave(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnLoop.Leave
       Console.WriteLine("btnLoop Leave Event Fired")
       "btnLoop_Enter(sender, e)
   End Sub
   Private Sub btnRemember_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnRemember.Click
       Me.Size = formsize
       Me.Location = formlocation
   End Sub
   Private Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) _
       Handles Button1.Click, Button2.Click, Button3.Click
     MsgBox(sender.Text & " was clicked!")
   End Sub

End Class


 </source>


Form.MouseUp

<source lang="vbnet"> Imports System Imports System.Drawing Imports System.Windows.Forms Public Class MainClass

  Shared Sub Main()
       Dim myform As Form = New FrmPainter()
       Application.Run(myform)
  End Sub " Main

End Class Public Class FrmPainter

  Inherits System.Windows.Forms.Form
  Dim shouldPaint As Boolean = False
  1. Region " Windows Form Designer generated code "
  Public Sub New()
     MyBase.New()
     "This call is required by the Windows Form Designer.
     InitializeComponent()
     "Add any initialization after the InitializeComponent() call
  End Sub
  "Form overrides dispose to clean up the component list.
  Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
     If disposing Then
        If Not (components Is Nothing) Then
           components.Dispose()
        End If
     End If
     MyBase.Dispose(disposing)
  End Sub
  "Required by the Windows Form Designer
  Private components As System.ruponentModel.Container
  "NOTE: The following procedure is required by the Windows Form Designer
  "It can be modified using the Windows Form Designer.  
  "Do not modify it using the code editor.
  <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
     "
     "Form1
     "
     Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
     Me.ClientSize = New System.Drawing.Size(292, 273)
     Me.Name = "Form1"
     Me.Text = "Painter"
  End Sub
  1. End Region
  Private Sub FrmPainter_MouseMove( _
     ByVal sender As System.Object, _
     ByVal e As System.Windows.Forms.MouseEventArgs) _
     Handles MyBase.MouseMove
     If shouldPaint Then
        Dim graphic As Graphics = CreateGraphics()
        graphic.FillRectangle _
           (New SolidBrush(Color.BlueViolet), e.X, e.Y, 4, 4)
     End If
  End Sub
  Private Sub FrmPainter_MouseDown(ByVal sender As Object, _
     ByVal e As System.Windows.Forms.MouseEventArgs) _
     Handles MyBase.MouseDown
     shouldPaint = True
  End Sub 
  Private Sub FrmPainter_MouseUp(ByVal sender As Object, _
     ByVal e As System.Windows.Forms.MouseEventArgs) _
     Handles MyBase.MouseUp
     shouldPaint = False
  End Sub

End Class


 </source>


Form.OnNotifyMessage

<source lang="vbnet">

Imports System.Windows.Forms Imports System.IO

Public Class WndProcTextBox

   Inherits TextBox
  1. Region " Component Designer generated code "
   Public Sub New(ByVal Container As System.ruponentModel.IContainer)
       MyClass.New()
       "Required for Windows.Forms Class Composition Designer support
       Container.Add(Me)
   End Sub
   Public Sub New()
       MyBase.New()
       "This call is required by the Component Designer.
       InitializeComponent()
       "Add any initialization after the InitializeComponent() call
       Me.SetStyle(ControlStyles.EnableNotifyMessage, True)
   End Sub
   "Component overrides dispose to clean up the component list.
   Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
       If disposing Then
           If Not (components Is Nothing) Then
               components.Dispose()
           End If
       End If
       MyBase.Dispose(disposing)
   End Sub
   "Required by the Component Designer
   Private components As System.ruponentModel.IContainer
   "NOTE: The following procedure is required by the Component Designer
   "It can be modified using the Component Designer.
   "Do not modify it using the code editor.
   <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
       components = New System.ruponentModel.Container()
   End Sub
  1. End Region
   Public Delegate Sub ShowEventInfo(ByVal info As String)
   Public Event ShowEventInfoEvent As ShowEventInfo
   Protected Overrides Sub OnNotifyMessage(ByVal m As System.Windows.Forms.Message)
       RaiseEvent ShowEventInfoEvent(String.Format("Msg: HWND({0}) LPARAM({1}) WPARAM({2}) MSG({3})", m.HWnd, m.LParam, m.WParam, m.Msg))
       MyBase.OnNotifyMessage(m)
   End Sub

End Class


 </source>


Form.OnPaint

<source lang="vbnet"> Imports System Imports System.Drawing Imports System.Windows.Forms public class MainClass

  Shared Sub Main()
     Dim form1 As Form = New Form1
     Application.Run(form1)
  End Sub

End Class

Public Class Form1

   Inherits System.Windows.Forms.Form
  1. Region " Windows Form Designer generated code "
   Public Sub New()
       MyBase.New()
       "This call is required by the Windows Form Designer.
       InitializeComponent()
       "Add any initialization after the InitializeComponent() call
   End Sub
   "Form overrides dispose to clean up the component list.
   Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
       If disposing Then
           If Not (components Is Nothing) Then
               components.Dispose()
           End If
       End If
       MyBase.Dispose(disposing)
   End Sub
   Friend WithEvents cmdDrawStuff As System.Windows.Forms.Button
   Friend WithEvents cmdInvalidate As System.Windows.Forms.Button
   Friend WithEvents cmdOtherForm As System.Windows.Forms.Button
   "Required by the Windows Form Designer
   Private components As System.ruponentModel.IContainer
   "NOTE: The following procedure is required by the Windows Form Designer
   "It can be modified using the Windows Form Designer.  
   "Do not modify it using the code editor.
   <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
       Me.cmdOtherForm = New System.Windows.Forms.Button()
       Me.cmdDrawStuff = New System.Windows.Forms.Button()
       Me.cmdInvalidate = New System.Windows.Forms.Button()
       Me.SuspendLayout()
       "
       "cmdOtherForm
       "
       Me.cmdOtherForm.Location = New System.Drawing.Point(184, 136)
       Me.cmdOtherForm.Name = "cmdOtherForm"
       Me.cmdOtherForm.Size = New System.Drawing.Size(96, 32)
       Me.cmdOtherForm.TabIndex = 2
       Me.cmdOtherForm.Text = "Other Form"
       "
       "cmdDrawStuff
       "
       Me.cmdDrawStuff.Location = New System.Drawing.Point(184, 80)
       Me.cmdDrawStuff.Name = "cmdDrawStuff"
       Me.cmdDrawStuff.Size = New System.Drawing.Size(96, 32)
       Me.cmdDrawStuff.TabIndex = 1
       Me.cmdDrawStuff.Text = "Draw Stuff"
       "
       "cmdInvalidate
       "
       Me.cmdInvalidate.Location = New System.Drawing.Point(184, 24)
       Me.cmdInvalidate.Name = "cmdInvalidate"
       Me.cmdInvalidate.Size = New System.Drawing.Size(96, 32)
       Me.cmdInvalidate.TabIndex = 0
       Me.cmdInvalidate.Text = "Invalidate"
       "
       "Form1
       "
       Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
       Me.ClientSize = New System.Drawing.Size(292, 273)
       Me.Controls.AddRange(New System.Windows.Forms.Control() {Me.cmdOtherForm, Me.cmdDrawStuff, Me.cmdInvalidate})
       Me.Name = "Form1"
       Me.Text = "Form1"
       Me.ResumeLayout(False)
   End Sub
  1. End Region
   Dim backgroundbitmap As Bitmap
   Protected Overrides Sub OnResize(ByVal e As System.EventArgs)
       If Not Me.ClientRectangle.IsEmpty Then            
           If Not Me.ClientSize.Equals(New Size(backgroundbitmap.Width, backgroundbitmap.Height)) Then
               Dim newbitmap As Bitmap
               newbitmap = New Bitmap(Me.ClientSize.Width, Me.ClientSize.Height)
               If Not backgroundbitmap Is Nothing Then
                   Dim g As Graphics = graphics.FromImage(newbitmap)
                   g.DrawImage(backgroundbitmap, 0, 0)
               End If
               backgroundbitmap = newbitmap
           End If
       End If
   End Sub
   Protected Overrides Sub OnPaint(ByVal e As System.Windows.Forms.PaintEventArgs)

" MyBase.OnPaint(e)

       e.Graphics.DrawLine(pens.Black, 0, 0, 200, 200)
       e.Graphics.DrawLine(pens.Red, 0, 200, 200, 0)
       "RaiseEvent Paint(Me, e)
   End Sub

End Class


 </source>


Form.OnResize

<source lang="vbnet"> imports System imports System.Drawing imports System.Windows.Forms public class ControlDynamicSizeLocation : inherits Form

 private WithEvents btnShow as Button
 public sub New()
   btnShow = new Button()
   btnShow.Parent = me
   Size = new Size(350,400)
   btnShow.Size = new Size(20, 20)
   OnResize(EventArgs.Empty)
 end sub
 protected overrides sub OnResize(ByVal e as EventArgs)
   MyBase.OnResize(e)
   
   
   btnShow.Location = new Point(me.ClientSize.Width/10, me.ClientSize.Height/10)
 end sub
 public shared sub Main() 
   Application.Run(new ControlDynamicSizeLocation())
 end sub

end class


 </source>


Form.Opacity

<source lang="vbnet">

Imports System.Windows.Forms public class FormFadeOut

  public Shared Sub Main
       Application.Run(New Form1)
  End Sub

End class Public Class Form1

   Private Sub ActClose_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles ActClose.Click
       Dim counter As Integer
       For counter = 90 To 10 Step -5
           Me.Opacity = counter / 100
           Me.Refresh()
           Threading.Thread.Sleep(100)
       Next counter
       Me.Close()
   End Sub

End Class

<Global.Microsoft.VisualBasic.rupilerServices.DesignerGenerated()> _ Partial Class Form1

   Inherits System.Windows.Forms.Form
   "Form overrides dispose to clean up the component list.
   <System.Diagnostics.DebuggerNonUserCode()> _
   Protected Overrides Sub Dispose(ByVal disposing As Boolean)
       If disposing AndAlso components IsNot Nothing Then
           components.Dispose()
       End If
       MyBase.Dispose(disposing)
   End Sub
   "Required by the Windows Form Designer
   Private components As System.ruponentModel.IContainer
   "NOTE: The following procedure is required by the Windows Form Designer
   "It can be modified using the Windows Form Designer.  
   "Do not modify it using the code editor.
   <System.Diagnostics.DebuggerStepThrough()> _
   Private Sub InitializeComponent()
       Me.ActClose = New System.Windows.Forms.Button
       Me.SuspendLayout()
       "
       "ActClose
       "
       Me.ActClose.Location = New System.Drawing.Point(104, 112)
       Me.ActClose.Name = "ActClose"
       Me.ActClose.Size = New System.Drawing.Size(75, 23)
       Me.ActClose.TabIndex = 0
       Me.ActClose.Text = "Close"
       Me.ActClose.UseVisualStyleBackColor = True
       "
       "Form1
       "
       Me.AutoScaleDimensions = New System.Drawing.SizeF(6.0!, 13.0!)
       Me.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font
       Me.ClientSize = New System.Drawing.Size(292, 266)
       Me.Controls.Add(Me.ActClose)
       Me.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle
       Me.MaximizeBox = False
       Me.Name = "Form1"
       Me.Text = "Fading Form"
       Me.ResumeLayout(False)
   End Sub
   Friend WithEvents ActClose As System.Windows.Forms.Button

End Class


 </source>


Form.Paint

<source lang="vbnet"> Imports System Imports System.Drawing Imports System.Windows.Forms

Public Class MainClass

  Public Shared Sub Main()
        Application.Run(New OwnerDrawnButton())
  End Sub
  
  

End Class Public Class OwnerDrawnButton

   Inherits System.Windows.Forms.Form
  1. Region " Windows Form Designer generated code "
   Public Sub New()
       MyBase.New()
       "This call is required by the Windows Form Designer.
       InitializeComponent()
       "Add any initialization after the InitializeComponent() call
   End Sub
   "Form overrides dispose to clean up the component list.
   Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
       If disposing Then
           If Not (components Is Nothing) Then
               components.Dispose()
           End If
       End If
       MyBase.Dispose(disposing)
   End Sub
   "Required by the Windows Form Designer
   Private components As System.ruponentModel.IContainer
   "NOTE: The following procedure is required by the Windows Form Designer
   "It can be modified using the Windows Form Designer.  
   "Do not modify it using the code editor.
   Friend WithEvents button4 As System.Windows.Forms.Button
   <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
       Me.button4 = New System.Windows.Forms.Button()
       Me.SuspendLayout()
       "
       "button4
       "
       Me.button4.Location = New System.Drawing.Point(16, 23)
       Me.button4.Name = "button4"
       Me.button4.Size = New System.Drawing.Size(200, 40)
       Me.button4.TabIndex = 2
       Me.button4.Text = "button4"
       "
       "OwnerDrawnButton
       "
       Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
       Me.ClientSize = New System.Drawing.Size(232, 86)
       Me.Controls.AddRange(New System.Windows.Forms.Control() {Me.button4})
       Me.Name = "OwnerDrawnButton"
       Me.Text = "OwnerDrawnButton"
       Me.ResumeLayout(False)
   End Sub
  1. End Region
   Private Sub button4_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles button4.Paint
       Dim _pen As Pen = New Pen(Color.Red, 2)
       e.Graphics.DrawRectangle(_pen, 5, 5, button4.Width - 10, button4.Height - 10)
   End Sub

End Class


 </source>


Form.Region

<source lang="vbnet"> Imports System Imports System.Drawing Imports System.Windows.Forms Imports System.ruponentModel Imports System.Drawing.Drawing2D Imports System.IO Public Class MainClass

   Shared Sub Main()
       Dim form1 As Form = New Form1
       Application.Run(form1)
   End Sub

End Class

Public Class Form1

   Inherits System.Windows.Forms.Form
  1. Region " Windows Form Designer generated code "
   Public Sub New()
       MyBase.New()
       "This call is required by the Windows Form Designer.
       InitializeComponent()
       "Add any initialization after the InitializeComponent() call
   End Sub
   "Form overrides dispose to clean up the component list.
   Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
       If disposing Then
           If Not (components Is Nothing) Then
               components.Dispose()
           End If
       End If
       MyBase.Dispose(disposing)
   End Sub
   "Required by the Windows Form Designer
   Private components As System.ruponentModel.IContainer
   "NOTE: The following procedure is required by the Windows Form Designer
   "It can be modified using the Windows Form Designer.  
   "Do not modify it using the code editor.
   Friend WithEvents Button1 As System.Windows.Forms.Button
   <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
       Me.Button1 = New System.Windows.Forms.Button()
       Me.SuspendLayout()
       "
       "Button1
       "
       Me.Button1.Location = New System.Drawing.Point(20, 16)
       Me.Button1.Name = "Button1"
       Me.Button1.Size = New System.Drawing.Size(136, 36)
       Me.Button1.TabIndex = 0
       Me.Button1.Text = "Button1"
       "
       "Form1
       "
       Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
       Me.ClientSize = New System.Drawing.Size(320, 226)
       Me.Controls.AddRange(New System.Windows.Forms.Control() {Me.Button1})
       Me.Name = "Form1"
       Me.Text = "Shaped Form"
       Me.ResumeLayout(False)
   End Sub
  1. End Region
   Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
       Dim Path As New GraphicsPath()
       Path.AddEllipse(0, 0, Me.Width \ 2, Me.Height \ 2)
       Me.Region = New Region(Path)
   End Sub

End Class


 </source>


Form.RemoveOwnedForm

<source lang="vbnet"> Imports System Imports System.Drawing Imports System.Windows.Forms Imports System.ruponentModel Public Class MainClass

   Shared Sub Main()
       Dim form1 As Form = New Form1
       Application.Run(form1)
   End Sub

End Class Public Class OwnedForm

   Inherits System.Windows.Forms.Form
  1. Region " Windows Form Designer generated code "
   Public Sub New()
       MyBase.New()
       "This call is required by the Windows Form Designer.
       InitializeComponent()
       "Add any initialization after the InitializeComponent() call
   End Sub
   "Form overrides dispose to clean up the component list.
   Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
       If disposing Then
           If Not (components Is Nothing) Then
               components.Dispose()
           End If
       End If
       MyBase.Dispose(disposing)
   End Sub
   Friend WithEvents lblState As System.Windows.Forms.Label
   "Required by the Windows Form Designer
   Private components As System.ruponentModel.Container
   "NOTE: The following procedure is required by the Windows Form Designer
   "It can be modified using the Windows Form Designer.  
   "Do not modify it using the code editor.
   <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
       Me.lblState = New System.Windows.Forms.Label()
       Me.SuspendLayout()
       "
       "lblState
       "
       Me.lblState.Location = New System.Drawing.Point(12, 12)
       Me.lblState.Name = "lblState"
       Me.lblState.Size = New System.Drawing.Size(184, 56)
       Me.lblState.TabIndex = 0
       "
       "OwnedForm
       "
       Me.AutoScaleBaseSize = New System.Drawing.Size(5, 14)
       Me.ClientSize = New System.Drawing.Size(204, 78)
       Me.Controls.AddRange(New System.Windows.Forms.Control() {Me.lblState})
       Me.Font = New System.Drawing.Font("Tahoma", 8.25!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
       Me.Name = "OwnedForm"
       Me.StartPosition = System.Windows.Forms.FormStartPosition.Manual
       Me.Text = "Owned Form"
       Me.ResumeLayout(False)
   End Sub
  1. End Region

End Class

Public Class Form1

   Inherits System.Windows.Forms.Form
  1. Region " Windows Form Designer generated code "
   Public Sub New()
       MyBase.New()
       "This call is required by the Windows Form Designer.
       InitializeComponent()
       "Add any initialization after the InitializeComponent() call
   End Sub
   "Form overrides dispose to clean up the component list.
   Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
       If disposing Then
           If Not (components Is Nothing) Then
               components.Dispose()
           End If
       End If
       MyBase.Dispose(disposing)
   End Sub
   Friend WithEvents cmdAddOwnership As System.Windows.Forms.Button
   Friend WithEvents cmdReleaseOwnership As System.Windows.Forms.Button
   "Required by the Windows Form Designer
   Private components As System.ruponentModel.Container
   "NOTE: The following procedure is required by the Windows Form Designer
   "It can be modified using the Windows Form Designer.  
   "Do not modify it using the code editor.
   Friend WithEvents label1 As System.Windows.Forms.Label
   <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
       Me.cmdAddOwnership = New System.Windows.Forms.Button()
       Me.cmdReleaseOwnership = New System.Windows.Forms.Button()
       Me.label1 = New System.Windows.Forms.Label()
       Me.SuspendLayout()
       "
       "cmdAddOwnership
       "
       Me.cmdAddOwnership.FlatStyle = System.Windows.Forms.FlatStyle.System
       Me.cmdAddOwnership.Location = New System.Drawing.Point(12, 180)
       Me.cmdAddOwnership.Name = "cmdAddOwnership"
       Me.cmdAddOwnership.Size = New System.Drawing.Size(120, 32)
       Me.cmdAddOwnership.TabIndex = 0
       Me.cmdAddOwnership.Text = "Set Ownership"
       "
       "cmdReleaseOwnership
       "
       Me.cmdReleaseOwnership.FlatStyle = System.Windows.Forms.FlatStyle.System
       Me.cmdReleaseOwnership.Location = New System.Drawing.Point(148, 180)
       Me.cmdReleaseOwnership.Name = "cmdReleaseOwnership"
       Me.cmdReleaseOwnership.Size = New System.Drawing.Size(128, 32)
       Me.cmdReleaseOwnership.TabIndex = 1
       Me.cmdReleaseOwnership.Text = "Remove Ownership"
       "
       "label1
       "
       Me.label1.Location = New System.Drawing.Point(40, 32)
       Me.label1.Name = "label1"
       Me.label1.Size = New System.Drawing.Size(216, 80)
       Me.label1.TabIndex = 5
       Me.label1.Text = "Minimize to check the ownership."
       "
       "Owner
       "
       Me.AutoScaleBaseSize = New System.Drawing.Size(5, 14)
       Me.ClientSize = New System.Drawing.Size(288, 222)
       Me.Controls.AddRange(New System.Windows.Forms.Control() {Me.label1, Me.cmdReleaseOwnership, Me.cmdAddOwnership})
       Me.Font = New System.Drawing.Font("Tahoma", 8.25!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
       Me.Name = "Owner"
       Me.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen
       Me.Text = "Basic Form"
       Me.ResumeLayout(False)
   End Sub
  1. End Region
   Private frmOwned As New OwnedForm()
   Private Sub Owner_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
       Me.Show()
       frmOwned.Show()
   End Sub
   Private Sub cmdAddOwnership_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdAddOwnership.Click
       Me.AddOwnedForm(frmOwned)
       frmOwned.lblState.Text = "I"m Owned"
   End Sub
   Private Sub cmdReleaseOwnership_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdReleaseOwnership.Click
       Me.RemoveOwnedForm(frmOwned)
       frmOwned.lblState.Text = "I"m Free!"
   End Sub

End Class


 </source>


Form.Resize

<source lang="vbnet"> Imports System.Diagnostics Imports System.Windows.Forms public class FormEvents

  public Shared Sub Main
       Application.Run(New Form1)
  End Sub

End class

Public Class Form1

   Inherits System.Windows.Forms.Form
  1. Region " Windows Form Designer generated code "
   Public Sub New()
       MyBase.New()
       "This call is required by the Windows Form Designer.
       InitializeComponent()
       "Add any initialization after the InitializeComponent() call
       Console.WriteLine("New Event Fired")
   End Sub
   "Form overrides dispose to clean up the component list.
   Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
       Console.WriteLine("Dispose Method Executed")
       If disposing Then
           If Not (components Is Nothing) Then
               components.Dispose()
           End If
       End If
       MyBase.Dispose(disposing)
   End Sub
   Friend WithEvents btnLoop As System.Windows.Forms.Button
   Friend WithEvents btnRemember As System.Windows.Forms.Button
   Friend WithEvents Button1 As System.Windows.Forms.Button
   Friend WithEvents Button2 As System.Windows.Forms.Button
   Friend WithEvents Button3 As System.Windows.Forms.Button
   "Required by the Windows Form Designer
   Private components As System.ruponentModel.IContainer
   "NOTE: The following procedure is required by the Windows Form Designer
   "It can be modified using the Windows Form Designer.  
   "Do not modify it using the code editor.
   <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
       Me.btnLoop = New System.Windows.Forms.Button()
       Me.btnRemember = New System.Windows.Forms.Button()
       Me.Button1 = New System.Windows.Forms.Button()
       Me.Button2 = New System.Windows.Forms.Button()
       Me.Button3 = New System.Windows.Forms.Button()
       Me.SuspendLayout()
       "
       "btnLoop
       "
       Me.btnLoop.Location = New System.Drawing.Point(24, 56)
       Me.btnLoop.Name = "btnLoop"
       Me.btnLoop.TabIndex = 0
       Me.btnLoop.Text = "Loop"
       "
       "btnRemember
       "
       Me.btnRemember.Location = New System.Drawing.Point(136, 56)
       Me.btnRemember.Name = "btnRemember"
       Me.btnRemember.Size = New System.Drawing.Size(112, 23)
       Me.btnRemember.TabIndex = 1
       Me.btnRemember.Text = "Remember Position"
       "
       "Button1
       "
       Me.Button1.Location = New System.Drawing.Point(24, 16)
       Me.Button1.Name = "Button1"
       Me.Button1.TabIndex = 2
       Me.Button1.Text = "Button1"
       "
       "Button2
       "
       Me.Button2.Location = New System.Drawing.Point(128, 16)
       Me.Button2.Name = "Button2"
       Me.Button2.TabIndex = 3
       Me.Button2.Text = "Button2"
       "
       "Button3
       "
       Me.Button3.Location = New System.Drawing.Point(224, 16)
       Me.Button3.Name = "Button3"
       Me.Button3.Size = New System.Drawing.Size(72, 24)
       Me.Button3.TabIndex = 4
       Me.Button3.Text = "Button3"
       "
       "Form1
       "
       Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
       Me.ClientSize = New System.Drawing.Size(320, 134)
       Me.Controls.AddRange(New System.Windows.Forms.Control() {Me.Button3, Me.Button2, Me.Button1, Me.btnRemember, Me.btnLoop})
       Me.Name = "Form1"
       Me.Text = "Event-O-Rama"
       Me.ResumeLayout(False)
   End Sub
  1. End Region
   Dim formsize As System.Drawing.Size
   Dim formlocation As System.Drawing.Point
   Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Load
       Console.WriteLine("Load Event Fired")
       formsize = Me.Size
       formlocation = Me.Location
   End Sub
   Private Sub Form1_Activated(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Activated
       Console.WriteLine("Activated Event Fired")
   End Sub
   Private Sub Form1_Closed(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Closed
       Console.WriteLine("Closed Event Fired")
   End Sub
   Private Sub Form1_Closing(ByVal sender As Object, ByVal e As System.ruponentModel.CancelEventArgs) Handles MyBase.Closing
       Console.WriteLine("Closing Event Fired")
       Dim answer As MsgBoxResult
       answer = MsgBox("Do you want to close this window?", MsgBoxStyle.YesNo, "Demonstration of the Closing event")
       If answer = MsgBoxResult.No Then
           e.Cancel = True
       End If
   End Sub
   Private Sub Form1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Click
       Console.WriteLine("Click Event Fired")
   End Sub
   Private Sub Form1_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles MyBase.MouseMove
       Console.WriteLine("MouseMove Event Fired")
   End Sub
   Private Sub Form1_Resize(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Resize
       Console.WriteLine("Resize Event Fired " & Me.Size.Width.ToString())
   End Sub
   Private Sub Form1_Deactivate(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Deactivate
       Console.WriteLine("Deactivate Event Fired")
   End Sub
   Private Sub Form1_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles MyBase.Paint
       Console.WriteLine("Paint Event Fired")
   End Sub
   Private Sub Form1_Leave(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Leave
       Console.WriteLine("Leave Event Fired")
   End Sub
   Private Sub Form1_Enter(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Enter
       Console.WriteLine("Enter Event Fired")
   End Sub
   Private Sub btnLoop_Enter(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnLoop.Enter
       Console.WriteLine("btnLoop Enter Event Fired")
       "btnLoop_Leave(sender, e)
   End Sub
   Private Sub btnLoop_Leave(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnLoop.Leave
       Console.WriteLine("btnLoop Leave Event Fired")
       "btnLoop_Enter(sender, e)
   End Sub
   Private Sub btnRemember_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnRemember.Click
       Me.Size = formsize
       Me.Location = formlocation
   End Sub
   Private Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) _
       Handles Button1.Click, Button2.Click, Button3.Click
     MsgBox(sender.Text & " was clicked!")
   End Sub

End Class


 </source>


Form.ResizeRedraw

<source lang="vbnet"> Imports System.Drawing.Drawing2D Imports System Imports System.Drawing.Text Imports System.Drawing Imports System.Windows.Forms Imports System.Math Public Class MainClass

  Shared Sub Main()
      Dim form1 As Form = New Form1()
      Application.Run(form1)
  End Sub 

End Class

Public Class Form1

   Inherits System.Windows.Forms.Form
   Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
       Me.ResizeRedraw = True
   End Sub
   Private Sub Form1_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles MyBase.Paint
       Dim txt As String
       Dim the_font As New Font("Times New Roman", 30, FontStyle.Bold, GraphicsUnit.Pixel)
       Dim layout_rect As RectangleF
       e.Graphics.TextRenderingHint = System.Drawing.Text.TextRenderingHint.AntiAliasGridFit
       layout_rect = New RectangleF(100, 0, 180, 70)
       txt = "Today is Monday. Tomorrow is Friday"
       Dim string_format As New StringFormat
       string_format.Trimming = StringTrimming.Word
       e.Graphics.DrawString(txt, the_font, Brushes.Black, layout_rect, string_format)
       e.Graphics.DrawRectangle(Pens.Black, Rectangle.Round(layout_rect))
   End Sub

End Class


 </source>


Form.SetStyle

<source lang="vbnet"> Imports System Imports System.Collections Imports System.ruponentModel Imports System.Windows.Forms Imports System.Data Imports System.Configuration Imports System.Resources Imports System.Drawing Imports System.Drawing.Drawing2D Imports System.Drawing.Imaging Public Class MainClass

   Shared Sub Main()
       Dim myform As Form = New TransparencyForm()
       Application.Run(myform)
   End Sub

End Class Public Class TransparencyForm

   Inherits System.Windows.Forms.Form
   Public Sub New()
       MyBase.New()
       InitializeComponent()
       Me.SetStyle(ControlStyles.ResizeRedraw, True)
       Me.SetStyle(ControlStyles.DoubleBuffer, True)
       Me.SetStyle(ControlStyles.AllPaintingInWmPaint, True)
   End Sub
   Friend WithEvents splitter2 As System.Windows.Forms.Splitter
   Friend WithEvents splitter1 As System.Windows.Forms.Splitter
   Friend WithEvents groupBox1 As System.Windows.Forms.GroupBox
   Friend WithEvents panel1 As System.Windows.Forms.Panel
   Friend WithEvents groupBox3 As System.Windows.Forms.GroupBox
   Friend WithEvents panel3 As System.Windows.Forms.Panel
   Friend WithEvents groupBox2 As System.Windows.Forms.GroupBox
   Friend WithEvents panel2 As System.Windows.Forms.Panel
   <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
       Me.splitter2 = New System.Windows.Forms.Splitter()
       Me.splitter1 = New System.Windows.Forms.Splitter()
       Me.groupBox1 = New System.Windows.Forms.GroupBox()
       Me.panel1 = New System.Windows.Forms.Panel()
       Me.groupBox3 = New System.Windows.Forms.GroupBox()
       Me.panel3 = New System.Windows.Forms.Panel()
       Me.groupBox2 = New System.Windows.Forms.GroupBox()
       Me.panel2 = New System.Windows.Forms.Panel()
       Me.groupBox1.SuspendLayout()
       Me.groupBox3.SuspendLayout()
       Me.groupBox2.SuspendLayout()
       Me.SuspendLayout()
       "
       "splitter2
       "
       Me.splitter2.Location = New System.Drawing.Point(232, 0)
       Me.splitter2.Name = "splitter2"
       Me.splitter2.Size = New System.Drawing.Size(3, 102)
       Me.splitter2.TabIndex = 9
       Me.splitter2.TabStop = False
       "
       "splitter1
       "
       Me.splitter1.Location = New System.Drawing.Point(229, 0)
       Me.splitter1.Name = "splitter1"
       Me.splitter1.Size = New System.Drawing.Size(3, 102)
       Me.splitter1.TabIndex = 6
       Me.splitter1.TabStop = False
       "
       "groupBox1
       "
       Me.groupBox1.Controls.AddRange(New System.Windows.Forms.Control() {Me.panel1})
       Me.groupBox1.Dock = System.Windows.Forms.DockStyle.Left
       Me.groupBox1.Location = New System.Drawing.Point(117, 0)
       Me.groupBox1.Name = "groupBox1"
       Me.groupBox1.Size = New System.Drawing.Size(112, 102)
       Me.groupBox1.TabIndex = 5
       Me.groupBox1.TabStop = False
       Me.groupBox1.Text = "Original Colors"
       "
       "panel1
       "
       Me.panel1.BackColor = System.Drawing.Color.White
       Me.panel1.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D
       Me.panel1.Dock = System.Windows.Forms.DockStyle.Fill
       Me.panel1.Location = New System.Drawing.Point(3, 16)
       Me.panel1.Name = "panel1"
       Me.panel1.Size = New System.Drawing.Size(106, 83)
       Me.panel1.TabIndex = 0
       "
       "groupBox3
       "
       Me.groupBox3.Controls.AddRange(New System.Windows.Forms.Control() {Me.panel3})
       Me.groupBox3.Dock = System.Windows.Forms.DockStyle.Fill
       Me.groupBox3.Location = New System.Drawing.Point(117, 0)
       Me.groupBox3.Name = "groupBox3"
       Me.groupBox3.Size = New System.Drawing.Size(235, 102)
       Me.groupBox3.TabIndex = 8
       Me.groupBox3.TabStop = False
       Me.groupBox3.Text = "Made Transparent"
       "
       "panel3
       "
       Me.panel3.BackColor = System.Drawing.Color.White
       Me.panel3.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D
       Me.panel3.Dock = System.Windows.Forms.DockStyle.Fill
       Me.panel3.Location = New System.Drawing.Point(3, 16)
       Me.panel3.Name = "panel3"
       Me.panel3.Size = New System.Drawing.Size(229, 83)
       Me.panel3.TabIndex = 0
       "
       "groupBox2
       "
       Me.groupBox2.Controls.AddRange(New System.Windows.Forms.Control() {Me.panel2})
       Me.groupBox2.Dock = System.Windows.Forms.DockStyle.Left
       Me.groupBox2.Name = "groupBox2"
       Me.groupBox2.Size = New System.Drawing.Size(117, 102)
       Me.groupBox2.TabIndex = 7
       Me.groupBox2.TabStop = False
       Me.groupBox2.Text = "White Background"
       "
       "panel2
       "
       Me.panel2.BackColor = System.Drawing.Color.White
       Me.panel2.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D
       Me.panel2.Dock = System.Windows.Forms.DockStyle.Fill
       Me.panel2.Location = New System.Drawing.Point(3, 16)
       Me.panel2.Name = "panel2"
       Me.panel2.Size = New System.Drawing.Size(111, 83)
       Me.panel2.TabIndex = 0
       "
       "TransparencyForm
       "
       Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
       Me.ClientSize = New System.Drawing.Size(352, 102)
       Me.Controls.AddRange(New System.Windows.Forms.Control() {Me.splitter2, Me.splitter1, Me.groupBox1, Me.groupBox3, Me.groupBox2})
       Me.Name = "TransparencyForm"
       Me.Text = "TransparencyForm"
       Me.groupBox1.ResumeLayout(False)
       Me.groupBox3.ResumeLayout(False)
       Me.groupBox2.ResumeLayout(False)
       Me.ResumeLayout(False)
   End Sub
   Dim backgroundString As String = "a\n b\n c\n d\n e\n f\n g\n H \n"
   Private Sub panel1_Paint(ByVal sender As Object, ByVal e As PaintEventArgs) Handles panel1.Paint
       Dim g As Graphics = e.Graphics
       Dim bmp As Bitmap = New Bitmap("figure2.BMP")
       g.DrawString(backgroundString, Me.Font, Brushes.Black, Me.ClientRectangle.Left, Me.ClientRectangle.Top)
       Dim rect As Rectangle = New Rectangle(0, 0, bmp.Width, bmp.Height)
       rect.Offset((Me.panel1.ClientRectangle.Width - rect.Width) / 2, (Me.panel1.ClientRectangle.Height - rect.Height) / 2)
       g.DrawImage(bmp, rect)
   End Sub
   Private Sub panel2_Paint(ByVal sender As Object, ByVal e As PaintEventArgs) Handles panel2.Paint
       Dim g As Graphics = e.Graphics
       Dim bmp As Bitmap = New Bitmap("figure2.BMP")
       g.DrawString(backgroundString, Me.Font, Brushes.Black, Me.ClientRectangle.Left, Me.ClientRectangle.Top)
       Dim colorMap As ColorMap() = New ColorMap() {New ColorMap()}
       colorMap(0).OldColor = bmp.GetPixel(0, bmp.Height - 1)
       colorMap(0).NewColor = Color.White
       Dim attr As ImageAttributes = New ImageAttributes()
       attr.SetRemapTable(colorMap)
       Dim rect As Rectangle = New Rectangle(0, 0, bmp.Width, bmp.Height)
       rect.Offset((Me.panel1.ClientRectangle.Width - rect.Width) / 2, (Me.panel1.ClientRectangle.Height - rect.Height) / 2)
       g.DrawImage(bmp, rect)
   End Sub
   Private Sub panel3_Paint(ByVal sender As Object, ByVal e As PaintEventArgs) Handles panel3.Paint
       Dim g As Graphics = e.Graphics
       Dim bmp As Bitmap = New Bitmap("figure2.BMP")
       g.DrawString(backgroundString, Me.Font, Brushes.Black, Me.ClientRectangle.Left, Me.ClientRectangle.Top)
       bmp.MakeTransparent(bmp.GetPixel(0, bmp.Height - 1))
       Dim rect As Rectangle = New Rectangle(0, 0, bmp.Width, bmp.Height)
       rect.Offset((Me.panel1.ClientRectangle.Width - rect.Width) / 2, (Me.panel1.ClientRectangle.Height - rect.Height) / 2)
       g.DrawImage(bmp, rect)
   End Sub
   Private Sub TransparencyForm_Layout(ByVal sender As Object, ByVal e As LayoutEventArgs) Handles MyBase.Layout
       panel1.Refresh()
       panel2.Refresh()
       panel3.Refresh()
   End Sub

End Class


 </source>


Form.ShowDialog

<source lang="vbnet"> Option Strict On Imports System.Drawing Imports System.Windows.Forms Public Class Form1 : Inherits Form

  Private WithEvents cmdClickCtr As Button = New Button()
  Public Sub New()
     Me.cmdClickCtr.Location = New Point(100, 75)
     Me.cmdClickCtr.Size = New Size(100, 50)
     Me.cmdClickCtr.Text = "Click Counter"
     
     Me.Controls.Add(cmdClickCtr)
     Me.Text = "Click Counter"
  End Sub
  
  Private Sub cmdClickCtr_Click(ByVal sender As System.Object, _
              ByVal e As System.EventArgs) _
              Handles cmdClickCtr.Click
     Static ctr As Integer = 1
     MsgBox("Button was clicked " & ctr & " times.")
     ctr += 1
  End Sub
  
  Public Shared Sub Main()
     Dim frm As New Form1()
     frm.ShowDialog()
  End Sub

End Class


 </source>


Form.Size

<source lang="vbnet"> Imports System.Windows.Forms public class FormDemo

  public Shared Sub Main
       Application.Run(New Form1)
  End Sub

End class Public Class Form1

   Inherits System.Windows.Forms.Form
  1. Region " Windows Form Designer generated code "
   Public Sub New()
       MyBase.New()
       "This call is required by the Windows Form Designer.
       InitializeComponent()
       "Add any initialization after the InitializeComponent() call
   End Sub
   "Form overrides dispose to clean up the component list.
   Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
       If disposing Then
           If Not (components Is Nothing) Then
               components.Dispose()
           End If
       End If
       MyBase.Dispose(disposing)
   End Sub
   Friend WithEvents Button1 As System.Windows.Forms.Button
   Friend WithEvents Button2 As System.Windows.Forms.Button
   Friend WithEvents btnChangeColor As System.Windows.Forms.Button
   Friend WithEvents btnRGB As System.Windows.Forms.Button
   Friend WithEvents btnCompare As System.Windows.Forms.Button
   Friend WithEvents btnFont As System.Windows.Forms.Button
   Friend WithEvents btnBigger As System.Windows.Forms.Button
   Friend WithEvents btnSmaller As System.Windows.Forms.Button
   Friend WithEvents btnFormText As System.Windows.Forms.Button
   "Required by the Windows Form Designer
   Private components As System.ruponentModel.IContainer
   "NOTE: The following procedure is required by the Windows Form Designer
   "It can be modified using the Windows Form Designer.  
   "Do not modify it using the code editor.
   <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
       Dim configurationAppSettings As System.Configuration.AppSettingsReader = New System.Configuration.AppSettingsReader()
       Me.Button1 = New System.Windows.Forms.Button()
       Me.Button2 = New System.Windows.Forms.Button()
       Me.btnChangeColor = New System.Windows.Forms.Button()
       Me.btnRGB = New System.Windows.Forms.Button()
       Me.btnCompare = New System.Windows.Forms.Button()
       Me.btnFont = New System.Windows.Forms.Button()
       Me.btnBigger = New System.Windows.Forms.Button()
       Me.btnSmaller = New System.Windows.Forms.Button()
       Me.btnFormText = New System.Windows.Forms.Button()
       Me.SuspendLayout()
       "
       "Button1
       "
       Me.Button1.Location = New System.Drawing.Point(56, 16)
       Me.Button1.Name = "Button1"
       Me.Button1.TabIndex = 1
       Me.Button1.TabStop = False
       Me.Button1.Text = "Button1"
       "
       "Button2
       "
       Me.Button2.Location = New System.Drawing.Point(216, 16)
       Me.Button2.Name = "Button2"
       Me.Button2.TabIndex = 0
       Me.Button2.TabStop = False
       Me.Button2.Text = "Button2"
       "
       "btnChangeColor
       "
       Me.btnChangeColor.Location = New System.Drawing.Point(56, 56)
       Me.btnChangeColor.Name = "btnChangeColor"
       Me.btnChangeColor.Size = New System.Drawing.Size(128, 23)
       Me.btnChangeColor.TabIndex = 2
       Me.btnChangeColor.Text = "Change Color"
       "
       "btnRGB
       "
       Me.btnRGB.Location = New System.Drawing.Point(56, 96)
       Me.btnRGB.Name = "btnRGB"
       Me.btnRGB.Size = New System.Drawing.Size(128, 23)
       Me.btnRGB.TabIndex = 3
       Me.btnRGB.Text = "Use RGB"
       "
       "btnCompare
       "
       Me.btnCompare.Location = New System.Drawing.Point(56, 136)
       Me.btnCompare.Name = "btnCompare"
       Me.btnCompare.Size = New System.Drawing.Size(128, 24)
       Me.btnCompare.TabIndex = 4
       Me.btnCompare.Text = "Compare"
       "
       "btnFont
       "
       Me.btnFont.Font = New System.Drawing.Font("Edwardian Script ITC", 20.25!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
       Me.btnFont.Location = New System.Drawing.Point(56, 184)
       Me.btnFont.Name = "btnFont"
       Me.btnFont.Size = New System.Drawing.Size(208, 64)
       Me.btnFont.TabIndex = 5
       Me.btnFont.Text = "Change Font!"
       "
       "btnBigger
       "
       Me.btnBigger.Location = New System.Drawing.Point(64, 264)
       Me.btnBigger.Name = "btnBigger"
       Me.btnBigger.Size = New System.Drawing.Size(80, 24)
       Me.btnBigger.TabIndex = 6
       Me.btnBigger.Text = "Bigger"
       "
       "btnSmaller
       "
       Me.btnSmaller.Location = New System.Drawing.Point(64, 304)
       Me.btnSmaller.Name = "btnSmaller"
       Me.btnSmaller.Size = New System.Drawing.Size(80, 24)
       Me.btnSmaller.TabIndex = 7
       Me.btnSmaller.Text = "Smaller"
       "
       "btnFormText
       "
       Me.btnFormText.Location = New System.Drawing.Point(64, 344)
       Me.btnFormText.Name = "btnFormText"
       Me.btnFormText.Size = New System.Drawing.Size(128, 32)
       Me.btnFormText.TabIndex = 8
       Me.btnFormText.Text = "Change Form Text"
       "
       "Form1
       "
       Me.AcceptButton = Me.Button2
       Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
       Me.AutoScroll = True
       Me.BackColor = System.Drawing.Color.FromArgb(CType(255, Byte), CType(128, Byte), CType(128, Byte))
       Me.ClientSize = New System.Drawing.Size(320, 382)
       Me.Controls.AddRange(New System.Windows.Forms.Control() {Me.btnFormText, Me.btnSmaller, Me.btnBigger, Me.btnFont, Me.btnCompare, Me.btnRGB, Me.btnChangeColor, Me.Button2, Me.Button1})
       Me.ForeColor = System.Drawing.Color.Black
       Me.Name = "Form1"
       Me.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen
       Me.Text = "old value"
       Me.TopMost = True
       Me.ResumeLayout(False)
   End Sub
  1. End Region
   Private Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
       MsgBox("I am Button1!")
   End Sub
   Private Sub Button2_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button2.Click
       MsgBox("I am Button2!")
   End Sub
   Private Sub btnChangeColor_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnChangeColor.Click
       Me.BackColor = System.Drawing.Color.Yellow
   End Sub
   Private Sub btnRGB_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnRGB.Click
       Me.BackColor = System.Drawing.Color.Red
   End Sub
   Private Sub btnCompare_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnCompare.Click
       Dim formcolor As System.Drawing.Color
       formcolor = Me.BackColor
       If System.Drawing.Color.op_Equality(formcolor, System.Drawing.color.AliceBlue) Then
           MsgBox("Color changed!")
       Else
           MsgBox("Not yet")
       End If
   End Sub
   Private Sub btnFont_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnFont.Click
       Me.btnFont.Font = New System.Drawing.Font("WingDings", 20)
   End Sub
   Private Sub btnBigger_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnBigger.Click
       Me.Size = New System.Drawing.Size(500, 600)
   End Sub
   Private Sub btnSmaller_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnSmaller.Click
       Me.Size = New System.Drawing.Size(100, 150)
   End Sub
   Private Sub btnFormText_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnFormText.Click
       Me.Text = " new Text"
   End Sub

End Class


 </source>


Form.Text

<source lang="vbnet"> Option Strict On Imports System.Drawing Imports System.Windows.Forms Public Class Form1 : Inherits Form

  Private WithEvents cmdClickCtr As Button = New Button()
  Public Sub New()
     Me.cmdClickCtr.Location = New Point(100, 75)
     Me.cmdClickCtr.Size = New Size(100, 50)
     Me.cmdClickCtr.Text = "Click Counter"
     
     Me.Controls.Add(cmdClickCtr)
     Me.Text = "Click Counter"
  End Sub
  
  Private Sub cmdClickCtr_Click(ByVal sender As System.Object, _
              ByVal e As System.EventArgs) _
              Handles cmdClickCtr.Click
     Static ctr As Integer = 1
     MsgBox("Button was clicked " & ctr & " times.")
     ctr += 1
  End Sub
  
  Public Shared Sub Main()
     Dim frm As New Form1()
     frm.ShowDialog()
  End Sub

End Class


 </source>


Form.TransparencyKey

<source lang="vbnet"> Imports System.Drawing Imports System.Drawing.Drawing2D Imports System.Windows.Forms public class FormBackgroundPicture

  public Shared Sub Main
       Application.Run(New Form1)
  End Sub

End class Public Class Form1

   Inherits System.Windows.Forms.Form
  1. Region " Windows Form Designer generated code "
   Public Sub New()
       MyBase.New()
       "This call is required by the Windows Form Designer.
       InitializeComponent()
       "Add any initialization after the InitializeComponent() call
   End Sub
   "Form overrides dispose to clean up the component list.
   Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
       If disposing Then
           If Not (components Is Nothing) Then
               components.Dispose()
           End If
       End If
       MyBase.Dispose(disposing)
   End Sub
   "Required by the Windows Form Designer
   Private components As System.ruponentModel.IContainer
   "NOTE: The following procedure is required by the Windows Form Designer
   "It can be modified using the Windows Form Designer.  
   "Do not modify it using the code editor.
   Friend WithEvents Button1 As System.Windows.Forms.Button
   <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
       Dim resources As System.Resources.ResourceManager = New System.Resources.ResourceManager(GetType(Form1))
       Me.Button1 = New System.Windows.Forms.Button
       Me.SuspendLayout()
       "
       "Button1
       "
       Me.Button1.Location = New System.Drawing.Point(152, 88)
       Me.Button1.Name = "Button1"
       Me.Button1.TabIndex = 0
       Me.Button1.Text = "Close"
       "
       "Form1
       "
       Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
       Me.BackgroundImage = System.Drawing.Image.FromFile("yourfile.jpg")
       Me.ClientSize = New System.Drawing.Size(376, 208)
       Me.Controls.Add(Me.Button1)
       Me.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None
       Me.Name = "Form1"
       Me.Text = "Form1"
       Me.TransparencyKey = System.Drawing.Color.White
       Me.ResumeLayout(False)
   End Sub
  1. End Region
   Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
       Me.Close()
   End Sub

End Class


 </source>


Form.WndProc

<source lang="vbnet"> Imports System.Windows.Forms public class ConvertMouseEventToFormDragEvent

  public Shared Sub Main
       Application.Run(New Form1)
  End Sub

End class

Public Class Form1

   Const HT_CAPTION As Integer = &H2
   Const WM_NCLBUTTONDOWN As Integer = &HA1
   Private Sub DragBar_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles DragBar.MouseDown
       If (e.Button = Windows.Forms.MouseButtons.Left) Then
           DragBar.Capture = False
           Me.WndProc(Message.Create(Me.Handle, WM_NCLBUTTONDOWN, _
               CType(HT_CAPTION, IntPtr), IntPtr.Zero))
       End If
   End Sub
   Private Sub ActClose_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ActClose.Click
       Me.Close()
   End Sub

End Class

<Global.Microsoft.VisualBasic.rupilerServices.DesignerGenerated()> _ Partial Class Form1

   Inherits System.Windows.Forms.Form
   "Form overrides dispose to clean up the component list.
   <System.Diagnostics.DebuggerNonUserCode()> _
   Protected Overrides Sub Dispose(ByVal disposing As Boolean)
       If disposing AndAlso components IsNot Nothing Then
           components.Dispose()
       End If
       MyBase.Dispose(disposing)
   End Sub
   "Required by the Windows Form Designer
   Private components As System.ruponentModel.IContainer
   "NOTE: The following procedure is required by the Windows Form Designer
   "It can be modified using the Windows Form Designer.  
   "Do not modify it using the code editor.
   <System.Diagnostics.DebuggerStepThrough()> _
   Private Sub InitializeComponent()
       Me.ActClose = New System.Windows.Forms.Button
       Me.DragBar = New System.Windows.Forms.PictureBox
       CType(Me.DragBar, System.ruponentModel.ISupportInitialize).BeginInit()
       Me.SuspendLayout()
       "
       "ActClose
       "
       Me.ActClose.DialogResult = System.Windows.Forms.DialogResult.Cancel
       Me.ActClose.Location = New System.Drawing.Point(208, 80)
       Me.ActClose.Name = "ActClose"
       Me.ActClose.Size = New System.Drawing.Size(75, 23)
       Me.ActClose.TabIndex = 0
       Me.ActClose.Text = "Close"
       Me.ActClose.UseVisualStyleBackColor = True
       "
       "DragBar
       "
       Me.DragBar.BackColor = System.Drawing.SystemColors.ActiveCaption
       Me.DragBar.Location = New System.Drawing.Point(8, 8)
       Me.DragBar.Name = "DragBar"
       Me.DragBar.Size = New System.Drawing.Size(280, 24)
       Me.DragBar.TabIndex = 1
       Me.DragBar.TabStop = False
       "
       "Form1
       "
       Me.AutoScaleDimensions = New System.Drawing.SizeF(6.0!, 13.0!)
       Me.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font
       Me.CancelButton = Me.ActClose
       Me.ClientSize = New System.Drawing.Size(292, 114)
       Me.Controls.Add(Me.DragBar)
       Me.Controls.Add(Me.ActClose)
       Me.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None
       Me.Name = "Form1"
       Me.Text = "Form1"
       CType(Me.DragBar, System.ruponentModel.ISupportInitialize).EndInit()
       Me.ResumeLayout(False)
   End Sub
   Friend WithEvents ActClose As System.Windows.Forms.Button
   Friend WithEvents DragBar As System.Windows.Forms.PictureBox

End Class


 </source>


Inherits Form

<source lang="vbnet"> Imports System.Drawing.Drawing2D Imports System Imports System.Drawing.Text Imports System.Drawing Imports System.Windows.Forms Imports System.Math Public Class MainClass

  Shared Sub Main()
      Dim form1 As Form = New Form1()
      Application.Run(form1)
  End Sub 

End Class

Public Class Form1

   Inherits System.Windows.Forms.Form
   Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
       Me.ResizeRedraw = True
   End Sub
   Private Sub Form1_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles MyBase.Paint
       Dim txt As String
       Dim the_font As New Font("Times New Roman", 30, FontStyle.Bold, GraphicsUnit.Pixel)
       Dim layout_rect As RectangleF
       e.Graphics.TextRenderingHint = System.Drawing.Text.TextRenderingHint.AntiAliasGridFit
       layout_rect = New RectangleF(100, 0, 180, 70)
       txt = "Today is Monday. Tomorrow is Friday"
       Dim string_format As New StringFormat
       string_format.Trimming = StringTrimming.None
       e.Graphics.DrawString(txt, the_font, Brushes.Black, layout_rect, string_format)
       e.Graphics.DrawRectangle(Pens.Black, Rectangle.Round(layout_rect))
   End Sub

End Class


 </source>