2011-12-05 4 views
1

Je suis un novice en matière de point visuel de base. J'ai essayé de créer un design en cours d'exécution. Voici mon code simple.Codage au moment du design

Dim frmLogin As New Form 
    Dim lblUserName, lblPassword As New Label 
    Dim txtUserName, txtPassword As New TextBox 
    Dim btnContinue, btnCancel As New Button 

    'set frmLogin properties 
    frmLogin.StartPosition = FormStartPosition.CenterScreen 
    frmLogin.FormBorderStyle = Windows.Forms.FormBorderStyle.None 
    frmLogin.BackColor = Color.LightGray 
    frmLogin.Size = New Size(400, 200) 

    'set lblUserName properties 
    lblUserName.Text = "User Name: " 
    lblUserName.Font = New Font("Calibri", 12, FontStyle.Regular) 
    lblUserName.Location = New Point(20, 30) 

    'set lblPassword properties 
    lblPassword.Text = "Password: " 
    lblPassword.Font = New Font("Calibri", 12, FontStyle.Regular) 
    lblPassword.Location = New Point(20, 70) 

    'set txtUserName properties 
    txtUserName.Font = New Font("Calibri", 12, FontStyle.Regular) 
    txtUserName.Location = New Point(120, 20) 
    txtUserName.Size = New Size(250, 20) 

    txtPassword.Font = New Font("Calibri", 12, FontStyle.Regular) 
    txtPassword.Location = New Point(120, 60) 
    txtPassword.Size = New Size(250, 20) 
    txtPassword.PasswordChar = "*" 

    btnCancel.Text = "Cancel" 
    btnCancel.Location = New Point(270, 120) 
    btnCancel.Size = New Size(100, 28) 
    btnCancel.BackColor = Color.White 
    btnCancel.Font = New Font("Calibri", 12, FontStyle.Regular) 

    frmLogin.Controls.Add(lblPassword) 
    frmLogin.Controls.Add(lblUserName) 
    frmLogin.Controls.Add(txtUserName) 
    frmLogin.Controls.Add(txtPassword) 
    frmLogin.Controls.Add(btnCancel) 
    frmLogin.ShowDialog() 

Comment commencer à créer un code ici? Je voudrais commencer dans btnCancel, comment pourrais-je insérer ce code dans btnCancel

dim myAns as string = msgbox("This will exit the program. Are you sure?") 
if ans = vbyes then application.exit 

Répondre

2

vous devez ajouter un gestionnaire d'événements aux contrôles:

'register the event handler after initializing of the control 
AddHandler btnCancel.Click, AddressOf CancelClick 


'create a method with same signature as the delegate of the event 
Private Sub CancelClick(ByVal sender As Object, ByVal e As EventArgs) 
    'do your stuff here 
End Sub 
+0

si je fais un code (pour la course design-temps) dans un autre bouton? Comment puis-je insérer le code de sortie à l'intérieur du bouton Annuler. – aer

+0

... et il y a une erreur La méthode 'Public Sub CancelClick (expéditeur comme objet, e Comme system.Windows.Forms.MoseEventArgs)' n'a pas la même signature que le délégué 'Delegate Sub EventHandler (expéditeur As Object, e Comme System.EventArgs) '. – aer

+1

désolé ses EventArgs et pas MouseEventArgs -> voir modifier. S'il vous plaît, posez votre autre question, je ne comprends pas ce que vous voulez dire. – fixagon

Questions connexes