home *** CD-ROM | disk | FTP | other *** search
- '************************************************
- ' File: Formular.vb
- ' Autor: G. Born www.borncity.de
- '
- ' Erzeugt ein Formular mit einem Textfeld und
- ' zwei SchaltflΣchen.
- ' Beim ▄bersetzen die Bibliotheken system.dll,
- ' system.windows.forms.dll und system.drawing.dll
- ' referenzieren!
- '************************************************
- Option Strict
- Imports System.Drawing
- Imports System.Windows.Forms
-
- Class Test
- Shared Eingabe As String ' Eingabespeicher
-
- Shared Sub Main()
- Dim oForm As New Formular() ' Formular anlegen
-
- oForm.Text = " Einfaches .NET-Formular"
- oForm.ShowDialog() ' als modalen Dialog anzeigen
- ' Rⁿckgabecode, Variable Eingabe und Formularwert anzeigen
- MessageBox.Show ("Rⁿckgabecode " & oForm.DialogResult & _
- " Eingabe: " & Eingabe & " Ergebnis: " & _
- oForm.T1.Text, "Benutzereingabe")
- oForm.Dispose()
- End Sub
-
-
- Class Formular ' Formularklasse
- Inherits System.Windows.Forms.Form ' wir erben
-
- Const H1 As Integer = 24 ' H÷he Elemente
- Const y1 As Integer = 30 ' erste Zeile
- Const y2 As Integer = 80 ' zweite Zeile
- Const x1 As Integer = 20 ' erste Spalte
-
- ' SchaltflΣchen so anlegen, dass Ereignisse m÷glich sind
- Friend WithEvents b1 As New Button()
- Friend WithEvents b2 As New Button()
-
- Dim l1 As New Label() ' Labeltext
- Public Dim t1 As New TextBox() ' Textfeld
-
- Sub New() ' New-Construktor zum Anlegen des Formulars
- MyBase.New() ' Formularobjekt aus Klasse
- With Me
- .Name = "Form1"
- .Text = " Benutzername" ' Titeltext
- .Width = 300 ' Abmessungen
- .Height = 150
- .Left = 100 ' Position
- .Top = 200
-
- ' Σu▀ere Gestaltung
- .FormBorderStyle = FormBorderStyle.FixedDialog
- .MaximizeBox = False ' SchaltflΣchen aus
- .MinimizeBox = False
- End With
-
- ' Label definieren
- With l1
- .Text = "Name"
- .Name = "L1"
- .Size = New Size (80, H1) ' Gr÷▀e
- .Location = New Point(X1, Y1) ' Position
- End With
-
- ' Textfeld definieren
- With T1
- .Text = "Born"
- .Name = "T1"
- .Size = New Size (156, H1) ' Gr÷▀e
- .Location = New Point(l1.Left + l1.Width + 20, Y1)
- End With
-
- ' SchaltflΣche1 definieren
- With B1
- .Text = "OK"
- .Name = "B1"
- .DialogResult = DialogResult.OK ' Rⁿckgabecode
- .Size = New Size (80, H1) ' Gr÷▀e
- .Location = New Point(X1 + 50, Y2)
- End With
-
- ' SchaltflΣche2 definieren
- With B2
- .Text = "Schlie▀en"
- .Name = "B2"
- .DialogResult = DialogResult.Cancel
- .Size = New Size (80, H1) ' Gr÷▀e
- .Location = New Point(B1.Left + B1.Width +20, Y2)
- End With
-
- With Me ' Steuerelemente zum Formular hinzufⁿgen
- .Controls.Add(L1) ' Label
- .Controls.Add(T1) ' Textfeld
- .Controls.Add(B1) ' SchaltflΣche 1
- .Controls.Add(B2) ' SchaltflΣche 2
- End With
- End Sub
-
- ' Ereignisbehandlungsroutinen
- Private Sub OK_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles B1.Click
- Eingabe = Me.T1.Text ' Ergebnis sichern
- Me.Close ' Formular schlie▀en
- End Sub
-
- Private Sub Cancel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles B2.Click
- Eingabe = "abgebrochen" ' Abgebrochen
- Me.Close ' Formular schlie▀en
- End Sub
- End Class
- End Class