473,320 Members | 1,694 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes and contribute your articles to a community of 473,320 developers and data experts.

Simple Parent Child Form Switching

This article is aimed at beginners, so don't judge me on the quality please.

I know many of you are there sitting at your computers looking at the title going 'what is he on about?'. I would too.

Over the past few weeks, many of the forums I've browsed have nothing on switching between a 'parent' and a 'child' form other than some really complex 'mumbo jumbo'. I am here to show a simple solution.

Also do note, my explanation of parent and child forms is different to that defined in the c# language.


This was the problem:
  1. You have 2 forms.
  2. One is named frmParent and the other named frmChild.
  3. frmParent is your main form which is most of the program.
  4. frmChild is like a settings type form, which only handles a small part of the program.

Now, you have a button on your main form that says 'settings', when you click on it, you want it to hide your main form, and show the settings form. When you close the settings form, you want it to show the main form again.

Some of the code I have seen to do this is way too complex.

Here is my solution.

For the settings button's Click Event, lets call it btnSettings, we add this code:

Expand|Select|Wrap|Line Numbers
  1. private void btnSettings_Click(object sender, EventArgs e)
  2. {
  3. frmChild child = new frmChild();
  4. this.Hide();
  5. child.ShowDialog();
  6. this.Show();
  7. }
  8.  
You may expect that this code will hide and show the parent form instantly, but it doesn't.

The this.Hide(); command hides frmParent from view.
The child.ShowDialog(); command pauses frmParent and disables it. Similar to what happens when you summon a MessageBox and you can't use the form behind it. child.ShowDialog(); also shows an instance of frmChild frmParent will remain paused until you close frmChild, and when you do, viola! frmParent reappears because of this.Show();!

Now many forums seem to discuss disposal problems, but in my own opinion, for beginners, this is a good place to start.

Note: I know this article is rough, but it is my first time! :)

mindmadness45
Jan 11 '11 #1
0 5680

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Mr. B | last post by:
I've been beating my brains out on trying to figure out how to do Recurse (Parent/Child) code for my application (VB.net). Basically a User enters data into an array. The data is pretty simple:...
4
by: tdmailbox | last post by:
I have form with subform that has a button(one in parent, one in the child) that calls the microsoft access find/replace object. In order to make it a find only object I need to set the...
0
by: Karthick Kumar | last post by:
Hi, I need to create a simple parent/child hierarchical menu. I have alread used the Treeview control but my requirement is slightly different than the Treeview control. I already have the kind...
0
by: Ross | last post by:
ASP.NET Problem: I have a dataset with a parent table and a child table. For every row in the parent table there are ~1/2 dozen corresponding records in the child table. In the ASPX page I have a...
1
by: news.microsoft.com | last post by:
I am trying to make a customer look up page that can send back the customer Id to the parent page. What is the best way to do this? It is easy in vb.net desktop application, but other than...
1
by: KentG | last post by:
I need a little direction. I'm converting an access database application to a webforms application. My access form has a one to many relationship between the parent and subforms. I would like to...
0
by: Hardik Shah | last post by:
Hi, I have a child form that has textbox1, I want to add default value for textbox1 but value is not stored to textbox successfully. However , If I run same form directly , it runs successfully....
3
by: Sheikko | last post by:
Hi, i have an application MDI with a TPanel in the left side. THe problem is when I call a child and I maximizie it, it go also under the panel. I have tried to insert another TPanel and include...
7
by: Darin | last post by:
I have a parent form that has a menu. I then have a child form on the menu. From the child form I need to change the parent form's menu - how can i do that? I tried me.parent.mfavorites, but that...
1
by: scudsong | last post by:
I override ProcessCmdKey() in my MDI parent form class and have some keyboard shortcut calling method in same class. But I wish to make these hotkeys working in parent/child form and other form. The...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

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.