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

x
?
Solved

show() and ShowDialog()

Posted on 2011-03-10
5
Medium Priority
?
793 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 2000 total points
ID: 35105917
Here is a sample. hope this helps
WindowsApplication1.zip
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

This article explains how to create and use a custom WaterMark textbox class.  The custom WaterMark textbox class allows you to set the WaterMark Background Color and WaterMark text at design time.   IMAGE OF WATERMARKS STEPS Create VB …
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…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…

670 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