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
169 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

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

Article by: jpaulino
XML Literals are a great way to handle XML files and the community doesn’t use it as much as it should.  An XML Literal is like a String (http://msdn.microsoft.com/en-us/library/system.string.aspx) Literal, only instead of starting and ending with w…
A while ago, I was working on a Windows Forms application and I needed a special label control with reflection (glass) effect to show some titles in a stylish way. I've always enjoyed working with graphics, but it's never too clever to re-invent …
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

707 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now