home *** CD-ROM | disk | FTP | other *** search
/ PC Professionell 2003 January / PCpro_2003_01.ISO / born / Beisp / Formular.vb < prev    next >
Encoding:
Text File  |  2002-10-15  |  3.5 KB  |  115 lines

  1. '************************************************
  2. ' File:  Formular.vb 
  3. ' Autor: G. Born www.borncity.de
  4. '
  5. ' Erzeugt ein Formular mit einem Textfeld und
  6. ' zwei SchaltflΣchen. 
  7. ' Beim ▄bersetzen die Bibliotheken system.dll,
  8. ' system.windows.forms.dll und system.drawing.dll
  9. ' referenzieren! 
  10. '************************************************
  11. Option Strict
  12. Imports System.Drawing
  13. Imports System.Windows.Forms
  14.  
  15. Class Test
  16.  Shared Eingabe As String         ' Eingabespeicher
  17.  
  18.  Shared Sub Main() 
  19.   Dim oForm As New Formular()     ' Formular anlegen
  20.  
  21.     oForm.Text = " Einfaches .NET-Formular"
  22.     oForm.ShowDialog()        ' als modalen Dialog anzeigen
  23. ' Rⁿckgabecode, Variable Eingabe und Formularwert anzeigen
  24.     MessageBox.Show ("Rⁿckgabecode " & oForm.DialogResult & _
  25.                      " Eingabe: " & Eingabe & " Ergebnis: " & _
  26.                      oForm.T1.Text, "Benutzereingabe")
  27.     oForm.Dispose()
  28.  End Sub
  29.  
  30.  
  31.  Class Formular                  ' Formularklasse 
  32.   Inherits System.Windows.Forms.Form ' wir erben
  33.  
  34.   Const H1 As Integer = 24        ' H÷he Elemente
  35.   Const y1 As Integer = 30        ' erste Zeile
  36.   Const y2 As Integer = 80        ' zweite Zeile
  37.   Const x1 As Integer = 20        ' erste Spalte
  38.  
  39. ' SchaltflΣchen so anlegen, dass Ereignisse m÷glich sind
  40.   Friend WithEvents b1 As New Button()         
  41.   Friend WithEvents b2 As New Button()
  42.  
  43.   Dim l1 As New Label()           ' Labeltext
  44.   Public Dim t1 As New TextBox()  ' Textfeld
  45.  
  46.   Sub New()    ' New-Construktor zum Anlegen des Formulars
  47.    MyBase.New()                   ' Formularobjekt aus Klasse
  48.    With Me
  49.    .Name = "Form1"
  50.    .Text = " Benutzername"        ' Titeltext
  51.    .Width = 300                   ' Abmessungen 
  52.    .Height = 150
  53.    .Left = 100                    ' Position
  54.    .Top = 200  
  55.  
  56. ' Σu▀ere Gestaltung
  57.    .FormBorderStyle = FormBorderStyle.FixedDialog
  58.    .MaximizeBox = False           ' SchaltflΣchen aus
  59.    .MinimizeBox = False
  60.   End With
  61.  
  62. ' Label definieren
  63.    With l1 
  64.     .Text = "Name"
  65.     .Name = "L1"
  66.     .Size = New Size (80, H1)      ' Gr÷▀e
  67.     .Location = New Point(X1, Y1)  ' Position
  68.    End With
  69.  
  70. ' Textfeld definieren
  71.    With T1 
  72.     .Text = "Born"
  73.     .Name = "T1"
  74.     .Size = New Size (156, H1)     ' Gr÷▀e
  75.     .Location = New Point(l1.Left + l1.Width + 20, Y1)
  76.    End With
  77.  
  78. ' SchaltflΣche1 definieren
  79.    With B1 
  80.     .Text = "OK"
  81.     .Name = "B1"
  82.     .DialogResult = DialogResult.OK ' Rⁿckgabecode  
  83.     .Size = New Size (80, H1)       ' Gr÷▀e
  84.     .Location = New Point(X1 + 50, Y2)
  85.    End With
  86.  
  87. ' SchaltflΣche2 definieren
  88.    With B2 
  89.     .Text = "Schlie▀en"
  90.     .Name = "B2"
  91.     .DialogResult = DialogResult.Cancel 
  92.     .Size = New Size (80, H1)       ' Gr÷▀e
  93.     .Location = New Point(B1.Left + B1.Width +20, Y2)
  94.    End With
  95.  
  96.    With Me       ' Steuerelemente zum Formular hinzufⁿgen
  97.     .Controls.Add(L1)              ' Label
  98.     .Controls.Add(T1)              ' Textfeld
  99.     .Controls.Add(B1)              ' SchaltflΣche 1
  100.     .Controls.Add(B2)              ' SchaltflΣche 2
  101.    End With
  102.   End Sub
  103.  
  104. ' Ereignisbehandlungsroutinen 
  105.   Private Sub OK_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles B1.Click
  106.    Eingabe = Me.T1.Text             ' Ergebnis sichern
  107.    Me.Close                         ' Formular schlie▀en 
  108.   End Sub
  109.  
  110.   Private Sub Cancel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles B2.Click
  111.    Eingabe = "abgebrochen"          ' Abgebrochen
  112.    Me.Close                         ' Formular schlie▀en 
  113.   End Sub
  114.  End Class
  115. End Class