home *** CD-ROM | disk | FTP | other *** search
- '************************************************
- ' File: Form1.vb (21-Aug-2002)
- ' Author: G. Born www.borncity.de
- '
- ' Class with Main Sub and a Form classe,
- ' Creates a form with buttons, events etc.
- '
- ' Compile with:
- ' vbc <name>.vbs /t:winexe /Win32Icon:<name>.ico
- ' /r:system.dll /r:system.windows.forms.dll
- ' /r:system.drawing.dll
- '************************************************
- Option Strict
-
- Imports Microsoft.VisualBasic ' for vbCrLf
- Imports System.Windows.Forms ' for Forms
- Imports System.Drawing
- Imports System
-
- Public Class Test ' the main clss
- Shared Sub Main()
- On Error Goto ErrHandler ' Error handler
-
- Dim MyForm As Form = New Form1() ' new Form
-
- With myForm ' Invoke Form
- .Text="My first Form"
- .ShowDialog() ' show Dialog
- .Dispose() ' destroy form object
- End With
-
- Exit Sub ' End
-
- ' Error Exit
- ErrHandler:
- MessageBox.Show ("Error " & Err.Number & vbCrLf & _
- err.Description)
- End Sub
- End Class
-
- Public Class Form1
- Inherits System.Windows.Forms.Form
-
- Friend WithEvents Button1 As System.Windows.Forms.Button
- Friend WithEvents Label1 As System.Windows.Forms.Label
- Friend WithEvents TextBox1 As System.Windows.Forms.TextBox
-
- Public Sub New()
- MyBase.New()
-
- With Me
- .Button1 = New System.Windows.Forms.Button()
- .Label1 = New System.Windows.Forms.Label()
- .TextBox1 = New System.Windows.Forms.TextBox()
-
- ' Button1
- .Button1.Location = New System.Drawing.Point(96, 56)
- .Button1.Name = "Button1"
- .Button1.Size = New System.Drawing.Size(88, 32)
- .Button1.TabIndex = 0
- .Button1.Text = "OK"
-
- ' Label1
- .Label1.Location = New System.Drawing.Point(8, 16)
- .Label1.Name = "Label1"
- .Label1.Size = New System.Drawing.Size(56, 23)
- .Label1.TabIndex = 1
- .Label1.Text = "Label1"
-
- ' TextBox1
- .TextBox1.Location = New System.Drawing.Point(72, 16)
- .TextBox1.Name = "TextBox1"
- .TextBox1.Size = New System.Drawing.Size(192, 20)
- .TextBox1.TabIndex = 2
- .TextBox1.Text = "TextBox1"
-
- 'Form2
- .AutoScaleBaseSize = New System.Drawing.Size(5, 13)
- .ClientSize = New System.Drawing.Size(280, 133)
- .Controls.AddRange(New System.Windows.Forms.Control() _
- {Me.TextBox1, Me.Label1, Me.Button1})
- .Name = "Form1"
- .Text = "MyForm"
- End With
- End Sub ' End constructor
-
- ' Event handling for button
- Private Sub Button1_Click(ByVal sender As System.Object, _
- ByVal e As System.EventArgs) Handles Button1.Click
- MessageBox.Show ("Text: " & TextBox1.Text)
- Me.Close() ' close Form
- End Sub
- End Class