Bonjour à tous,

Je vous sollicite à nouveau pour avoir un petit coup de pouce sur la mutualisation des actions sur des Richtextbox ...

1) Pour restructurer mes RichTextBox, je fais ceci :

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
Private Sub RichTextBox59_ContentResized(sender As Object, e As ContentsResizedEventArgs) Handles RichTextBox59.ContentsResized
RichTextBox59.Height = e.NewRectangle.Height + 12
End Sub
Au lieu de réécrire cela pour X RichtextBox, il y a t-il un moyen de le faire appliquer à une liste précise de RichTextBox ?

2) Pour chaque RichTextBox, j'ai ajouté un menu contextuel pour pouvoir changer la taille caractère, couleur, etc ... d'une partie du texte sélectionnée. Pour l'instant j'ajoute le menu ainsi :

Code : Sélectionner tout - Visualiser dans une fenêtre à part
RichTextBox59.ContextMenuStrip = ContextMenuStripFormat
Là aussi je cherche la méthode pour l'appliquer à mes différentes RichTextBox ...

3) Mon menu contextuel permet d'ouvrir la fenêtre "FontDialog" ou "ColorDialog" . Là aussi pour l'instant c'est écrit en "dur" pour un seul RichTextBox du style :

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
RichTextBox59.SelectionFont = ....
RichTextBox59.SelectionColor = ....
Là aussi je cherche le moyen de remplacer RichTextBox59 par un mot générique qui correspond au RichTextBox ou j'ai sélectionné le texte

4) Un dernier soucis est lorsque le FontDialog s'ouvre ou ColorDialog sur un texte sélectionné, il ne tient pas compte du format actuel : C'est à dire que si mon texte était en gras et en rouge, lorsque le FontDialog s'ouvre, il s'ouvre avec des paramètres par défaut ...

Voici le code concernant l'ouverture du menu contextuel :
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
Public Sub ToolStripItemsClicked_Click(sender As Object, e As EventArgs)
        Dim RTBSelStart As Integer = 0
        If DirectCast(sender, ToolStripMenuItem).Name = "ToolStripMenuItemFormat" Then
            Using FD As New FontDialog
                With FD
                    .AllowScriptChange = True
                    .FixedPitchOnly = False
                    .ShowColor = True
                    .ShowEffects = True
                    .AllowVectorFonts = True
                    .AllowVerticalFonts = True
                End With
                If RichTextBox59.SelectionLength > 0 Then
                    RTBSelStart = RichTextBox59.SelectionStart
                    If FD.ShowDialog = Windows.Forms.DialogResult.OK Then
                        RichTextBox59.SelectionFont = FD.Font
                        RichTextBox59.SelectionColor = FD.Color
                        RichTextBox59.SelectionStart = RTBSelStart
                        RichTextBox59.SelectionLength = 0
                    End If
                End If
            End Using
        ElseIf DirectCast(sender, ToolStripMenuItem).Name = "ToolStripMenuItemFond" Then
            Using CD As New ColorDialog
                With CD
                    .AllowFullOpen = True
                    .AnyColor = True
                    .FullOpen = True
                End With
                If RichTextBox59.SelectionLength > 0 Then
                    RTBSelStart = RichTextBox59.SelectionStart
                    If CD.ShowDialog = Windows.Forms.DialogResult.OK Then
                        RichTextBox59.SelectionBackColor = CD.Color
                        RichTextBox59.SelectionStart = RTBSelStart
                        RichTextBox59.SelectionLength = 0
                    End If
                End If
            End Using
        End If
    End Sub
Merci pour vos futures suggestions ...