Bonjour mes amis.
J'ai besoin de votre aide pour résoudre un problème de débutant.
J'ai créé 3 fenêtres Form1,Form2 et Form3, qui contiennent tous 3 textBox: txtMatricule, txtNom et txtPrenom.
Form1 contient en plus 2 boutons: btnForm2 et btnForm3.
Le but est d'avoir au niveau de Form2 les mêmes informations que Form1 quand je clique su btnForm2. De même pour Form3.
J'ai écris ce code qui marche:
Je vois que je me répète:
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 Public Class Form1 Private Sub btnForm2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnForm2.Click Dim f As New Form2 f.txtMatricule.Text = Me.txtMatricule.Text f.txtNom.Text = Me.txtNom.Text f.txtPrenom.Text = Me.txtPrenom.Text f.ShowDialog() End Sub Private Sub btnForm3_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnForm3.Click Dim f As New Form3 f.txtMatricule.Text = Me.txtMatricule.Text f.txtNom.Text = Me.txtNom.Text f.txtPrenom.Text = Me.txtPrenom.Text f.ShowDialog() End Sub End Class
J'ai pensé donc à créer une fonction. J'ai essayé:
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4 f.txtMatricule.Text = Me.txtMatricule.Text f.txtNom.Text = Me.txtNom.Text f.txtPrenom.Text = Me.txtPrenom.Text f.ShowDialog()
aussi:
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6 Public Sub afficher(ByVal f As form) f.txtMatricule.Text = Me.txtMatricule.Text f.txtNom.Text = Me.txtNom.Text f.txtPrenom.Text = Me.txtPrenom.Text f.ShowDialog() End Sub
Rien ne marche. J'attends une idée de votre part.
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6 Public Sub afficher(ByVal f As System.Windows.Forms.Form) f.txtMatricule.Text = Me.txtMatricule.Text f.txtNom.Text = Me.txtNom.Text f.txtPrenom.Text = Me.txtPrenom.Text f.ShowDialog() End Sub
Merci à vous
Partager