1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113
|
'Fenetre MDI
'un composant MainMenu boite à outils
'item Fichier
'2 sous items Nouveau et Fermer
'item Fenetres
'2 sous items Cascade et Horizontal
Public Class frmMDI
'cree un nouveau enfant Form1
Private Sub MenuItemNouveau_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MenuItemNouveau.Click
Dim NouvEnfantMDI As New Form1()
'Definit la Forme parente de la Forme Enfant.
NouvEnfantMDI.MdiParent = Me
'Affiche la Forme Enfant
NouvEnfantMDI.Show()
End Sub
'Ferme l'enfant actif
'Il faut ajouter un focus pour attirer la "vue" de l'user
'et un message d'avertissement
Private Sub MenuItemFermer_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MenuItemFermer.Click
' recherche l'enfant actif.
Dim actifEnfant As Form = Me.ActiveMdiChild
Dim reponse As MsgBoxResult
If (Not actifEnfant Is Nothing) Then
actifEnfant.Focus()
reponse = MsgBox("vous-vous fermer la fenetre :" & actifEnfant.Text, MsgBoxStyle.OkCancel)
If reponse = MsgBoxResult.Ok Then
actifEnfant.Close()
End If
End If
End Sub
Private Sub MenuItemFenCascade_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MenuItemFenCascade.Click
Me.LayoutMdi(System.Windows.Forms.MdiLayout.Cascade)
End Sub
Private Sub MenuItemFenHorizontal_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MenuItemFenHorizontal.Click
Me.LayoutMdi(System.Windows.Forms.MdiLayout.TileHorizontal)
End Sub
End Class
'Form1 ouvre simplement Form2
Public Class Form1
Private Sub btnAfficheForme2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAfficheForme2.Click
Dim NouvEnfantMDI As New Form2()
'Definit la Forme parente de la Forme Enfant Form2.
NouvEnfantMDI.MdiParent = frmMDI
'Affiche la Forme Enfant Form2
NouvEnfantMDI.Show()
End Sub
End Class
'Form2 plus complique
'Form2 peut afficher Form1
'Form2 peut fermer Form1 s'il est afficher
'
Public Class Form2
Private Sub btnFermeForme1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnFermeForme1.Click
' recherche form1 et le ferme s'il est ouvert
Dim boolTrouve As Boolean = False
For I As Integer = 0 To (frmMDI.MdiChildren.Length) - 1
If frmMDI.MdiChildren(I).Name = Form1.Name Then
boolTrouve = True
Dim reponse As MsgBoxResult
reponse = MsgBox("vous-vous fermer la fenetre :" & frmMDI.MdiChildren(I).Text, MsgBoxStyle.OkCancel)
If reponse = MsgBoxResult.Ok Then
frmMDI.MdiChildren(I).Close()
Exit For
End If
End If
Next
If Not boolTrouve Then
MessageBox.Show("pas de Fenetre Form1 ouverte...")
End If
End Sub
Private Sub btnAfficheForme1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAfficheForme1.Click
'Rcherche Form1 et l'affiche s'il n'est pas deja affiche
Dim boolTrouve As Boolean = False
Dim formeTrouve As Form = Nothing
For I As Integer = 0 To (frmMDI.MdiChildren.Length) - 1
If frmMDI.MdiChildren(I).Name = Form1.Name Then
boolTrouve = True
formeTrouve = frmMDI.MdiChildren(I)
Exit For
End If
Next
If boolTrouve Then
If Not formeTrouve.Visible Then
Dim reponse As MsgBoxResult
reponse = MsgBox("Afficher Fenetre :" & formeTrouve.Text, MsgBoxStyle.OkCancel)
If reponse = MsgBoxResult.Ok Then
formeTrouve.Show()
End If
Else
MessageBox.Show("Fenetre :" & formeTrouve.Text & " est deja affiche...")
End If
Else
Dim reponse As MsgBoxResult
reponse = MsgBox("Form1 n'est pas affiché. Vous-vous l'afficher", MsgBoxStyle.OkCancel)
If reponse = MsgBoxResult.Ok Then
Dim NouvEnfantMDI As New Form1()
'Definit la Forme parente de la Forme Enfant Form1.
NouvEnfantMDI.MdiParent = frmMDI
'Affiche la Forme Enfant Form1
NouvEnfantMDI.Show()
End If
End If
End Sub
End Class |
Partager