Exercice VB: Interface MS Word

Ecrire le programme qui permet de réaliser l'interface suivante:
ExerciceVB-id2082


 

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
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
Imports System.IO
 
Public Class Form1
    Public lblrs As Label
    Private Sub NouveauToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles NouveauToolStripMenuItem.Click
 
    End Sub
 
    Private Sub OuvrirToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles OuvrirToolStripMenuItem.Click
        'Dim opendlg As New OpenFileDialog
        'With opendlg
        '    .InitialDirectory = IO.Directory.GetCurrentDirectory
        '    If .ShowDialog() = DialogResult.OK Then
        '        lblrs.Text = "filename = " & .FileName
        '    Else
        '        lblrs.Text = "annulé"
        '    End If
        'End With
        If OpenFileDialog1.ShowDialog = Windows.Forms.DialogResult.OK Then
            Dim nomfichier As String = OpenFileDialog1.FileName
            Dim str As StreamReader = New StreamReader(nomfichier)
            RichTextBox1.Text = str.ReadToEnd
            str.Close()
        End If
    End Sub
 
    Private Sub FermerToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles FermerToolStripMenuItem.Click
        End
    End Sub
 
    Private Sub EnregestrerToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles EnregestrerToolStripMenuItem.Click
        FileOpen(1, "stagiaire.txt", OpenMode.Random, OpenAccess.Write, Len(RichTextBox1))
    End Sub
 
    Private Sub EnregestrerSousToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles EnregestrerSousToolStripMenuItem.Click
        SaveFileDialog1.InitialDirectory = Application.ExecutablePath
        SaveFileDialog1.Filter = "Enregestrer Sous (*.doc)|*.doc|All files (*.*)|*.*"
        SaveFileDialog1.FilterIndex = 0
 
        If SaveFileDialog1.ShowDialog() = DialogResult.OK Then
            Dim nomFichier As String = SaveFileDialog1.FileName
            Dim fichier As StreamWriter = Nothing
            Try
                fichier = New StreamWriter(nomFichier)
 
            Catch ex As Exception
                MessageBox.Show("Problème à l'écriture du fichier (" + ex.Message + ")", "Erreur", MessageBoxButtons.OK, MessageBoxIcon.Error)
                Return
            Finally
                Try
                    fichier.Close()
                Catch
                End Try
            End Try
        End If
 
    End Sub
 
    Private Sub ToolStripButton5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ToolStripButton5.Click
        If ColorDialog1.ShowDialog() = Windows.Forms.DialogResult.OK Then    ' choix d'une couleur de texte
            RichTextBox1.ForeColor = ColorDialog1.Color ' on change la propriété forecolor du TextBox
        End If
    End Sub
 
    Private Sub ToolStripButton11_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ToolStripButton11.Click
        If FontDialog1.ShowDialog() = Windows.Forms.DialogResult.OK Then
            RichTextBox1.Font = FontDialog1.Font
        End If
    End Sub
 
    Private Sub MiseEnPageToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MiseEnPageToolStripMenuItem.Click
        Dim pagedlg As New PageSetupDialog
        With pagedlg
            Dim pd As New Drawing.Printing.PrintDocument()
            .Document = pd
            If .ShowDialog = DialogResult.OK Then
                With .PageSettings.PaperSize
                    lblrs.Text = String.Format("papier : {0] * {1]", .Width, .Height)
                End With
                With .PageSettings.Margins
                    lblrs.Text += String.Format("-marges {0],{1],{2],{3]", .Left, .Top, .Right, .Bottom)
                End With
            Else
                lblrs.Text = "annulé"
            End If
        End With
 
 
 
    End Sub
 
    Private Sub CouperToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CouperToolStripMenuItem.Click
        RichTextBox1.Cut()
    End Sub
 
    Private Sub CopierToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CopierToolStripMenuItem.Click
        RichTextBox1.Copy()
    End Sub
 
    Private Sub CollerToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CollerToolStripMenuItem.Click
        RichTextBox1.Paste()
    End Sub
 
    Private Sub SelectionnerToutToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles SelectionnerToutToolStripMenuItem.Click
        RichTextBox1.SelectAll()
    End Sub
 
    Private Sub EffacerToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles EffacerToolStripMenuItem.Click
        RichTextBox1.Clear()
    End Sub
 
    'Private Sub RechercherToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RechercherToolStripMenuItem.Click
    '    Dim dlgrecherche As New DialogResult
    '    Dim i As Integer = RichTextBox1.Text.IndexOf(Text, RichTextBox1.selectionstatr + RichTextBox1.selectionlenght)
    'End Sub
 
    Private Sub ImprimerToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ImprimerToolStripMenuItem.Click
        Dim printdlg As New PrintDialog
        With printdlg
            Dim pd As New Drawing.Printing.PrintDocument()
            .Document = pd
            .AllowSelection = True
            .AllowSomePages = True
            pd.PrinterSettings.MaximumPage = 5
            If .ShowDialog = DialogResult.OK Then
                With pd.PrinterSettings
                    lblrs.Text = String.Format("imprimante : {0]-copier : {1] - page : {2] -{3]", .PrinterName, .Copies, .FromPage, .ToPage)
                End With
            Else
                lblrs.Text = "annuler"
            End If
 
        End With
    End Sub
 
    Private Sub PoliceToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PoliceToolStripMenuItem.Click
        If FontDialog1.ShowDialog() = Windows.Forms.DialogResult.OK Then
            RichTextBox1.Font = FontDialog1.Font
        End If
    End Sub
 
    Private Sub ToolStripButton2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ToolStripButton2.Click
        Dim opendlg As New OpenFileDialog
        With opendlg
            .InitialDirectory = IO.Directory.GetCurrentDirectory
            If .ShowDialog() = DialogResult.OK Then
                lblrs.Text = "filename = " & .FileName
            Else
                lblrs.Text = "annulé"
            End If
        End With
    End Sub
 
    Private Sub ToolStripButton4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ToolStripButton4.Click
        Dim printdlg As New PrintDialog
        With printdlg
            Dim pd As New Drawing.Printing.PrintDocument()
            .Document = pd
            .AllowSelection = True
            .AllowSomePages = True
            pd.PrinterSettings.MaximumPage = 5
            If .ShowDialog = DialogResult.OK Then
                With pd.PrinterSettings
                    lblrs.Text = String.Format("imprimante : {0]-copier : {1] - page : {2] -{3]", .PrinterName, .Copies, .FromPage, .ToPage)
                End With
            Else
                lblrs.Text = "annuler"
            End If
 
        End With
    End Sub
 
    Private Sub ToolStripButton8_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ToolStripButton8.Click
        RichTextBox1.Cut()
    End Sub
 
    Private Sub ToolStripButton9_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ToolStripButton9.Click
        RichTextBox1.Copy()
    End Sub
 
    Private Sub ToolStripButton10_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ToolStripButton10.Click
        RichTextBox1.Paste()
    End Sub
 
    Private Sub ToolStripButton12_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ToolStripButton12.Click
        RichTextBox1.Undo()
    End Sub
 
    Private Sub ToolStripButton13_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ToolStripButton13.Click
        RichTextBox1.Update()
    End Sub
 
    Private Sub ToolStripButton14_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles button14.Click
        Try
            Dim nouveaustyle As FontStyle = RichTextBox1.SelectionFont.Style
            If sender.button14.pushed Then
                nouveaustyle = nouveaustyle Or FontStyle.Bold
            Else
                nouveaustyle = nouveaustyle And Not FontStyle.Bold
            End If
            RichTextBox1.SelectionFont = New Font(RichTextBox1.SelectionFont, nouveaustyle)
 
        Catch ex As Exception
            'button14.pushed = RichTextBox1.SelectionFont.Bold
        End Try
    End Sub
 
    Private Sub ToolStripComboBox1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ToolStripComboBox1.Click
        Dim t As Integer
        Dim fnt As New Font("arial", 20, FontStyle.Bold)
        sender.richtextbox1.drawstring(fnt.Style.ToString, fnt, Brushes.Blue, 10, t)
    End Sub
 
    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        ToolStripComboBox1.Items.Add("Arial")
    End Sub
End Class