Solved

Created a new form as a generic dialog result box, but 2 of the 3 buttons need to be clicked twice to work?

Posted on 2006-06-27
2
175 Views
Last Modified: 2010-04-23
I have created a simple additional form (frmDialog) to my application. It contains 3 buttons and a label. The idea is to create a generic dialog result box to my main app.

Properties –
      Form:
      FormBorderStyle:   FixedDialog
      CancelButton:         Button3

Button1:
      DialogResult:      “No”

Button2:
    DialogResult:      “Yes”

--------------------------------------------------------------------------------
The method call used throughout my app supplying different strings in the new form:

               ShowMyDialogForm("This Label Message.")
---------------------------------------------------------------------------------

The method to show frmDialog, display the message, and get the dialog result:

   Private Sub ShowMyDialogForm (ByVal MessageToDisplay As String)
        Dim dlg As New frmDialog
        dlg.DisplayMessage(MessageToDisplay)
        If dlg.ShowDialog = DialogResult.No Then
           Debug.WriteLine("No Was Pressed")
        ElseIf dlg.ShowDialog = DialogResult.Yes Then
            Debug.WriteLine("Yes Was Pressed")
        End If
    End Sub
---------------------------------------------------------------

The only method in the frmDialog to receive and display the message:

Public Sub DisplayMessage (ByVal Message As String)
        Me.lblMessage.Text = Message
End Sub

----------------------------------------------------------------
PROBLEM:

Click Button1 – OK    but...

Both Button2 and Button3 need to be clicked twice before the respective Debug.WriteLine message/Cancel of frmDialog happens.

Please, why? And how to resolve?

A big thanks in advance.
0
Comment
Question by:IvanHowarth
2 Comments
 
LVL 43

Accepted Solution

by:
TimCottee earned 500 total points
ID: 16992948
Hi IvanHowarth,

Because you are showing the dialog more than once:

   Private Sub ShowMyDialogForm (ByVal MessageToDisplay As String)
        Dim dlg As New frmDialog
        Dim result as DialogResult
        dlg.DisplayMessage(MessageToDisplay)
        result = dlg.ShowDialog
        If result = DialogResult.No Then
           Debug.WriteLine("No Was Pressed")
        ElseIf result = DialogResult.Yes Then
            Debug.WriteLine("Yes Was Pressed")
        End If
    End Sub

Is better, each time you use dlg.ShowDialog, the dialog is shown so your code forces it to be opened twice. You should save the result of a single opening and then test this for the various results.
Tim Cottee
0
 

Author Comment

by:IvanHowarth
ID: 16993341
Perfect - thanks!
0

Featured Post

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Get the selected ValueMember of Combobox 5 40
I need help converting a bitmap to an image in VB.Net 1 44
start a process from a service 3 33
SqlServer no dupes 25 38
Microsoft Reports are based on a report definition, which is an XML file that describes data and layout for the report, with a different extension. You can create a client-side report definition language (*.rdlc) file with Visual Studio, and build g…
Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

820 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question