Making two dialogs pop up on after the other.
Making two dialogs pop up on after the other.
Making two dialogs pop up on after the other.
Making two dialogs pop up on after the other.
Making two dialogs pop up on after the other.
Making two dialogs pop up on after the other. Making two dialogs pop up on after the other. Making two dialogs pop up on after the other. Making two dialogs pop up on after the other. Making two dialogs pop up on after the other. Making two dialogs pop up on after the other. Making two dialogs pop up on after the other. Making two dialogs pop up on after the other.
Making two dialogs pop up on after the other. Making two dialogs pop up on after the other.
Making two dialogs pop up on after the other.
Go Back  Xtreme Visual Basic Talk > > > Making two dialogs pop up on after the other.


Reply
 
Thread Tools Display Modes
  #1  
Old 06-18-2011, 02:47 AM
45minutes 45minutes is offline
Regular
 
Join Date: Jan 2011
Posts: 75
Default Making two dialogs pop up on after the other.


Hi, I have a slight problem. I can currently make a dialog1 pop up, then the user clicks "Yes" for dialog1, then dialog2 pops up, and if the user clicks "no" instead of "yes", dialog2 reappears again. I've got a headache now, but I will re-look over my code to see if there are logic errors.

I originally had dialog2 and form1 (the form1 was acting as dialog1). But The thing was that I do not how to give properties of a dialog to a form (i.e. not make the user be able to click other windows while this form is open) IF I could have code that says Me.bringtofront (which I have tried) didn't work though. If I apply this command to a form I get an error:

code: Form1.showdialog()
error: Please make form1 not visible. something a long those lines. But what I don't understand is form1 was never open.


What do the standard lines of code do?:

Me.DialogResult = System.Windows.Forms.DialogResult.OK
Me.DialogResult = System.Windows.Forms.DialogResult.Cancel

Last edited by 45minutes; 06-18-2011 at 03:13 AM.
Reply With Quote
  #2  
Old 06-24-2011, 09:03 PM
s0mewhiteguy7 s0mewhiteguy7 is offline
Newcomer
 
Join Date: Dec 2010
Posts: 7
Default

why dont you just use message boxes?

Code:
Dim result As MsgBoxResult
result = MsgBox("Dialog 1", MsgBox.Style.YesNo) ' The MsgBocStyle might differ a bit so correct it if im wrong im writing this off the top of my head.
If result = MsgBoxResult.Yes Then
MsgBox("Dialog 2", MsgBox.Style.YesNo)
ElseIf result = MsgBoxResult.No Then
MsgBox("Dialog 1", YesNo)
End If
That could work for what you are looking for i think from what you have said.
Reply With Quote
  #3  
Old 06-25-2011, 02:31 PM
AtmaWeapon's Avatar
AtmaWeaponMaking two dialogs pop up on after the other. AtmaWeapon is offline
Fabulous Florist

Forum Leader
* Guru *
 
Join Date: Feb 2004
Location: Austin, TX
Posts: 9,500
Default

It's really hard to comment on code I cannot see. There's hundreds of ways you could cause the behavior you're describing. It'd be a waste of time for me to speculate.

Instead, I'll discuss how to make two forms behave like you're saying. s0mewhiteguy7's suggestion is nice, but he really should have used MessageBox.Show instead of MsgBox(). Old habits die hard.

Suppose you have two forms, Dialog1 and Dialog2. You want to make them appear one after another, but you don't want dialog 2 to show up if the user clicked "no" to dialog 1. Before we make the forms, let's talk about what makes a dialog a dialog.

There's no magic to making a form a dialog; there's just a loose set of rules. To make any form a dialog, use the ShowDialog() method instead of Show() to show it. This has 2 major differences from Show():
  • A dialog is modal, which means it blocks input to other forms.
  • When a dialog is closed, it is not immediately disposed.
I'll talk about them as needed but leave most of the reasons a mystery you can ask about if curious.

ShowDialog() returns a DialogResult enumeration value. When you set the DialogResult property of a form that's been displayed with ShowDialog(), it usually closes itself, and ShowDialog() returns the result you set. This is how you tell if a dialog was cancelled or not. If you don't set DialogResult, I think it returns DialogResult.Cancel. You'll have to experiment if that matters to you.

So here's a basic implementation of Dialog1, assuming you have two buttons: btnOK and btnCancel:
Code:
Public Class Dialog1
    Inherits Form
    
    Sub btnOK_Click(...) Handles btnOK.Click
        Me.DialogResult = DialogResult.OK
    End Sub
    
    Sub btnCancel_Click(...) Handles btnCancel.Click
        Me.DialogResult = DialogResult.Cancel
    End Sub
End Class
Easy! Let's say Dialog2 looks similar. In some form MainForm you want to show these dialogs in succession. Code to do so may look like this:
Code:
Dim dialog1 As New Dialog1()
If dialog1.ShowDialog(Me) = DialogResult.OK Then
    Dim dialog2 As New Dialog2()
    If dialog2.ShowDialog(Me) = DialogResult.OK Then
        ' Do what happens if OK is clicked for both dialogs
    Else
        ' (Optional) Do what happens if dialog 1 is OK but dialog2 is cancel
    End If
Else
    ' (Optional) Do something if dialog1 is cancelled
End If
There's more complicated ways to lay it out to avoid the nesting, but it's easiest to teach this way. The first dialog is displayed; if it indicates the user clicked OK dialog 2 is displayed. Note that you don't have to use a button that says OK; there's dialog results for "Yes" and "No" and if you're feeling particularly silly feel free to let DialogResult.Cancel mean "OK" as long as you don't confuse yourself.

Note that I passed Me as a parameter to ShowDialog(). You don't *have* to do this. By default, the form that shows the dialog is the one that's blocked. If you want a different form to be blocked, you can use the parameter to specify. A long time ago in an older version of .NET I encountered a bug where my dialog wouldn't block the form that displayed it, so I have a habit of always passing Me even though that's the default.

There's a few other conventions dialogs are supposed to follow; Microsoft recommends a border style of "fixed dialog". Often dialogs hide the icon, minimize/maximize box, and even opt to not show in the taskbar. Personally, I let my dialogs display in the taskbar thanks to some bad experiences with dialogs that end up getting pushed under the blocked window. I also don't like forms I can't resize. But hiding the minimize/maximize boxes isn't harmful.
__________________
.NET Resources
My FAQ threads | Tutor's Corner | Code Library
I would bet money 2/3 of .NET questions are already answered in one of these three places.
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
Making two dialogs pop up on after the other.
Making two dialogs pop up on after the other.
Making two dialogs pop up on after the other. Making two dialogs pop up on after the other.
Making two dialogs pop up on after the other.
Making two dialogs pop up on after the other.
Making two dialogs pop up on after the other. Making two dialogs pop up on after the other. Making two dialogs pop up on after the other. Making two dialogs pop up on after the other. Making two dialogs pop up on after the other. Making two dialogs pop up on after the other. Making two dialogs pop up on after the other.
Making two dialogs pop up on after the other.
Making two dialogs pop up on after the other.
 
Making two dialogs pop up on after the other.
Making two dialogs pop up on after the other.
 
-->