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

Ransomware-A Revenue Bonanza for Service Providers

Ransomware – malware that gets on your customers’ computers, encrypts their data, and extorts a hefty ransom for the decryption keys – is a surging new threat.  The purpose of this eBook is to educate the reader about ransomware attacks.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
DataGridView Events ? 3 47
Vb. Net application freezes 9 48
VB.NET Repostiory Pattern 7 37
VB.Net - TypeInitializer Error 25 28
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…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…

803 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