Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

show() and ShowDialog()

Posted on 2011-03-10
5
Medium Priority
?
794 Views
Last Modified: 2012-05-11
I have two forms: Form1 and Form2, I want to Open form2 from form1 and return the value from Form2 to Form1, in addition, I want form1 stay active after form2 is opened.  When I call form2.show() , both forms are active, but form2 can't return any value to form2; While I call form2.showDialog(), I can return result from form2 to form1 but form1 is inactive. I know the differences between show() and ShowDiaglog(). However, what I need is the combination of two.  Is it possible? Just want to get some advise from experts before I say "no" to boss for this request.    

Thank you inadvance for help!
0
Comment
Question by:jrmc-pgmr
5 Comments
 
LVL 29

Expert Comment

by:Paul Jackson
ID: 35101840
0
 
LVL 86

Expert Comment

by:Mike Tomlinson
ID: 35102101
When you call ShowDialog(), code stops in the primary form until the secondary form is closed.  When the secondary form closes, you still have a reference to it so you can extract whatever you want:
' In Form1
    Dim f2 As New Form2
    If f2.ShowDialog = DialogResult.OK Then
        ' ...extract something from "f2" ...
        Me.Label1.Text = f2.TextBox1.Text
    End If

Open in new window


Note that we are checking the DialogResult() of Form2 to determine whether "OK" or "Cancel" was pressed.  In Form2, you'd simply do something like this to close the form and allow Form1 to continue and extract a value:
' In Form2
Private Sub btnOK_Click(...) Handles btnOK.Click
    Me.DialogResult = DialogResult.OK ' closes Form2 and allows Form1 to continue
End Sub

Open in new window

0
 
LVL 11

Expert Comment

by:bansidhar
ID: 35103742
you can do it. there is more than one way.

one way just pass form1 to form2 and when it closes update form1 or raise some event in form1. but i don't know why you want to do this, this can be dangerous because when the form2 closes and tries to update frm1, form1 may be in totally different state than expected or don't even exist.
0
 

Author Comment

by:jrmc-pgmr
ID: 35104555
Thanks all who helped!
Bansidhar: I understand the risk.   Could you provide sample code that will achieve this? Thanks
0
 
LVL 11

Accepted Solution

by:
bansidhar earned 2000 total points
ID: 35105917
Here is a sample. hope this helps
WindowsApplication1.zip
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

Introduction As chip makers focus on adding processor cores over increasing clock speed, developers need to utilize the features of modern CPUs.  One of the ways we can do this is by implementing parallel algorithms in our software.   One recent…
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.
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …
Look below the covers at a subform control , and the form that is inside it. Explore properties and see how easy it is to aggregate, get statistics, and synchronize results for your data. A Microsoft Access subform is used to show relevant calcul…
Suggested Courses

926 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