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

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

Button.Anchor

  
Imports System.Windows.Forms
public class ButtonAnchor
   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
        Button1.Location = New System.Drawing.Point( _
            Me.ClientRectangle.Width - Button1.Width, _
            Me.ClientRectangle.Height - Button1.Height)
        Button1.Anchor = AnchorStyles.Bottom Or AnchorStyles.Right
    End Sub
End Class
<Global.Microsoft.VisualBasic.rupilerServices.DesignerGenerated()> _
Partial Public Class Form1
    Inherits System.Windows.Forms.Form
    <System.Diagnostics.DebuggerStepThrough()> _
    Private Sub InitializeComponent()
        Me.Button1 = New System.Windows.Forms.Button
        Me.SuspendLayout()
        "
        Me.Button1.Location = New System.Drawing.Point(24, 24)
        Me.Button1.Name = "Button1"
        Me.Button1.Size = New System.Drawing.Size(75, 23)
        Me.Button1.TabIndex = 0
        Me.Button1.Text = "Button1"
        "
        "Form1
        "
        Me.AutoScaleDimensions = New System.Drawing.SizeF(6.0!, 13.0!)
        Me.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font
        Me.ClientSize = New System.Drawing.Size(185, 84)
        Me.Controls.Add(Me.Button1)
        Me.Name = "Form1"
        Me.Text = "Form1"
        Me.ResumeLayout(False)
    End Sub
    Friend WithEvents Button1 As System.Windows.Forms.Button
End Class


Button.BackColor

  
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 OptionsDialog
    Inherits System.Windows.Forms.Form
#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

    "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 okButton As System.Windows.Forms.Button
    Friend WithEvents changeColorButton As System.Windows.Forms.Button
    Friend WithEvents label1 As System.Windows.Forms.Label
    Friend WithEvents errorProvider1 As System.Windows.Forms.ErrorProvider
    Friend WithEvents colorDialog1 As System.Windows.Forms.ColorDialog
    Friend WithEvents _cancelButton As System.Windows.Forms.Button
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
        Me.okButton = New System.Windows.Forms.Button()
        Me.changeColorButton = New System.Windows.Forms.Button()
        Me._cancelButton = New System.Windows.Forms.Button()
        Me.label1 = New System.Windows.Forms.Label()
        Me.errorProvider1 = New System.Windows.Forms.ErrorProvider()
        Me.colorDialog1 = New System.Windows.Forms.ColorDialog()
        Me.SuspendLayout()
        "
        "okButton
        "
        Me.okButton.Anchor = (System.Windows.Forms.AnchorStyles.Bottom Or System.Windows.Forms.AnchorStyles.Right)
        Me.okButton.DialogResult = System.Windows.Forms.DialogResult.OK
        Me.okButton.Location = New System.Drawing.Point(32, 64)
        Me.okButton.Name = "okButton"
        Me.okButton.TabIndex = 5
        Me.okButton.Text = "OK"
        "
        "changeColorButton
        "
        Me.changeColorButton.Location = New System.Drawing.Point(120, 8)
        Me.changeColorButton.Name = "changeColorButton"
        Me.changeColorButton.TabIndex = 4
        Me.changeColorButton.Text = "Change..."
        "
        "_cancelButton
        "
        Me._cancelButton.Anchor = (System.Windows.Forms.AnchorStyles.Bottom Or System.Windows.Forms.AnchorStyles.Right)
        Me._cancelButton.CausesValidation = False
        Me._cancelButton.DialogResult = System.Windows.Forms.DialogResult.Cancel
        Me._cancelButton.Location = New System.Drawing.Point(120, 64)
        Me._cancelButton.Name = "_cancelButton"
        Me._cancelButton.TabIndex = 6
        Me._cancelButton.Text = "Cancel"
        "
        "label1
        "
        Me.label1.Location = New System.Drawing.Point(8, 8)
        Me.label1.Name = "label1"
        Me.label1.TabIndex = 3
        Me.label1.Text = "Favorite Color"
        Me.label1.TextAlign = System.Drawing.ContentAlignment.MiddleLeft
        "
        "errorProvider1
        "
        Me.errorProvider1.DataMember = Nothing
        "
        "OptionsDialog
        "
        Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
        Me.ClientSize = New System.Drawing.Size(208, 102)
        Me.Controls.AddRange(New System.Windows.Forms.Control() {Me._cancelButton, Me.label1, Me.okButton, Me.changeColorButton})
        Me.Name = "OptionsDialog"
        Me.Text = "OptionsDialog"
        Me.ResumeLayout(False)
    End Sub
#End Region
    Private Sub changeColorButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles changeColorButton.Click
        If colorDialog1.ShowDialog() = DialogResult.OK Then
            changeColorButton.BackColor = colorDialog1.Color
        End If
    End Sub
    Public Property FavoriteColor() As Color
        Get
            Return colorDialog1.Color
        End Get
        Set(ByVal Value As Color)
            changeColorButton.BackColor = Value
            colorDialog1.Color = Value
        End Set
    End Property
    Private Sub cancelButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles _cancelButton.Click
    End Sub
    Shared Sub Main()
        Dim myform As Form = New OptionsDialog()
        Application.Run(myform)
    End Sub
End Class


Button.Click

  
imports System
imports System.Drawing
imports System.Windows.Forms
public class EventsDemo : inherits System.Windows.Forms.Form
  Private btn as Button
  public sub New()
    btn = new Button()
    btn.Location = new Point(50,50)
    btn.Text = "Test"
    Controls.Add(btn)
        AddHandler btn.Click, AddressOf btn_Click
  end sub
  public shared sub Main() 
    Application.Run(new EventsDemo())
  end sub
  private sub btn_Click(ByVal sender as object,ByVal e as EventArgs)
    MessageBox.Show("btn_Click method","Events Demonstration")
  end sub
