Bonjour, dans le cadre du devellopement d'un logiciel, j'ai besoin d'onglets que l'utilisateur puisse ouvrir et fermer a volonté, un peu comme dans notepad++ ou firefox. C'est pour un editeur de texte. Dans chacun de ces onglets il y a une richtextbox ainsi qu'un bouton. J'ai donc plusieurs problèmes :

- Comment, quand j'ouvre un fichier texte, l'ouvrir dans la bonne richtextbox, celle qui correspond à l'onglet selectionné ?

- Comment mettre du code à executer pour tous les nouveaux bouton créés (à chaque fois le meme code, pour tous les boutons) ?

Un petit screen pour que vous compreniez mieux :


ainsi que le code :
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
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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
Imports System.IO
Imports mRibbon
Imports Vista_Api
 
Public Class Twinotes
    Dim nbonglet As Integer = 0
 
    Private Sub bandeau_Options_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles bandeau_Options.Click
        Me.Visible = False
        Accueil.Text = "wTwin"
    End Sub
 
    Private Sub Themebleu_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Themebleu.Click
        RibbonControl.ColorScheme = mRibbon.ColorScheme.Blue
        bandeau_Options.Invalidate()
        bandeau_Texte.Invalidate()
        Dim SW As StreamWriter
        SW = File.CreateText("C:\Program Files\wTwin\config.ini")
        SW.WriteLine("0")
        SW.Close()
    End Sub
 
    Private Sub Themegris_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Themegris.Click
        RibbonControl.ColorScheme = mRibbon.ColorScheme.Gray
        bandeau_Options.Invalidate()
        bandeau_Texte.Invalidate()
        Dim SW As StreamWriter
        SW = File.CreateText("C:\Program Files\wTwin\config.ini")
        SW.WriteLine("1")
        SW.Close()
    End Sub
 
    Private Sub Themechoix_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Themechoix.Click
        If ColorDialog1.ShowDialog() = DialogResult.OK Then
            RibbonControl.ColorScheme = mRibbon.ColorScheme.Custom
            RibbonControl.Color = ColorDialog1.Color
            bandeau_Options.Invalidate()
            bandeau_Texte.Invalidate()
            Dim SW As StreamWriter
            SW = File.CreateText("C:\Program Files\wTwin\config.ini")
            SW.WriteLine("2")
            SW.Close()
        End If
    End Sub
 
    Private Sub Nouveau_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Nouveau.Click
        Dim Tabp As New TabPage
        With Tabp
            .Text = "Nouveau" & " " & nbonglet
            .Name = "onglet" & nbonglet
        End With
        bandeau_Texte.Controls.Add(Tabp)
        Dim rtb As New RichTextBox
        With rtb
            .Size = New System.Drawing.Size(786, 412)
            .Location = New System.Drawing.Point(0, 0)
            .Name = "Textenote" & nbonglet
            .ScrollBars = System.Windows.Forms.RichTextBoxScrollBars.ForcedVertical
        End With
        Tabp.Controls.Add(rtb)
        Dim EnvoiTwin As New CommandLink
        With EnvoiTwin
            .Location = New System.Drawing.Point(558, 347)
            .Name = "EnvoiTwin" & nbonglet
            .Size = New System.Drawing.Size(205, 60)
            .Text = "Envoyer vers le Twin"
        End With
        rtb.Controls.Add(EnvoiTwin)
    End Sub
 
    Private Sub EnvoiTwin_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles EnvoiTwin.Click
        Dim texte, titre As String
        texte = Textenote.Text
        titre = Onglet1.Text
        For Each di As DriveInfo In DriveInfo.GetDrives()
            If di.IsReady Then
                If di.VolumeLabel = "MYPHONE" Then
                    If Not texte = Nothing Then
                        Dim lettre As String
                        lettre = di.Name
                        Dim SW As StreamWriter
                        SW = File.CreateText(lettre & titre & ".txt")
                        SW.WriteLine(texte$)
                        SW.Close()
                    Else : MsgBox("Vous n'avez pas renseigné tous les champs disponibles", MsgBoxStyle.Exclamation)
                    End If
                End If
            End If
        Next
    End Sub
 
    Private Sub tabremoved_Click(ByVal sender As System.Object, ByVal e As System.Windows.Forms.ControlEventArgs) Handles bandeau_Texte.ControlRemoved
        Dim i As Integer
        i = bandeau_Texte.TabCount - 2
        If i = 1 Then
            Nbonglets.Text = i & " " & "onglet ouvert"
        ElseIf i > 1 Then
            Nbonglets.Text = i & " " & "onglets ouverts"
        End If
        bandeau_Texte.SelectTab(i)
    End Sub
 
    Private Sub tabadded_Click(ByVal sender As System.Object, ByVal e As System.Windows.Forms.ControlEventArgs) Handles bandeau_Texte.ControlAdded
        Dim i As Integer
        i = bandeau_Texte.TabCount - 1
        If i = 1 Then
            Nbonglets.Text = i & " " & "onglet ouvert"
        ElseIf i > 1 Then
            Nbonglets.Text = i & " " & "onglets ouverts"
        End If
        bandeau_Texte.SelectTab(i)
        nbonglet += 1
    End Sub
 
    Private Sub Ouvrir_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Ouvrir.Click
        If Not Textenote.Text = "" Then
            Form1.Label1.Text = bandeau_Texte.SelectedTab.Text & " " & "a des modifications non enregistrées. Que voulez vous faire ?"
            Form1.ShowDialog()
        ElseIf Textenote.Text = "" Then
            OpenFileDialog1.Filter = "Texte (*.txt)|*.txt"
            If OpenFileDialog1.ShowDialog() = Windows.Forms.DialogResult.OK Then
                Dim CheminFichier As String
                CheminFichier = OpenFileDialog1.FileName
                Try
                    Dim Fichier As New System.IO.StreamReader(CheminFichier)
                    Textenote.Text = Fichier.ReadToEnd
                    Fichier.Close()
                Catch ex As System.Exception
                    MsgBox("Impossible d'ouvrir le fichier, il est peut être en cours d'utilisation", MsgBoxStyle.Critical)
                Finally
                End Try
                bandeau_Texte.SelectedTab.Text = Path.GetFileNameWithoutExtension(CheminFichier)
            End If
        End If
    End Sub
 
    Private Sub Suppronglet_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Suppronglet.Click
        If Not Textenote.Text = "" Then
            Form2.Label1.Text = bandeau_Texte.SelectedTab.Text & " " & "a des modifications non enregistrées. Que voulez vous faire ?"
            Form2.ShowDialog()
        ElseIf Textenote.Text = "" Then
            Dim i As Integer
            i = bandeau_Texte.TabCount
            If bandeau_Texte.TabCount > 2 Then
                bandeau_Texte.TabPages.RemoveAt(bandeau_Texte.SelectedIndex)
            End If
        End If
    End Sub
 
    Private Sub Annuler_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Annuler.Click
        Textenote.Undo()
    End Sub
 
    Private Sub Suivant_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Suivant.Click
        Textenote.Redo()
    End Sub
 
    Private Sub RibbonItem1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RibbonItem1.Click
        Textenote.Copy()
    End Sub
 
    Private Sub RibbonItem2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RibbonItem2.Click
        Textenote.Paste()
    End Sub
End Class
Merci de votre aide.