Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
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
Medium Priority
?
187 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 43

Accepted Solution

by:
TimCottee earned 2000 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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

This tutorial demonstrates one way to create an application that runs without any Forms but still has a GUI presence via an Icon in the System Tray. The magic lies in Inheriting from the ApplicationContext Class and passing that to Application.Ru…
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…
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Suggested Courses

715 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