Public Class Form3 Private mUser As String = String.Empty Public ReadOnly Property User() As String Get Me.ShowDialog() Return mUser End Get End Property Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click 'valider ! mUser = TextBox1.Text Me.Close() End Sub Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click 'annuler ! Me.Close() End Sub 'CODE ESTHéTIQUE... Private Sub Form3_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load Me.MoveCtrl(TextBox1, 12, 12, 225, 20) Me.MoveCtrl(Button1, 61, 12, 97, 23, "Valider") Me.MoveCtrl(Button2, 61, 142, 97, 23, "Annuler") Me.MoveCtrl(Me, 0, 0, 263, 126, "Saisissez votre nom") End Sub Private Sub MoveCtrl(ByVal oCtrl As Object, ByVal iTop As Integer, ByVal iLeft As Integer, ByVal iWidth As Integer, ByVal iHeight As Integer, Optional ByVal Caption As String = "") If TypeOf oCtrl Is System.Windows.Forms.TextBox Then With DirectCast(oCtrl, System.Windows.Forms.TextBox) .Top = iTop .Left = iLeft .Width = iWidth .Height = iHeight End With ElseIf TypeOf oCtrl Is System.Windows.Forms.Button Then With DirectCast(oCtrl, System.Windows.Forms.Button) .Top = iTop .Left = iLeft .Width = iWidth .Height = iHeight .Text = Caption End With ElseIf TypeOf oCtrl Is System.Windows.Forms.Form Then With DirectCast(oCtrl, System.Windows.Forms.Form) .Width = iWidth .Height = iHeight .Text = Caption End With End If End Sub End Class
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click 'on récupère la saisie utilisateur, sera vide en cas d'annulation ou de non remplissage 'CAS 1 => en cas de réouverture la form3 aura conservé la saisie Dim sRet1 As String = Form3.User 'CAS2 => toujours une fenêtre vierge Dim f As New Form3 Dim sRet2 As String = f.User End Sub
Vous n’avez pas trouvé la réponse que vous recherchez ?
Posez votre question