473,397 Members | 2,077 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,397 software developers and data experts.

Usercontrol open mdichild?

I am bulding a Windows Form Application in Visual Studio using C#.

In my application the main form (form1) has a usercontrol with a button. When the user clicks the button I would like a MdiChild form (of form1) to appear.

Normally when opening a MdiChild from a button on a parent form or another child form I use:

Expand|Select|Wrap|Line Numbers
  1. private void Button1_Click(object sender, EventArgs e)
  2.  {
  3.  
  4. Form2 newMdiChild = new Form2();
  5.  newMdiChild.Mdiparent = this.Mdiparent;
  6.  newMdiChild.Show();
However, this does not work with the Usercontrol button due to an error that states the Usercontrol does not contain a definition for MdiParent.

I am still new to programming but any help would be greatly appreciated.
Dec 6 '11 #1
1 3537
adriancs
122 100+
is this Example solve your problems?

create 3 Forms: Form1, Form2 and Form3.

Form1:
Expand|Select|Wrap|Line Numbers
  1. namespace WindowsFormsApplication1
  2. {
  3.     public partial class Form1 : Form
  4.     {
  5.         public Form1()
  6.         {
  7.             InitializeComponent();
  8.             this.IsMdiContainer = true;
  9.         }
  10.  
  11.         private void button1_Click(object sender, EventArgs e)
  12.         {
  13.             Form2 f2 = new Form2();
  14.             f2.MdiParent = this;
  15.             f2.Show();
  16.         }
  17.  
  18.         private void button2_Click(object sender, EventArgs e)
  19.         {
  20.             Form3 f3 = new Form3();
  21.             f3.MdiParent = this;
  22.             f3.Show();
  23.         }
  24.     }
  25. }
Form2:
Expand|Select|Wrap|Line Numbers
  1. namespace WindowsFormsApplication1
  2. {
  3.     public partial class Form2 : Form
  4.     {
  5.         public Form2()
  6.         {
  7.             InitializeComponent();
  8.         }
  9.  
  10.         private void button1_Click(object sender, EventArgs e)
  11.         {
  12.             Form2 f2 = new Form2();
  13.             f2.MdiParent = this.MdiParent;
  14.             f2.Show();
  15.         }
  16.  
  17.         private void button2_Click(object sender, EventArgs e)
  18.         {
  19.             Form3 f3 = new Form3();
  20.             f3.MdiParent = this.MdiParent;
  21.             f3.Show();
  22.         }
  23.     }
  24. }
Form3:
Expand|Select|Wrap|Line Numbers
  1. namespace WindowsFormsApplication1
  2. {
  3.     public partial class Form3 : Form
  4.     {
  5.         public Form3()
  6.         {
  7.             InitializeComponent();
  8.         }
  9.  
  10.         private void button1_Click(object sender, EventArgs e)
  11.         {
  12.             Form3 f3 = new Form3();
  13.             f3.MdiParent = this.MdiParent;
  14.             f3.Show();
  15.         }
  16.  
  17.         private void button2_Click(object sender, EventArgs e)
  18.         {
  19.             Form2 f2 = new Form2();
  20.             f2.MdiParent = this.MdiParent;
  21.             f2.Show();
  22.         }
  23.     }
  24. }
Dec 6 '11 #2

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

Similar topics

0
by: Supra | last post by:
i got mdichild working. i'm working on similar to mirc chat. when i joined channel #vb the first mdichild is on. then when i wanted to join another channel #visualbasic. then i got second mdichild...
1
by: Job Lot | last post by:
How can I prevent multiple instances of MdiChild form? I have a MdiParent form with a DataGrid showing all the clients in the database. User clicks on a row to open MdiChild form which display...
2
by: SpotNet | last post by:
Hello NewsGroup, I have a MDIParent form with a docked left treeview control, a splitter control and a generic docked control on the right. Kind of looks like Windows Explorer, though it's...
7
by: VM | last post by:
Hi, Is it possible to open always only one instance of a MDIChild form? Say, if form A is already opened, just give it the focus. I tried declaring theMDIChild forms as private members of the...
1
by: LCAdeveloper | last post by:
Can anyone help me with this? I'm trying to get an MDIChild form to lookup the value of a control on another open MDIChild form, but can't seem to get the right syntax. Let's say the two child...
0
by: Supra | last post by:
i got mdichild working. i'm working on similar to mirc chat. when i joined channel #vb the first mdichild is on. then when i wanted to join another channel #visualbasic. then i got second mdichild...
0
by: Supra | last post by:
i got code working. similar to mirc chat. but what happen when i joined the channel #visualbasic...that fine with me , i got all data coming into first mdichild. but when i joined another channel...
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...
2
by: faraz | last post by:
I am experiencing a very wierd problem. I have mdi application. I dont want mdiChild's min,max and close button. so i set all of them to false. now my title bar goes from mdiChild form. when i...
0
by: kardiss | last post by:
I am trying to add Meebo's "Pop-out" kinda feature to my application which when a button is pressed in a MdiChild form, it kicks that MdiChild form out of the MdiParent boundary and acts like a SDI...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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
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...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new...

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.