end class


Button.FlatStyle

  

imports System
imports System.Drawing
imports System.Windows.Forms
public class ButtonFlatStyle : inherits Form
  dim btn as Button
  dim i as integer
  dim theStyles as FlatStyle()
  dim img as Image  = Image.FromFile("yourfile.jpg")
  public sub New()
        Text = "Button Properties"
    Size = new Size(300,200)
    btn = new Button()
    btn.Parent = me
    btn.Text = btn.FlatStyle.ToString()
    btn.Location = new Point(10,10)
    btn.Size = new Size(200,100)
    btn.BackColor = Color.LightGreen
    AddHandler btn.Click, AddressOf btn_Click
    btn.Image = img
    btn.ImageAlign = ContentAlignment.MiddleRight
    btn.TextAlign = ContentAlignment.MiddleLeft
    dim theEnum as new FlatStyle()
    theStyles = CType([Enum].GetValues(theEnum.GetType()), FlatStyle())
  end sub
  public shared sub Main() 
    Application.Run(new ButtonFlatStyle())
  end sub
  private sub btn_Click(ByVal sender as object, ByVal e as EventArgs)
    Dim btn as Button = CType(sender, Button)
    btn.FlatStyle = theStyles(i)
    btn.Text = btn.FlatStyle.ToString()
    if (i < theStyles.Length - 1) then
      i = i + 1
    else
      i = 0
    end if
  end sub
end class


Button.HasChildren

  
    
imports System
imports System.Drawing
imports System.Windows.Forms
public class ControlParent : inherits Form
  Private WithEvents btn as Button
  public sub New()
    btn = new Button()
    btn.Location = new Point(50,50)
    btn.Size = new Size(100,23)
    btn.Text = "Relationships"
    Controls.Add(btn)
    btn.Parent = me
  end sub
  public shared sub Main() 
    Application.Run(new ControlParent())
  end sub
  private sub btn_Click(ByVal sender as object,ByVal e as EventArgs) Handles btn.Click
    Console.WriteLine("Button Parent:  " + btn.Parent.ToString())
    Console.WriteLine("Button HasChildren:  " + btn.HasChildren.ToString())
    Console.WriteLine("TopLevelControl:  " + btn.TopLevelControl.ToString())
    Console.WriteLine("Form HasChildren:  " + me.HasChildren.ToString())
    Console.WriteLine("Form Controls Count:  " + me.Controls.Count.ToString())
  end sub
end class


Button.Image

  

imports System
imports System.Drawing
imports System.Windows.Forms
public class ButtonFlatStyle : inherits Form
  dim btn as Button
  dim i as integer
  dim theStyles as FlatStyle()
  dim img as Image  = Image.FromFile("yourfile.jpg")
  public sub New()
        Text = "Button Properties"
    Size = new Size(300,200)
    btn = new Button()
    btn.Parent = me
    btn.Text = btn.FlatStyle.ToString()
    btn.Location = new Point(10,10)
    btn.Size = new Size(200,100)
    btn.BackColor = Color.LightGreen
    AddHandler btn.Click, AddressOf btn_Click
    btn.Image = img
    btn.ImageAlign = ContentAlignment.MiddleRight
    btn.TextAlign = ContentAlignment.MiddleLeft
    dim theEnum as new FlatStyle()
    theStyles = CType([Enum].GetValues(theEnum.GetType()), FlatStyle())
  end sub
  public shared sub Main() 
    Application.Run(new ButtonFlatStyle())
  end sub
  private sub btn_Click(ByVal sender as object, ByVal e as EventArgs)
    Dim btn as Button = CType(sender, Button)
    btn.FlatStyle = theStyles(i)
    btn.Text = btn.FlatStyle.ToString()
    if (i < theStyles.Length - 1) then
      i = i + 1
    else
      i = 0
    end if
  end sub
end class


Button.ImageAlign

  

imports System
imports System.Drawing
imports System.Windows.Forms
public class ButtonFlatStyle : inherits Form
  dim btn as Button
  dim i as integer
  dim theStyles as FlatStyle()
  dim img as Image  = Image.FromFile("yourfile.jpg")
  public sub New()
        Text = "Button Properties"
    Size = new Size(300,200)
    btn = new Button()
    btn.Parent = me
    btn.Text = btn.FlatStyle.ToString()
    btn.Location = new Point(10,10)
    btn.Size = new Size(200,100)
    btn.BackColor = Color.LightGreen
    AddHandler btn.Click, AddressOf btn_Click
    btn.Image = img
    btn.ImageAlign = ContentAlignment.MiddleRight
    btn.TextAlign = ContentAlignment.MiddleLeft
    dim theEnum as new FlatStyle()
    theStyles = CType([Enum].GetValues(theEnum.GetType()), FlatStyle())
  end sub
  public shared sub Main() 
    Application.Run(new ButtonFlatStyle())
  end sub
  private sub btn_Click(ByVal sender as object, ByVal e as EventArgs)
    Dim btn as Button = CType(sender, Button)
    btn.FlatStyle = theStyles(i)
    btn.Text = btn.FlatStyle.ToString()
    if (i < theStyles.Length - 1) then
      i = i + 1
    else
      i = 0
    end if
  end sub
end class


Button.ImageIndex

  

