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 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245
| Public Class FrmMsgBox
Dim nb As Integer
Dim VerrouResize As Boolean
'Private Sub FrmMsgBox_FormClosed(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosedEventArgs) Handles Me.FormClosed
' 'On doit retirer de la mesure du temps d'éxecution le temps passé à afficher la boîte de dialogue
' QueryPerformanceCounter(MesurePerfCtr7)
' MesurePerfCtr1 -= MesurePerfCtr7 - MesurePerfCtr6
'End Sub
Private Sub FrmMsgBox_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
VerrouResize = False
End Sub
Private Sub ChangerTaille()
If VerrouResize Then Exit Sub
'Remplir ces constantes au moment de la création ou de la modification de la fenêtre -------------------------
Const WXmin As Integer = 393, WYmin As Integer = 239 'Valeurs de Me.ClientRectangle.Width et .Height
Const EcartEntreBoutons As Integer = 6
Const TailleYBouton As Integer = 23
'-------------------------------------------------------------------------------------------------------------
Dim DX As Integer, DY As Integer
Dim TXbouton As Integer, TYbouton As Integer
Dim WXmin2 As Integer
If Me.WindowState = FormWindowState.Normal Then
TXbouton = Button1.Width
TYbouton = Button1.Height
'Calcul de WXmin2 (les boutons peuvent grossir selon les paramètres d'affichage...)
WXmin2 = EcartEntreBoutons * 3 + 3 * TXbouton 'représente les espaces entre les boutons et les bords de la fenêtre
If WXmin > WXmin2 Then WXmin2 = WXmin
DX = Me.ClientRectangle.Width - WXmin2
DY = Me.ClientRectangle.Height - WYmin
VerrouResize = True
If DX < 0 Then
Me.Width -= DX
DX = 0
End If
If DY < 0 Then
Me.Height -= DY
DY = 0
End If
VerrouResize = False
TxtMessage.Width = Me.ClientRectangle.Width - EcartEntreBoutons
TxtMessage.Height = Me.ClientRectangle.Height - TailleYBouton - 2 * EcartEntreBoutons - EcartEntreBoutons \ 2
Button1.Top = TxtMessage.Height + EcartEntreBoutons + EcartEntreBoutons \ 2
If nb > 1 Then Button2.Top = Button1.Top
If nb > 2 Then Button3.Top = Button1.Top
'Delta = (Me.Width - 401) \ 2
Select Case nb
Case 1 'un seul bouton au milieu :
Button1.Left = Me.ClientRectangle.Width \ 2 - TXbouton \ 2
Case 2 'deux boutons :
Button1.Left = Me.ClientRectangle.Width \ 2 - TXbouton - EcartEntreBoutons \ 2
Button2.Left = Me.ClientRectangle.Width \ 2 + EcartEntreBoutons \ 2
Case 3 'trois boutons :
Button1.Left = Me.ClientRectangle.Width \ 2 - 3 * TXbouton \ 2 - EcartEntreBoutons
Button2.Left = Me.ClientRectangle.Width \ 2 - TXbouton \ 2
Button3.Left = Me.ClientRectangle.Width \ 2 + TXbouton \ 2 + EcartEntreBoutons
End Select
End If
End Sub
Private Sub FrmMsgBox_SizeChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.SizeChanged
ChangerTaille()
End Sub
Public Function Montrer(ByVal Message As String, Optional ByVal Buttons As MsgBoxStyle = MsgBoxStyle.OkOnly, Optional ByVal Titre As String = "") As MsgBoxResult
'MsgBox(Me.ClientRectangle.Width.ToString & " " & Me.ClientRectangle.Height.ToString)
Dim i As Integer
Dim but As System.Windows.Forms.Button
'QueryPerformanceCounter(MesurePerfCtr6)
'Nombre et type de boutons :
Select Case Buttons
Case MsgBoxStyle.OkCancel
nb = 2
Button3.DialogResult = Windows.Forms.DialogResult.None
Button1.DialogResult = Windows.Forms.DialogResult.OK
Button2.DialogResult = Windows.Forms.DialogResult.Cancel
Case MsgBoxStyle.YesNo
nb = 2
Button3.DialogResult = Windows.Forms.DialogResult.None
Button1.DialogResult = Windows.Forms.DialogResult.Yes
Button2.DialogResult = Windows.Forms.DialogResult.No
Case MsgBoxStyle.YesNoCancel
nb = 3
Button1.DialogResult = Windows.Forms.DialogResult.Yes
Button2.DialogResult = Windows.Forms.DialogResult.No
Button3.DialogResult = Windows.Forms.DialogResult.Cancel
Case Else 'OK only
nb = 1
Button3.DialogResult = Windows.Forms.DialogResult.None
Button2.DialogResult = Windows.Forms.DialogResult.None
Button1.DialogResult = Windows.Forms.DialogResult.OK
End Select
'Texte des boutons :
For i = 1 To nb
Select Case i
Case 1 : but = Button1
Case 2 : but = Button2
Case 3 : but = Button3
End Select
If Langue = TypeLangue.Anglais Then
Select Case but.DialogResult
Case Windows.Forms.DialogResult.OK : but.Text = "OK"
Case Windows.Forms.DialogResult.Cancel : but.Text = "Cancel"
Case Windows.Forms.DialogResult.Yes : but.Text = "Yes"
Case Windows.Forms.DialogResult.No : but.Text = "No"
End Select
Else
Select Case but.DialogResult
Case Windows.Forms.DialogResult.OK : but.Text = "OK"
Case Windows.Forms.DialogResult.Cancel : but.Text = "Annuler"
Case Windows.Forms.DialogResult.Yes : but.Text = "Oui"
Case Windows.Forms.DialogResult.No : but.Text = "Non"
End Select
End If
Next
Button1.Visible = nb >= 1
Button2.Visible = nb >= 2
Button3.Visible = nb >= 3
Call ChangerTaille()
'Message :
TxtMessage.Text = Message
If Titre = "" Then
Me.Text = VersionProgramme
Else
Me.Text = Titre
End If
'choix par défaut :
Select Case nb
Case 1 : but = Button1
Case 2 : but = Button2
Case 3 : but = Button3
End Select
Me.DialogResult = but.DialogResult
'Affichage :
If My.Application.OpenForms.Count > 0 Then Call CentrerFenetre(My.Application.OpenForms.Item(My.Application.OpenForms.Count - 1), Me)
Me.ShowDialog()
'Fin et résultat :
TxtMessage.Clear()
Return CType(Me.DialogResult, MsgBoxResult)
End Function
End Class
<Global.Microsoft.VisualBasic.CompilerServices.DesignerGenerated()> _
Partial Class FrmMsgBox
Inherits System.Windows.Forms.Form
'Form remplace la méthode Dispose pour nettoyer la liste des composants.
<System.Diagnostics.DebuggerNonUserCode()> _
Protected Overrides Sub Dispose(ByVal disposing As Boolean)
Try
If disposing AndAlso components IsNot Nothing Then
components.Dispose()
End If
Finally
MyBase.Dispose(disposing)
End Try
End Sub
'Requise par le Concepteur Windows Form
Private components As System.ComponentModel.IContainer
'REMARQUE*: la procédure suivante est requise par le Concepteur Windows Form
'Elle peut être modifiée à l'aide du Concepteur Windows Form.
'Ne la modifiez pas à l'aide de l'éditeur de code.
<System.Diagnostics.DebuggerStepThrough()> _
Private Sub InitializeComponent()
Me.TxtMessage = New System.Windows.Forms.TextBox()
Me.Button1 = New System.Windows.Forms.Button()
Me.Button2 = New System.Windows.Forms.Button()
Me.Button3 = New System.Windows.Forms.Button()
Me.SuspendLayout()
'
'TxtMessage
'
Me.TxtMessage.Location = New System.Drawing.Point(3, 3)
Me.TxtMessage.Multiline = True
Me.TxtMessage.Name = "TxtMessage"
Me.TxtMessage.ScrollBars = System.Windows.Forms.ScrollBars.Vertical
Me.TxtMessage.Size = New System.Drawing.Size(387, 203)
Me.TxtMessage.TabIndex = 3
Me.TxtMessage.TabStop = False
'
'Button1
'
Me.Button1.Location = New System.Drawing.Point(3, 212)
Me.Button1.Name = "Button1"
Me.Button1.Size = New System.Drawing.Size(125, 23)
Me.Button1.TabIndex = 0
Me.Button1.Text = "Bouton 1"
Me.Button1.UseVisualStyleBackColor = True
'
'Button2
'
Me.Button2.Location = New System.Drawing.Point(134, 212)
Me.Button2.Name = "Button2"
Me.Button2.Size = New System.Drawing.Size(125, 23)
Me.Button2.TabIndex = 1
Me.Button2.Text = "Bouton 2"
Me.Button2.UseVisualStyleBackColor = True
'
'Button3
'
Me.Button3.Location = New System.Drawing.Point(265, 212)
Me.Button3.Name = "Button3"
Me.Button3.Size = New System.Drawing.Size(125, 23)
Me.Button3.TabIndex = 2
Me.Button3.Text = "Bouton 3"
Me.Button3.UseVisualStyleBackColor = True
'
'FrmMsgBox
'
Me.AutoScaleDimensions = New System.Drawing.SizeF(6.0!, 13.0!)
Me.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font
Me.ClientSize = New System.Drawing.Size(393, 239)
Me.Controls.Add(Me.TxtMessage)
Me.Controls.Add(Me.Button2)
Me.Controls.Add(Me.Button3)
Me.Controls.Add(Me.Button1)
Me.MaximizeBox = False
Me.MinimizeBox = False
Me.Name = "FrmMsgBox"
Me.StartPosition = System.Windows.Forms.FormStartPosition.Manual
Me.Text = "FrmMsgBox"
Me.ResumeLayout(False)
Me.PerformLayout()
End Sub
Friend WithEvents TxtMessage As System.Windows.Forms.TextBox
Friend WithEvents Button1 As System.Windows.Forms.Button
Friend WithEvents Button2 As System.Windows.Forms.Button
Friend WithEvents Button3 As System.Windows.Forms.Button
End Class |
Partager