Hallo!
Benenne Formulare nach ihrer Funktion - hier z.B. frmSettingsDialog
Public Class frmSettingsDialog
'Membervariable
Private Property _TB_Tabindex As Integer
'Per Code erstellte Controls
Private WithEvents txtTabindex As New TextBox _
With {.Parent = Me, .Top = 10, .Left = 10, .Width = 100}
Private WithEvents btnOk As New Button With _
{.Parent = Me, .Top = 40, .Left = 10, .Text = "OK", _
.DialogResult = DialogResult.OK}
Private WithEvents btnCancel As New Button With _
{.Parent = Me, .Top = 40, .Left = 100, .Text = "Cancel", _
.DialogResult = DialogResult.Cancel}
'Eigenschaft für Tabindex
Public Property TB_Tabindex As Integer
Set(ByVal value As Integer)
_TB_Tabindex = value
txtTabindex.Text = CStr(value)
End Set
Get
Return _TB_Tabindex
End Get
End Property
'Schließen des Formulars durch den User verhindern
Private Sub frmSettingsDialog_FormClosing(ByVal sender As Object, _
ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles _
Me.FormClosing
If e.CloseReason = CloseReason.UserClosing Then
Me.Hide()
e.Cancel = True
End If
End Sub
'Eingabe kontrollieren
Private Sub txtTabindex_TextChanged(ByVal sender As Object, _
ByVal e As System.EventArgs) Handles txtTabindex.TextChanged
If txtTabindex.Text <> String.Empty Then
Dim index As Integer
If Not Integer.TryParse(txtTabindex.Text.Trim, index) OrElse index _
< 0 Then
MsgBox("Unzulässige Eingabe")
Else
_TB_Tabindex = index
End If
End If
End Sub
End Class Verwendung des Dialogs:
Public Class frmUser
Dim mySettingsDialog As New frmSettingsDialog With _
{.Owner = Me, .Visible = False}
Dim WithEvents btnSettingsDialog As New Button With _
{.Parent = Me, .Top = 10, .Left = 10, .Width = 100, .Text = "Settings"}
Dim txtDemo As New TextBox With _
{.Parent = Me, .Top = 40, .Left = 10, .Width = 300}
Private Sub btnSettingsDialog_Click(ByVal sender As Object, _
ByVal e As System.EventArgs) Handles btnSettingsDialog.Click
With mySettingsDialog
.TB_Tabindex = txtDemo.TabIndex
If .ShowDialog = DialogResult.OK Then
txtDemo.TabIndex = .TB_Tabindex
End If
End With
End Sub
End Class |