Le réseau pour les développeurs > Forums - Accueil > Visual Basic General > Call a form and wait for its button click
Poser une questionPoser une question
 

TraitéeCall a form and wait for its button click

  • mercredi 4 novembre 2009 15:41s_walker1522 Médailles de l'utilisateurMédailles de l'utilisateurMédailles de l'utilisateurMédailles de l'utilisateurMédailles de l'utilisateur
     A du code

    I have 2 forms, form1 is my main form and form2 is a "Do this or do this" form (Form with 2 buttons like a are you sure form).  When the user tries to close form1 if their is more than 1 tab open, it shows form2 which ask if they want to close the whole program or just the current tab.

    I'm trying to figure out how to reviecve what button the user clicks on form2. How would I need to do this?

    ''Form1:    
    
    Private Sub frmMain_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
            If (tc1.TabPages.Count > 1) And (My.Settings.AskClseTab = True) Then
                If frm_Closemain.ActionTakin = "Exit" Then
                    GoTo Cont
                ElseIf frm_Closemain.ActionTakin = "Tab" Then
                    tc1.TabPages.Remove(tc1.TabPages.SelectedTab)
                    Exit Sub
                ElseIf frm_Closemain.ActionTakin = "WasClosed" Then
                    Exit Sub
                End If
            End If
    End sub
    
    ''Form2:
    
    Public Class frm_Closemain
    
        Dim _actiontakin As String = ""
    
        Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
            actiontakin = sender.tag
            Me.Close()
        End Sub
    
        Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
            actiontakin = sender.tag
            Me.Close()
        End Sub
    
        Public Property ActionTakin As String
            Get
                _actiontakin = ""
                Me.Show()
                Do Until _actiontakin.Length > 0
                                Loop
    
                Return _actiontakin
            End Get
            Set(ByVal value As String)
                _actiontakin = value
            End Set
        End Property
    
        Private Sub frm_Closemain_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
            If _actiontakin = "" Then
                _actiontakin = "WasClosed"
            End If
        End Sub
    End Class
    
    The problem: as soon as the form loads it becomes "Not responding" I believe this is caused by my do while loop, what other way could I go about doing this?

Réponses

  • mercredi 4 novembre 2009 15:51TechNoHick Médailles de l'utilisateurMédailles de l'utilisateurMédailles de l'utilisateurMédailles de l'utilisateurMédailles de l'utilisateur
     TraitéeA du code
    if you use ShowDialog the form will open and the app will wait for it to close without the loop

    something like:
    Public Class frmMain
        Private Sub frmMain_FormClosing(ByVal sender As Object, _
                                        ByVal e As System.Windows.Forms.FormClosingEventArgs) _
                                        Handles Me.FormClosing
    
            Dim dlgClosemain As New frm_Closemain
    
            If (tc1.TabPages.Count > 1) And (My.Settings.AskClseTab = True) Then
    
    
                'use ShowDialog
                If dlgClosemain.ShowDialog(Me) = Windows.Forms.DialogResult.No Then
                    e.Cancel = True
                End If
    
    
    
            End If
        End Sub
    
    End Class
    
    • Marqué comme réponses_walker1522 mercredi 4 novembre 2009 16:06
    •  

Toutes les réponses

  • mercredi 4 novembre 2009 15:51TechNoHick Médailles de l'utilisateurMédailles de l'utilisateurMédailles de l'utilisateurMédailles de l'utilisateurMédailles de l'utilisateur
     TraitéeA du code
    if you use ShowDialog the form will open and the app will wait for it to close without the loop

    something like:
    Public Class frmMain
        Private Sub frmMain_FormClosing(ByVal sender As Object, _
                                        ByVal e As System.Windows.Forms.FormClosingEventArgs) _
                                        Handles Me.FormClosing
    
            Dim dlgClosemain As New frm_Closemain
    
            If (tc1.TabPages.Count > 1) And (My.Settings.AskClseTab = True) Then
    
    
                'use ShowDialog
                If dlgClosemain.ShowDialog(Me) = Windows.Forms.DialogResult.No Then
                    e.Cancel = True
                End If
    
    
    
            End If
        End Sub
    
    End Class
    
    • Marqué comme réponses_walker1522 mercredi 4 novembre 2009 16:06
    •  
  • mercredi 4 novembre 2009 16:06s_walker1522 Médailles de l'utilisateurMédailles de l'utilisateurMédailles de l'utilisateurMédailles de l'utilisateurMédailles de l'utilisateur
     

    Thank You.