imports System
imports System.Drawing
imports System.Windows.Forms
public class ButtonImageList : inherits Form
  dim imgList as ImageList = new ImageList()
    dim lbl as Label 
    dim lnk as LinkLabel
    dim btn as Button
    dim nmbrUpDown as NumericUpDown
  public sub New()
       Size = new Size(300,300)
    dim img as Image
    dim i as integer
    dim arFiles as string() = {"1.ico","2.ico","3.ico","4.ico"}
    for i = 0 to arFiles.Length - 1
      img = Image.FromFile(arFiles(i))
      imgList.Images.Add(img)
    next
    btn = new Button()
    btn.Parent = me
    btn.ImageList = imgList
    btn.ImageIndex = imgList.Images.Count - 1
    btn.Location = new Point(0, 0)
    btn.Size = new Size(200,20)
    "  Create numeric updown to select the image
    nmbrUpDown = new NumericUpDown()
    nmbrUpDown.Parent = me
    nmbrUpDown.Location = new Point(0, 60)
    nmbrUpDown.Value = 0
    nmbrUpDown.Minimum = 0
    nmbrUpDown.Maximum = imgList.Images.Count - 1
    nmbrUpDown.Width = 50
    nmbrUpDown.ReadOnly = true
    AddHandler nmbrUpDown.ValueChanged,AddressOf nmbrUpDown_ValueChanged
    end sub
    public shared sub Main() 
      Application.Run(new ButtonImageList())
    end sub
    private sub nmbrUpDown_ValueChanged(ByVal sender as object,ByVal e as EventArgs)
      dim n as NumericUpDown  = CType(sender, NumericUpDown)
    btn.ImageIndex = CType(n.Value, Integer)
    end sub
end class


Button.ImageList

  

imports System
imports System.Drawing
imports System.Windows.Forms
public class ButtonImageList : inherits Form
  dim imgList as ImageList = new ImageList()
    dim lbl as Label 
    dim lnk as LinkLabel
    dim btn as Button
    dim nmbrUpDown as NumericUpDown
  public sub New()
       Size = new Size(300,300)
    dim img as Image
    dim i as integer
    dim arFiles as string() = {"1.ico","2.ico","3.ico","4.ico"}
    for i = 0 to arFiles.Length - 1
      img = Image.FromFile(arFiles(i))
      imgList.Images.Add(img)
    next
    btn = new Button()
    btn.Parent = me
    btn.ImageList = imgList
    btn.ImageIndex = imgList.Images.Count - 1
    btn.Location = new Point(0, 0)
    btn.Size = new Size(200,20)
    "  Create numeric updown to select the image
    nmbrUpDown = new NumericUpDown()
    nmbrUpDown.Parent = me
    nmbrUpDown.Location = new Point(0, 60)
    nmbrUpDown.Value = 0
    nmbrUpDown.Minimum = 0
    nmbrUpDown.Maximum = imgList.Images.Count - 1
    nmbrUpDown.Width = 50
    nmbrUpDown.ReadOnly = true
    AddHandler nmbrUpDown.ValueChanged,AddressOf nmbrUpDown_ValueChanged
    end sub
    public shared sub Main() 
      Application.Run(new ButtonImageList())
    end sub
    private sub nmbrUpDown_ValueChanged(ByVal sender as object,ByVal e as EventArgs)
      dim n as NumericUpDown  = CType(sender, NumericUpDown)
    btn.ImageIndex = CType(n.Value, Integer)
    end sub
end class


Button.LostFocus

  
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

Public Class MainClass
    Shared Sub Main()
        Dim myform As Form = New Form1()
        Application.Run(myform)
    End Sub
End Class
Public Class Form1
    Private Sub Button1_Click(ByVal sender As System.Object, _
        ByVal e As System.EventArgs) Handles Button1.Click
        MessageBox.Show("The MouseUp event has been fired.", "Info")
    End Sub
    Private Sub Button1_LostFocus(ByVal sender As Object, _
        ByVal e As System.EventArgs) Handles Button1.LostFocus
        MessageBox.Show("Button1 has lost focus.", "Info")
    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.Button2 = New System.Windows.Forms.Button
        Me.Button1 = New System.Windows.Forms.Button
        Me.SuspendLayout()
        "
        "Button2
        "
        Me.Button2.Location = New System.Drawing.Point(136, 33)
        Me.Button2.Name = "Button2"
        Me.Button2.Size = New System.Drawing.Size(93, 23)
        Me.Button2.TabIndex = 3
        Me.Button2.Text = "Button2"
        "
        "Button1
        "
        Me.Button1.Location = New System.Drawing.Point(24, 33)
        Me.Button1.Name = "Button1"
        Me.Button1.Size = New System.Drawing.Size(93, 23)
        Me.Button1.TabIndex = 2
        Me.Button1.Text = "Mouse Events"
        "
        "Form1
        "
        Me.AutoScaleDimensions = New System.Drawing.SizeF(6.0!, 13.0!)
        Me.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font
        Me.ClientSize = New System.Drawing.Size(253, 89)
        Me.Controls.Add(Me.Button2)
        Me.Controls.Add(Me.Button1)
        Me.Name = "Form1"
        Me.Text = "Form1"
        Me.ResumeLayout(False)
    End Sub
    Friend WithEvents Button2 As System.Windows.Forms.Button
    Friend WithEvents Button1 As System.Windows.Forms.Button
End Class


Button.MouseDown

  
    
Imports System.Drawing
Imports System.Drawing.Drawing2D
Imports System.Windows.Forms
public class MouseEnterLeave
   public Shared Sub Main
        Application.Run(New Form1)
   End Sub
