Solved

show() and ShowDialog()

Posted on 2011-03-10
5
791 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
[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
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 500 total points
ID: 35105917
Here is a sample. hope this helps
WindowsApplication1.zip
0

Featured Post

Enroll in May's Course of the Month

May’s Course of the Month is now available! Experts Exchange’s Premium Members and Team Accounts have access to a complimentary course each month as part of their membership—an extra way to increase training and boost professional development.

Question has a verified solution.

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

1.0 - Introduction Converting Visual Basic 6.0 (VB6) to Visual Basic 2008+ (VB.NET). If ever there was a subject full of murkiness and bad decisions, it is this one!   The first problem seems to be that people considering this task of converting…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…
Finding and deleting duplicate (picture) files can be a time consuming task. My wife and I, our three kids and their families all share one dilemma: Managing our pictures. Between desktops, laptops, phones, tablets, and cameras; over the last decade…

752 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