473,385 Members | 1,764 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Creating child forms?

jay
I'm trying to open up an existing form from my main form. In that new form,
I want to pass a value to a starting form from a button click.

I'm using:

Form2 f = new Form2()
f.Show()

but how do I reference the Form1 from the Form2?
I tried using ParentForm property, but unsuccessfully.

I would also like to know how to open this new form (Form2) modally.

thank you,
jay
Nov 16 '05 #1
3 8039
You could pass a reference in the Form2 constructor.

Use ShowDialog() to get it modal, you can use the DialogResult enumeration
that is returned to determine appropriate actions.
You can associate a DialogResult with buttons, thay way you don't have to
implement a click event that sets the property.

Form2 f = new Form2(this)

if(f.ShowDialog() == DialogResult.OK)
{
// do something
}

Chris

"jay" <so***@nospam.com> wrote in message news:cc**********@bagan.srce.hr...
I'm trying to open up an existing form from my main form. In that new form, I want to pass a value to a starting form from a button click.

I'm using:

Form2 f = new Form2()
f.Show()

but how do I reference the Form1 from the Form2?
I tried using ParentForm property, but unsuccessfully.

I would also like to know how to open this new form (Form2) modally.

thank you,
jay

Nov 16 '05 #2
I had the same problem, and the way I got around it was passing a variable
into the Form2 constructor. You can also declare a static variable on Form1
and set its value before calling Form2. I've asked around what the 'best'
or 'preferred' method is, but haven't received a response yet. But those
two options do work. The ShowDialog() method opens your form as a modal
dialog box, and returns a DialogResult you can use to determine which dialog
Button was pressed; or you can set its value manually in the modal dialog if
something went wrong.

Thanks,
Michael C.

"jay" <so***@nospam.com> wrote in message news:cc**********@bagan.srce.hr...
I'm trying to open up an existing form from my main form. In that new form, I want to pass a value to a starting form from a button click.

I'm using:

Form2 f = new Form2()
f.Show()

but how do I reference the Form1 from the Form2?
I tried using ParentForm property, but unsuccessfully.

I would also like to know how to open this new form (Form2) modally.

thank you,
jay

Nov 16 '05 #3
jay
Thanks for both of your replies. I'd like to add a complete solution I found
for my problem in case someone needs it:

In form1 I have a static variable that I can access from form2 when form2 is
open.
In form1 I have an event that gets fired when form2 is closed. This is where
I handle whatever I want handled when form2 is closed. It looks like this:

// This is form1 code:

private void button1_Click(object sender, System.EventArgs e)
{
Form2 f = new Form2();
f.Closed += new EventHandler(f_Closed);
f.ShowDialog();
}
private void f_Closed(object sender, EventArgs e)
{
_Act();
}
private void _Act()
{
MessageBox.Show ("Do whatever...");
}

hope this helps someone and thanks again to you two guys,
jay

"Michael C" <mi*******@optonline.net> wrote in message
news:2O********************@news4.srv.hcvlny.cv.ne t...
I had the same problem, and the way I got around it was passing a variable
into the Form2 constructor. You can also declare a static variable on Form1 and set its value before calling Form2. I've asked around what the 'best'
or 'preferred' method is, but haven't received a response yet. But those
two options do work. The ShowDialog() method opens your form as a modal
dialog box, and returns a DialogResult you can use to determine which dialog Button was pressed; or you can set its value manually in the modal dialog if something went wrong.

Thanks,
Michael C.

"jay" <so***@nospam.com> wrote in message

news:cc**********@bagan.srce.hr...
I'm trying to open up an existing form from my main form. In that new

form,
I want to pass a value to a starting form from a button click.

I'm using:

Form2 f = new Form2()
f.Show()

but how do I reference the Form1 from the Form2?
I tried using ParentForm property, but unsuccessfully.

I would also like to know how to open this new form (Form2) modally.

thank you,
jay


Nov 16 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Mike Turco | last post by:
What is the difference between creating relationships in the front-end vs. the back-end database? I was trying to create a relationship in a database front-end and noticed that I could not check...
8
by: CJack | last post by:
hy, I have an mdi application, i create a child form and I want to know when a button is pressed while that child form is loaded. I have this code: private void frmTestBaby_KeyUp(object sender,...
3
by: James Spibey | last post by:
Hi, I have an MDI application which has aboout 10 child windows. The way the app needs to work is that only one window should be visible at a time and it should be maximized within the parent...
3
by: Lance | last post by:
I've noticed that controls that are contained in MDI child forms fail to raise MouseLeave events if the MDI child form's MdiParent property is set to Nothing (after it was set to an existing MDI...
10
by: Charles Law | last post by:
For some reason, when I click the X to close my MDI parent form, the action appears to be re-directed to one of the MDI child forms, and the parent remains open. I am then unable to close the...
0
by: Bruin | last post by:
Hi All, I'm having a problem with MDI child forms when the reference to the MDI Parent is set in a Control library. (Sorry for the long post) I have an control library assembly which holds all...
2
by: Lenster | last post by:
Environment --------------- Visual Studio.NET 2003 Version 7.1.3088 ..NET Framework 1.1 Version 1.1.4322 SP1 XP Professional 5.1.2600 SP2 Build 2600 Problem Description...
0
by: Scott H. | last post by:
I have an MDI parent form that creates mdi child forms each of which are represented by a tab item. I use a third party control to generate the tabbed MDI child forms. Each tab or MDI child form...
13
by: Academic | last post by:
I have a MDI form, sometimes child forms and sometimes forms that are neither If I close the app the child forms closing and closed event happens followed by the Mdi form receiving the...
0
by: emalcolm_FLA | last post by:
Hello and TIA for any help with this non profit Christmas assistance project. I have an applicant (app history) and child (child history) tables (4 total). I need to grab the next available (in...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.