End class
Public Class Form1
    Private ButtonBackColor As Color = Color.LightGreen
    Private Sub Button2_MouseEnter(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button2.MouseEnter
        ButtonBackColor = Color.Yellow
    End Sub
    Private Sub Button2_MouseLeave(ByVal sender As Object,ByVal e As System.EventArgs) Handles Button2.MouseLeave
        ButtonBackColor = Color.Red
    End Sub
    Private Sub Button2_MouseDown(ByVal sender As Object,ByVal e As System.Windows.Forms.MouseEventArgs) Handles Button2.MouseDown
        ButtonBackColor = Color.Green
    End Sub
    Private Sub Button2_MouseUp(ByVal sender As Object,ByVal e As System.Windows.Forms.MouseEventArgs) Handles Button2.MouseUp
        ButtonBackColor = Color.LightGreen
        Button2.Refresh()
    End Sub
    Private Sub Button2_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles Button2.Paint
        Dim canvas As Graphics = e.Graphics
        canvas.Clear(ButtonBackColor)
        Dim atomPen As Pen = New Pen(Color.Blue, 2)
        Dim largerFont As Font = New Font(Me.Font.Name, 10)
        e.Graphics.DrawString("This is a form", largerFont, Brushes.Black,0, 20)
    End Sub
    Private Sub Button2_Click(ByVal sender As System.Object,ByVal e As System.EventArgs) Handles Button2.Click
        MsgBox("Button2 clicked!", MsgBoxStyle.Exclamation,"Painting on Controls")
    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.Panel1 = New System.Windows.Forms.Panel
        Me.Button2 = New System.Windows.Forms.Button
        Me.SuspendLayout()
        "
        "Panel1
        "
        Me.Panel1.Location = New System.Drawing.Point(56, 32)
        Me.Panel1.Name = "Panel1"
        Me.Panel1.Size = New System.Drawing.Size(368, 40)
        Me.Panel1.TabIndex = 0
        "
        "Button2
        "
        Me.Button2.Location = New System.Drawing.Point(272, 104)
        Me.Button2.Name = "Button2"
        Me.Button2.Size = New System.Drawing.Size(152, 152)
        Me.Button2.TabIndex = 1
        Me.Button2.Text = "Button2"
        Me.Button2.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(479, 284)
        Me.Controls.Add(Me.Button2)
        Me.Controls.Add(Me.Panel1)
        Me.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle
        Me.MaximizeBox = False
        Me.Text = "Special Effects"
        Me.ResumeLayout(False)
    End Sub
    Friend WithEvents Panel1 As System.Windows.Forms.Panel
    Friend WithEvents Button2 As System.Windows.Forms.Button
End Class


Button.MouseEnter

  
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

Public Class MainClass
    Shared Sub Main()
        Dim myform As Form = New Form1()
        Application.Run(myform)
    End Sub
End Class
Public Class Form1
    Private Sub btnSayHello_Click(ByVal sender As System.Object, _
        ByVal e As System.EventArgs) Handles btnSayHello.Click
        "Display a MessageBox
        MessageBox.Show("Hello, world!", Me.Text)
    End Sub
    Private Sub btnSayHello_MouseEnter(ByVal sender As Object, _
        ByVal e As System.EventArgs) Handles btnSayHello.MouseEnter
        "Change the Button text
        btnSayHello.Text = "The mouse is here!"
    End Sub
    Private Sub btnSayHello_MouseLeave(ByVal sender As Object, _
        ByVal e As System.EventArgs) Handles btnSayHello.MouseLeave
        "Change the Button text
        btnSayHello.Text = "The mouse has gone!"
    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.btnSayHello = New System.Windows.Forms.Button
        Me.SuspendLayout()
        "
        "btnSayHello
        "
        Me.btnSayHello.Location = New System.Drawing.Point(22, 22)
        Me.btnSayHello.Name = "btnSayHello"
        Me.btnSayHello.Size = New System.Drawing.Size(165, 23)
        Me.btnSayHello.TabIndex = 0
        Me.btnSayHello.Text = "Hello, world!"
        "
        "Form1
        "
        Me.AutoScaleDimensions = New System.Drawing.SizeF(6.0!, 13.0!)
        Me.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font
        Me.ClientSize = New System.Drawing.Size(209, 67)
        Me.Controls.Add(Me.btnSayHello)
        Me.Name = "Form1"
        Me.Text = "Hello, world! 2.0"
        Me.ResumeLayout(False)
    End Sub
    Friend WithEvents btnSayHello As System.Windows.Forms.Button
End Class


Button.MouseHover

  

    
Option Strict On
imports System
imports System.Drawing
imports System.Windows.Forms
public class MouseEnterHoverLeave : inherits Form
  private btn as Button
  public sub New()
    Size = new Size(400,400)
    btn = new Button()
    btn.Parent = me
    btn.Location = new Point(50,50)
    btn.Size = new Size(150,25)
    AddHandler btn.MouseEnter, AddressOf btn_MouseEnter
    AddHandler btn.MouseHover, AddressOf btn_MouseHover
    AddHandler btn.MouseLeave, AddressOf btn_MouseLeave
  end sub
  public shared sub Main() 
    Application.Run(new MouseEnterHoverLeave())
  end sub
  private sub btn_MouseEnter(ByVal sender as object,ByVal e as EventArgs)
    btn.Text = "MouseEnter"
    Console.WriteLine("Button MouseEnter")
  end sub
  private sub btn_MouseHover(ByVal sender as object,ByVal e as EventArgs)
    btn.Text = "MouseHover"
    Console.WriteLine("Button MouseHover")
  end sub
  private sub btn_MouseLeave(ByVal sender as object,ByVal e as EventArgs)
    btn.Text = "MouseLeave"
    Console.WriteLine("Button MouseLeave")
  end sub
  protected overrides sub OnMouseEnter(ByVal e as EventArgs)
    myBase.OnMouseEnter(e)
    Console.WriteLine("Form MouseEnter")
  end sub
  protected overrides sub OnMouseHover(ByVal e as EventArgs)
    myBase.OnMouseHover(e)
    Console.WriteLine("Form MouseHover")
  end sub
  protected overrides sub OnMouseLeave(ByVal e as EventArgs)
    myBase.OnMouseLeave(e)
    Console.WriteLine("Form MouseLeave")
  end sub
end class


Button.MouseLeave

  

    
Option Strict On
imports System
imports System.Drawing
imports System.Windows.Forms
public class MouseEnterHoverLeave : inherits Form
  private btn as Button
  public sub New()
    Size = new Size(400,400)
    btn = new Button()
    btn.Parent = me
    btn.Location = new Point(50,50)
    btn.Size = new Size(150,25)
    AddHandler btn.MouseEnter, AddressOf btn_MouseEnter
    AddHandler btn.MouseHover, AddressOf btn_MouseHover
    AddHandler btn.MouseLeave, AddressOf btn_MouseLeave
  end sub
  public shared sub Main() 
    Application.Run(new MouseEnterHoverLeave())
  end sub
  private sub btn_MouseEnter(ByVal sender as object,ByVal e as EventArgs)
    btn.Text = "MouseEnter"
    Console.WriteLine("Button MouseEnter")
  end sub
  private sub btn_MouseHover(ByVal sender as object,ByVal e as EventArgs)
    btn.Text = "MouseHover"
    Console.WriteLine("Button MouseHover")
  end sub
  private sub btn_MouseLeave(ByVal sender as object,ByVal e as EventArgs)
    btn.Text = "MouseLeave"
    Console.WriteLine("Button MouseLeave")
  end sub
  protected overrides sub OnMouseEnter(ByVal e as EventArgs)
    myBase.OnMouseEnter(e)
    Console.WriteLine("Form MouseEnter")
  end sub
  protected overrides sub OnMouseHover(ByVal e as EventArgs)
    myBase.OnMouseHover(e)
    Console.WriteLine("Form MouseHover")
  end sub
  protected overrides sub OnMouseLeave(ByVal e as EventArgs)
    myBase.OnMouseLeave(e)
    Console.WriteLine("Form MouseLeave")
  end sub
end class


Button.MouseUp

  

    
Imports System.Drawing
Imports System.Drawing.Drawing2D
Imports System.Windows.Forms
public class MouseEnterLeave
   public Shared Sub Main
        Application.Run(New Form1)
   End Sub
End class
Public Class Form1
    Private ButtonBackColor As Color = Color.LightGreen
    Private Sub Button2_MouseEnter(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button2.MouseEnter
        ButtonBackColor = Color.Yellow
    End Sub
    Private Sub Button2_MouseLeave(ByVal sender As Object,ByVal e As System.EventArgs) Handles Button2.MouseLeave
        ButtonBackColor = Color.Red
    End Sub
    Private Sub Button2_MouseDown(ByVal sender As Object,ByVal e As System.Windows.Forms.MouseEventArgs) Handles Button2.MouseDown
        ButtonBackColor = Color.Green
    End Sub
    Private Sub Button2_MouseUp(ByVal sender As Object,ByVal e As System.Windows.Forms.MouseEventArgs) Handles Button2.MouseUp
        ButtonBackColor = Color.LightGreen
        Button2.Refresh()
    End Sub
    Private Sub Button2_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles Button2.Paint
        Dim canvas As Graphics = e.Graphics
        canvas.Clear(ButtonBackColor)
        Dim atomPen As Pen = New Pen(Color.Blue, 2)
        Dim largerFont As Font = New Font(Me.Font.Name, 10)
        e.Graphics.DrawString("This is a form", largerFont, Brushes.Black,0, 20)
    End Sub
    Private Sub Button2_Click(ByVal sender As System.Object,ByVal e As System.EventArgs) Handles Button2.Click
        MsgBox("Button2 clicked!", MsgBoxStyle.Exclamation,"Painting on Controls")
    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.Panel1 = New System.Windows.Forms.Panel
        Me.Button2 = New System.Windows.Forms.Button
        Me.SuspendLayout()
        "
        "Panel1
        "
        Me.Panel1.Location = New System.Drawing.Point(56, 32)
        Me.Panel1.Name = "Panel1"
        Me.Panel1.Size = New System.Drawing.Size(368, 40)
        Me.Panel1.TabIndex = 0
        "
        "Button2
        "
        Me.Button2.Location = New System.Drawing.Point(272, 104)
        Me.Button2.Name = "Button2"
        Me.Button2.Size = New System.Drawing.Size(152, 152)
        Me.Button2.TabIndex = 1
        Me.Button2.Text = "Button2"
        Me.Button2.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(479, 284)
        Me.Controls.Add(Me.Button2)
        Me.Controls.Add(Me.Panel1)
        Me.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle
        Me.MaximizeBox = False
        Me.Text = "Special Effects"
        Me.ResumeLayout(False)
    End Sub
    Friend WithEvents Panel1 As System.Windows.Forms.Panel
    Friend WithEvents Button2 As System.Windows.Forms.Button
End Class


Button.Paint

  
    
Imports System.Drawing
Imports System.Drawing.Drawing2D
Imports System.Windows.Forms
public class MouseEnterLeave
   public Shared Sub Main
        Application.Run(New Form1)
   End Sub
End class
Public Class Form1
    Private ButtonBackColor As Color = Color.LightGreen
    Private Sub Button2_MouseEnter(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button2.MouseEnter
        ButtonBackColor = Color.Yellow
    End Sub
    Private Sub Button2_MouseLeave(ByVal sender As Object,ByVal e As System.EventArgs) Handles Button2.MouseLeave
        ButtonBackColor = Color.Red
    End Sub
    Private Sub Button2_MouseDown(ByVal sender As Object,ByVal e As System.Windows.Forms.MouseEventArgs) Handles Button2.MouseDown
        ButtonBackColor = Color.Green
    End Sub
    Private Sub Button2_MouseUp(ByVal sender As Object,ByVal e As System.Windows.Forms.MouseEventArgs) Handles Button2.MouseUp
        ButtonBackColor = Color.LightGreen
        Button2.Refresh()
    End Sub
    Private Sub Button2_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles Button2.Paint
        Dim canvas As Graphics = e.Graphics
        canvas.Clear(ButtonBackColor)
        Dim atomPen As Pen = New Pen(Color.Blue, 2)
        Dim largerFont As Font = New Font(Me.Font.Name, 10)
        e.Graphics.DrawString("This is a form", largerFont, Brushes.Black,0, 20)
    End Sub
    Private Sub Button2_Click(ByVal sender As System.Object,ByVal e As System.EventArgs) Handles Button2.Click
        MsgBox("Button2 clicked!", MsgBoxStyle.Exclamation,"Painting on Controls")
    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.Panel1 = New System.Windows.Forms.Panel
        Me.Button2 = New System.Windows.Forms.Button
        Me.SuspendLayout()
        "
        "Panel1
        "
        Me.Panel1.Location = New System.Drawing.Point(56, 32)
        Me.Panel1.Name = "Panel1"
        Me.Panel1.Size = New System.Drawing.Size(368, 40)
        Me.Panel1.TabIndex = 0
        "
        "Button2
        "
        Me.Button2.Location = New System.Drawing.Point(272, 104)
        Me.Button2.Name = "Button2"
        Me.Button2.Size = New System.Drawing.Size(152, 152)
        Me.Button2.TabIndex = 1
        Me.Button2.Text = "Button2"
        Me.Button2.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(479, 284)
        Me.Controls.Add(Me.Button2)
        Me.Controls.Add(Me.Panel1)
        Me.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle
        Me.MaximizeBox = False
        Me.Text = "Special Effects"
        Me.ResumeLayout(False)
    End Sub
    Friend WithEvents Panel1 As System.Windows.Forms.Panel
    Friend WithEvents Button2 As System.Windows.Forms.Button
End Class


Button.Parent

  
imports System
imports System.Drawing
imports System.Windows.Forms
public class ControlAnchorBottomLeft : inherits Form
  public sub New()
    Size = new Size(350,400)
    dim xButtonSize as integer = 120
    dim xMargin, yMargin  as integer
    xMargin = Font.Height * 2
    yMargin = Font.Height * 2
    dim btn as new Button()
    btn.Parent = me
    btn.Text = "Upper Left"
    
    btn.Size = new Size(xButtonSize, 26)
    btn.Location = new Point(xMargin, yMargin)
    btn = new Button()
    btn.Parent = me
    btn.Text = "Lower Left"
    btn.Size = new Size(xButtonSize, 26)
    btn.Location = new Point(xMargin, me.ClientSize.Height - yMargin - 26)
    btn.Anchor = AnchorStyles.Bottom Or AnchorStyles.Left
  end sub
  public shared sub Main() 
    Application.Run(new ControlAnchorBottomLeft())
  end sub
end class


Button.PerformClick

  
Imports System.Drawing
Imports System.Drawing.Drawing2D
Imports System.Windows.Forms
public class ButtonPerformClick
   public Shared Sub Main
        Application.Run(New Form1)
   End Sub
End class
Public Class Form1
    Inherits System.Windows.Forms.Form
    Friend WithEvents Button1 As System.Windows.Forms.Button
    Friend WithEvents Button2 As System.Windows.Forms.Button
    Friend WithEvents Label1 As System.Windows.Forms.Label
    Public Sub New()
        MyBase.New()
        Me.Button1 = New System.Windows.Forms.Button
        Me.Button2 = New System.Windows.Forms.Button
        Me.Label1 = New System.Windows.Forms.Label
        Me.SuspendLayout()
        "
        "Button1
        "
        Me.Button1.Location = New System.Drawing.Point(72, 80)
        Me.Button1.Name = "Button1"
        Me.Button1.Size = New System.Drawing.Size(184, 23)
        Me.Button1.TabIndex = 0
        Me.Button1.Text = "Click Me to Click the Other Button"
        "
        "Button2
        "
        Me.Button2.Location = New System.Drawing.Point(72, 160)
        Me.Button2.Name = "Button2"
        Me.Button2.Size = New System.Drawing.Size(184, 23)
        Me.Button2.TabIndex = 1
        Me.Button2.Text = "The Other Button"
        "
        "Label1
        "
        Me.Label1.Font = New System.Drawing.Font("Microsoft Sans Serif", 14.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.Label1.Location = New System.Drawing.Point(0, 0)
        Me.Label1.Name = "Label1"
        Me.Label1.Size = New System.Drawing.Size(328, 40)
        Me.Label1.TabIndex = 2
        Me.Label1.Text = "Clicked"
        "
        "Form1
        "
        Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
        Me.ClientSize = New System.Drawing.Size(328, 273)
        Me.Controls.Add(Me.Label1)
        Me.Controls.Add(Me.Button2)
        Me.Controls.Add(Me.Button1)
        Me.Name = "Form1"
        Me.Text = "Form1"
        Me.ResumeLayout(False)
    End Sub
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Button2.PerformClick()
    End Sub
    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        Button2.Text = "I"ve been clicked!"
    End Sub
End Class


Button.Region

  
Imports System.Drawing
Imports System.Drawing.Drawing2D
Imports System.Windows.Forms
public class IrregularShapeButton
   public Shared Sub Main
        Application.Run(New Form1)
   End Sub
End class

Public Class Form1
    Inherits System.Windows.Forms.Form
    Private originalSize As Size
    Friend WithEvents AnimationBtn As System.Windows.Forms.Button
    Friend WithEvents VideoBtn As System.Windows.Forms.Button
    Friend WithEvents AudioBtn As System.Windows.Forms.Button
    Friend WithEvents ContextMenu1 As System.Windows.Forms.ContextMenu
    Friend WithEvents Circlemenu As System.Windows.Forms.MenuItem
    Friend WithEvents RectMenu As System.Windows.Forms.MenuItem
    Friend WithEvents TriangleMenu As System.Windows.Forms.MenuItem
    Friend WithEvents CloseMenu As System.Windows.Forms.MenuItem
    Public Sub New()
        MyBase.New()
        Me.AnimationBtn = New System.Windows.Forms.Button
        Me.VideoBtn = New System.Windows.Forms.Button
        Me.AudioBtn = New System.Windows.Forms.Button
        Me.ContextMenu1 = New System.Windows.Forms.ContextMenu
        Me.Circlemenu = New System.Windows.Forms.MenuItem
        Me.RectMenu = New System.Windows.Forms.MenuItem
        Me.TriangleMenu = New System.Windows.Forms.MenuItem
        Me.CloseMenu = New System.Windows.Forms.MenuItem
        Me.SuspendLayout()
        "
        "AnimationBtn
        "
        Me.AnimationBtn.BackColor = System.Drawing.Color.Blue
        Me.AnimationBtn.Font = New System.Drawing.Font("Tahoma", 10.0!, System.Drawing.FontStyle.Bold)
        Me.AnimationBtn.ForeColor = System.Drawing.SystemColors.ControlLightLight
        Me.AnimationBtn.Location = New System.Drawing.Point(120, 146)
        Me.AnimationBtn.Name = "AnimationBtn"
        Me.AnimationBtn.Size = New System.Drawing.Size(152, 104)
        Me.AnimationBtn.TabIndex = 6
        Me.AnimationBtn.Text = "Animation"
        "
        "VideoBtn
        "
        Me.VideoBtn.BackColor = System.Drawing.Color.Green
        Me.VideoBtn.Font = New System.Drawing.Font("Tahoma", 10.0!, System.Drawing.FontStyle.Bold)
        Me.VideoBtn.ForeColor = System.Drawing.SystemColors.ControlLightLight
        Me.VideoBtn.Location = New System.Drawing.Point(208, 26)
        Me.VideoBtn.Name = "VideoBtn"
        Me.VideoBtn.Size = New System.Drawing.Size(160, 96)
        Me.VideoBtn.TabIndex = 5
        Me.VideoBtn.Text = "Play Video"
        "
        "AudioBtn
        "
        Me.AudioBtn.BackColor = System.Drawing.Color.FromArgb(CType(255, Byte), CType(128, Byte), CType(0, Byte))
        Me.AudioBtn.Font = New System.Drawing.Font("Tahoma", 10.0!, System.Drawing.FontStyle.Bold)
        Me.AudioBtn.ForeColor = System.Drawing.SystemColors.ControlLightLight
        Me.AudioBtn.Location = New System.Drawing.Point(96, 26)
        Me.AudioBtn.Name = "AudioBtn"
        Me.AudioBtn.Size = New System.Drawing.Size(160, 96)
        Me.AudioBtn.TabIndex = 4
        Me.AudioBtn.Text = "Play Audio"
        "
        "ContextMenu1
        "
        Me.ContextMenu1.MenuItems.AddRange(New System.Windows.Forms.MenuItem() {Me.Circlemenu, Me.RectMenu, Me.TriangleMenu, Me.CloseMenu})
        "
        "Circlemenu
        "
        Me.Circlemenu.Index = 0
        Me.Circlemenu.Text = "Circle"
        "
        "RectMenu
        "
        Me.RectMenu.Index = 1
        Me.RectMenu.Text = "Original"
        "
        "TriangleMenu
        "
        Me.TriangleMenu.Index = 2
        Me.TriangleMenu.Text = "TriangleMenu"
        "
        "CloseMenu
        "
        Me.CloseMenu.Index = 3
        Me.CloseMenu.Text = "Close"
        "
        "Form1
        "
        Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
        Me.ClientSize = New System.Drawing.Size(464, 277)
        Me.Controls.Add(Me.AnimationBtn)
        Me.Controls.Add(Me.VideoBtn)
        Me.Controls.Add(Me.AudioBtn)
        Me.ResumeLayout(False)
    End Sub

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        originalSize = Me.Size
        Dim path1 As New GraphicsPath(FillMode.Alternate)
        path1.AddEllipse(New Rectangle(30, 30, AudioBtn.Width - 60, AudioBtn.Height - 60))
        AudioBtn.Region = New [Region](path1)
        Dim path2 As New GraphicsPath(FillMode.Alternate)
        path2.AddEllipse(New Rectangle(30, 30, VideoBtn.Width - 60, VideoBtn.Height - 60))
        VideoBtn.Region = New [Region](path2)
        Dim path3 As New GraphicsPath(FillMode.Alternate)
        path3.AddEllipse(New Rectangle(20, 20, VideoBtn.Width - 40, VideoBtn.Height - 40))
        AnimationBtn.Region = New [Region](path3)
    End Sub
    Private Sub AudioBtn_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles AudioBtn.Click
        MessageBox.Show("Play Audio Button clicked!")
    End Sub
    Private Sub VideoBtn_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles VideoBtn.Click
        MessageBox.Show("Play Video Button clicked!")
    End Sub
    Private Sub AnimationBtn_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles AnimationBtn.Click
        MessageBox.Show("Play Animation Button clicked!")
    End Sub
    
End Class


Button.Text

  
Imports System
Imports System.Windows.Forms
Class MyFirstForm
    Inherits Form
    Private WithEvents mybutton As Button
    Public Sub New()
        Me.Text = "Hello, WinForms!"
        mybutton = New Button()
        mybutton.Text = "Click Me!"
        Me.Controls.Add(mybutton)
    End Sub
    Public Sub mybutton_Click(sender As Object, e As EventArgs) Handles mybutton.Click
        MessageBox.Show("Message")
    End Sub
    Shared Sub Main()
        Dim myform As Form = New MyFirstForm()
        Application.Run(myform)
    End Sub
End Class


Button.TextAlign

  

imports System
imports System.Drawing
imports System.Windows.Forms
public class ButtonFlatStyle : inherits Form
  dim btn as Button
  dim i as integer
  dim theStyles as FlatStyle()
  dim img as Image  = Image.FromFile("yourfile.jpg")
  public sub New()
        Text = "Button Properties"
    Size = new Size(300,200)
    btn = new Button()
    btn.Parent = me
    btn.Text = btn.FlatStyle.ToString()
    btn.Location = new Point(10,10)
    btn.Size = new Size(200,100)
    btn.BackColor = Color.LightGreen
    AddHandler btn.Click, AddressOf btn_Click
    btn.Image = img
    btn.ImageAlign = ContentAlignment.MiddleRight
    btn.TextAlign = ContentAlignment.MiddleLeft
    dim theEnum as new FlatStyle()
    theStyles = CType([Enum].GetValues(theEnum.GetType()), FlatStyle())
  end sub
  public shared sub Main() 
    Application.Run(new ButtonFlatStyle())
  end sub
  private sub btn_Click(ByVal sender as object, ByVal e as EventArgs)
    Dim btn as Button = CType(sender, Button)
    btn.FlatStyle = theStyles(i)
    btn.Text = btn.FlatStyle.ToString()
    if (i < theStyles.Length - 1) then
      i = i + 1
    else
      i = 0
    end if
  end sub
end class


Button.TopLevelControl

  
    
imports System
imports System.Drawing
imports System.Windows.Forms
public class ControlParent : inherits Form
  Private WithEvents btn as Button
  public sub New()
    btn = new Button()
    btn.Location = new Point(50,50)
    btn.Size = new Size(100,23)
    btn.Text = "Relationships"
    Controls.Add(btn)
    btn.Parent = me
  end sub
  public shared sub Main() 
    Application.Run(new ControlParent())
  end sub
  private sub btn_Click(ByVal sender as object,ByVal e as EventArgs) Handles btn.Click
    Console.WriteLine("Button Parent:  " + btn.Parent.ToString())
    Console.WriteLine("Button HasChildren:  " + btn.HasChildren.ToString())
    Console.WriteLine("TopLevelControl:  " + btn.TopLevelControl.ToString())
    Console.WriteLine("Form HasChildren:  " + me.HasChildren.ToString())
    Console.WriteLine("Form Controls Count:  " + me.Controls.Count.ToString())
  end sub
end class


Button.UseVisualStyleBackColor

  
Imports System.Windows.Forms
public class AddButtonAndAddEventHandler
   public Shared Sub Main
        Application.Run(New Form1)
   End Sub
End class

Public Class Form1
    Private Sub ShowTheTime(ByVal sender As System.Object, ByVal e As System.EventArgs)
            Console.WriteLine( Now.ToLongTimeString())
    End Sub
    Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        Dim dynamicButton As Button
        dynamicButton = New Windows.Forms.Button
        dynamicButton.Location = New System.Drawing.Point(144, 32)
        dynamicButton.Size = New System.Drawing.Size(99, 23)
        dynamicButton.Text = "Get Time"
        dynamicButton.UseVisualStyleBackColor = True
        dynamicButton.TabIndex = 1
        Me.Controls.Add(dynamicButton)
        " ----- Connect the button to an event handler.
        AddHandler dynamicButton.Click, AddressOf ShowTheTime
    End Sub
End Class

<Global.Microsoft.VisualBasic.rupilerServices.DesignerGenerated()> _
Partial Class Form1
    Inherits System.Windows.Forms.Form
    <System.Diagnostics.DebuggerStepThrough()> _
    Private Sub InitializeComponent()
        Me.SuspendLayout()
        Me.ClientSize = New System.Drawing.Size(260, 76)
        Me.Text = "Dynamic Controls"
        Me.ResumeLayout(False)
    End Sub
End Class