![]() |
Tipp 0121
|
Formszugriff mit überladenem Konstruktor
|
 |
|
Autor/Einsender: Datum: |
|
Klaus D. Raudszus 31.05.2006 |
|
Entwicklungsumgebung: |
|
VB.Net 2003 |
Framework: |
|
1.1 |
|
|
Überladener Konstruktor der Parent-Form bedeutet, dass nicht nur einzelne Elemente oder Gruppen in der Basisklasse überschattet werden,
sondern die ganze Klasse. Somit hat man Zugriff auf alle Eigenschaften und in diesem Fall auf die Controls der Formklasse.
|
Die Verweise auf die Formen sind als Private deklariert, um zu vermeiden, dass sie nicht nochmals gegenseitig aufgerufen werden können.
|
|
Code im Codebereich der Form frmParent |
|
|
Private WithEvents fSub As frmSub
Private Sub btnInstanzFrmSub_Click(ByVal sender As Object, _
ByVal e As EventArgs) Handles btnInstanzFrmSub.Click
If fSub Is Nothing Then
fSub = New frmSub
fSub.ParentForm = Me
fSub.Show()
Me.btnTextTofrmSub.Enabled = True
Else
MessageBox.Show("frmSub ist bereits instanziert!", _
Nothing, MessageBoxButtons.OK, _
MessageBoxIcon.Information, _
MessageBoxDefaultButton.Button1)
End If
End Sub
Private Sub btnTextTofrmSub_Click(ByVal sender As Object, _
ByVal e As EventArgs) Handles btnTextTofrmSub.Click
fSub.txtBoxfrmSub.Text = Me.txtBoxfrmParent.Text
End Sub
Private Sub fSub_Closed(ByVal sender As Object, _
ByVal e As EventArgs) Handles fSub.Closed
fSub = Nothing
End Sub
|
|
|
Code im Codebereich der Form frmSub |
|
|
Private boolHide As Boolean = False
Private pForm As frmParent
Shadows Property ParentForm() As frmParent
Get
Return pForm
End Get
Set(ByVal Value As frmParent)
pForm = Value
End Set
End Property
Private Sub frmSub_Location(ByVal sender As Object, _
ByVal e As EventArgs)
Dim intLocPointX As Integer = _
CInt(Screen.PrimaryScreen.WorkingArea.Width / 2)
Dim intLocPointY As Integer = _
CInt(Screen.PrimaryScreen.WorkingArea.Height / 2) - _
CInt(Me.Height / 2)
Me.Location = New Point(intLocPointX, intLocPointY)
End Sub
Private Sub btnAccess_Click(ByVal sender As Object, _
ByVal e As EventArgs) Handles btnAccess.Click
pForm.txtBoxfrmParent.Text = ""
End Sub
Private Sub txtBoxfrmSub_TextChanged(ByVal sender As Object, _
ByVal e As EventArgs) Handles txtBoxfrmSub.TextChanged
pForm.txtBoxfrmParent.Text = Me.txtBoxfrmSub.Text
End Sub
Private Sub btnHideShowfrmParent_Click(ByVal sender As Object, _
ByVal e As EventArgs) Handles btnHideShowfrmParent.Click
If boolHide Then
pForm.Show()
Me.btnHideShowfrmParent.Text = "ParentForm Hide"
boolHide = False
Else
pForm.Hide()
Me.btnHideShowfrmParent.Text = "ParentForm Show"
boolHide = True
End If
End Sub
Private Sub btnBeenden_Click(ByVal sender As Object, _
ByVal e As EventArgs) Handles btnBeenden.Click
pForm.Close()
End Sub
Private Sub btnMeClose_Click(ByVal sender As Object, _
ByVal e As EventArgs) Handles btnMeClose.Click
pForm.Show()
pForm.btnTextTofrmSub.Enabled = False
Me.Close()
End Sub
|
|
|
|
|
Windows-Version |
98/SE |
 |
|
ME |
 |
|
NT |
 |
|
2000 |
 |
|
XP |
 |
|
Vista |
 |
|
Win
7 |
 |
|
|
|
Download (10,5 kB)
|
Downloads bisher: [ 386 ]
|
|
|