home *** CD-ROM | disk | FTP | other *** search
/ PC Professionell 2003 January / PCpro_2003_01.ISO / born / IDE / DotNET-IDE / Templates / Form1.vb < prev    next >
Encoding:
Text File  |  2002-08-21  |  2.6 KB  |  93 lines

  1. '************************************************
  2. ' File:  Form1.vb  (21-Aug-2002)
  3. ' Author: G. Born www.borncity.de
  4. '
  5. ' Class with Main Sub and a Form classe, 
  6. ' Creates a form with buttons, events etc.
  7. '
  8. ' Compile with:
  9. ' vbc <name>.vbs /t:winexe /Win32Icon:<name>.ico
  10. ' /r:system.dll /r:system.windows.forms.dll 
  11. ' /r:system.drawing.dll
  12. '************************************************
  13. Option Strict
  14.  
  15. Imports Microsoft.VisualBasic      ' for vbCrLf
  16. Imports System.Windows.Forms       ' for Forms
  17. Imports System.Drawing
  18. Imports System
  19.  
  20. Public Class Test                   ' the main clss
  21.  Shared Sub Main()
  22.   On Error Goto ErrHandler          ' Error handler
  23.  
  24.   Dim MyForm As Form = New Form1()   ' new Form
  25.  
  26.   With myForm         ' Invoke Form
  27.    .Text="My first Form"
  28.    .ShowDialog()                     ' show Dialog
  29.    .Dispose()                        ' destroy form object
  30.   End With
  31.  
  32.   Exit Sub                           ' End
  33.  
  34. ' Error Exit
  35. ErrHandler:   
  36.   MessageBox.Show ("Error " & Err.Number & vbCrLf & _
  37.                     err.Description)
  38.  End Sub
  39. End Class
  40.  
  41. Public Class Form1
  42.  Inherits System.Windows.Forms.Form
  43.  
  44.  Friend WithEvents Button1 As System.Windows.Forms.Button
  45.  Friend WithEvents Label1 As System.Windows.Forms.Label
  46.  Friend WithEvents TextBox1 As System.Windows.Forms.TextBox
  47.  
  48.  Public Sub New()
  49.   MyBase.New()
  50.  
  51.  With Me
  52.   .Button1 = New System.Windows.Forms.Button()
  53.   .Label1 = New System.Windows.Forms.Label()
  54.   .TextBox1 = New System.Windows.Forms.TextBox()
  55.  
  56. ' Button1
  57.   .Button1.Location = New System.Drawing.Point(96, 56)
  58.   .Button1.Name = "Button1"
  59.   .Button1.Size = New System.Drawing.Size(88, 32)
  60.   .Button1.TabIndex = 0
  61.   .Button1.Text = "OK"
  62.  
  63. ' Label1
  64.   .Label1.Location = New System.Drawing.Point(8, 16)
  65.   .Label1.Name = "Label1"
  66.   .Label1.Size = New System.Drawing.Size(56, 23)
  67.   .Label1.TabIndex = 1
  68.   .Label1.Text = "Label1"
  69.  
  70. ' TextBox1
  71.   .TextBox1.Location = New System.Drawing.Point(72, 16)
  72.   .TextBox1.Name = "TextBox1"
  73.   .TextBox1.Size = New System.Drawing.Size(192, 20)
  74.   .TextBox1.TabIndex = 2
  75.   .TextBox1.Text = "TextBox1"
  76.  
  77. 'Form2
  78.   .AutoScaleBaseSize = New System.Drawing.Size(5, 13)
  79.   .ClientSize = New System.Drawing.Size(280, 133)
  80.   .Controls.AddRange(New System.Windows.Forms.Control() _
  81.                {Me.TextBox1, Me.Label1, Me.Button1})
  82.   .Name = "Form1"
  83.   .Text = "MyForm"
  84.  End With
  85. End Sub ' End constructor
  86.  
  87. ' Event handling for button
  88.  Private Sub Button1_Click(ByVal sender As System.Object, _
  89.     ByVal e As System.EventArgs) Handles Button1.Click
  90.    MessageBox.Show ("Text: " & TextBox1.Text)
  91.    Me.Close()      ' close Form
  92.  End Sub
  93. End Class