473,383 Members | 1,978 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,383 software developers and data experts.

Child usercontrol?

Okay.... so I have the feeling that this is not as difficult as I think it is but I can not seem to figure it out. Any help would be greatly appreciated!!

I have button on form3 that once clicked shows a new usercontrol on form1. However, the usercontrol has a number of buttons that I would like to be child forms of form1 (Form4 newMDIChild = new Form4(); newMDIChild.MdiParent = this.MdiParent;
newMDIChild.Show(); does not work). Unfortunatley, I cannot seem to figure out how to make the usercontrol a child or to let the usercontrol know who the child forms parent is.

This is what I have so far.

Thanks in advance!!!!!



Button Form

Expand|Select|Wrap|Line Numbers
  1.   public partial class Form3 : Form
  2.     {
  3.  
  4.         public Form3()
  5.         {
  6.             InitializeComponent();
  7.         }
  8.  
  9.             protected void Show (Control control)
  10.         {
  11.          Form1 form = (Form1)Application.OpenForms["Form1"];
  12.             form.Controls.Add(control);
  13.             form.Show();
  14.  
  15.  
  16.         }
  17.         private void button2_Click(object sender, EventArgs e)
  18.         {
  19.  
  20.             UserControl1 userControl = new UserControl1();
  21.             Form3 form = new Form3();
  22.             form.Show(userControl);
  23. }
  24. }
  25. }
Nov 27 '11 #1
2 2069
arie
64
Method Form.Show(owner) sets "A Form that represents the form that is the owner of this form." (according to MSDN)

If you want for your usercontrol to "own" the form, try setting Form.Parent property.

Or, in your Form3 class, you can add your own property that you will set when creating the form:
Expand|Select|Wrap|Line Numbers
  1. public partial class Form3 : Form
  2. {
  3.  public Control OwnerControl{get;set;}
  4.  public Form3()
  5.  {
  6.     InitializeComponent();
  7.  }
  8.  public Form3(Control c)
  9.  {
  10.     InitializeComponent();
  11.     OwnerControl = c;
  12.  }
  13.  
  14. //.....
  15. private void button2_Click(object sender, EventArgs e)
  16. {
  17.    UserControl1 userControl = new UserControl1();
  18.    Form3 form = new Form3(userControl);
  19.    form.Show();
  20. }
  21. }
(this code is not compiled or tested, it's only an idea)
Nov 28 '11 #2
Thanks for the help but I was hoping to make Form1 own the usercontrol but I will definatley use this in the future for other things! Thank you! : )
Nov 28 '11 #3

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

Similar topics

3
by: red | last post by:
mouse events when the mouse is on a "child control" hi everyone; my problem: I have a userControl in this usercontrol, I have a child control (a button) when the mouse moves over the...
2
by: Dave Veeneman | last post by:
Is there a simple way to pass drag-and-drop events to a child control in a UserControl? Here's an example: I have created a UserControl which contains a treeview and some text boxes. I want to...
9
by: Richard Brown | last post by:
Can anyone give me a good argument one way or another? I have an 'address' set of fields that are used in various situations (a client has an address, a destination has an address, etc). These...
0
by: Scott McChesney | last post by:
I have a problem I hope you folks can help me with. I have an application that is using a tab-based interface, with the ability for users to drag an item from a ListBox onto the tab control. ...
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...
9
by: Marcelo Cabrera | last post by:
Hi, I have a user control that in turn creates a bunch of webcontrols dynamically and handles the events these webcontrols raise. It used to work fine on ASP .Net 1.1 but when compiled on 2.0 it...
2
by: lotus | last post by:
HI All.. I'm realtively new to C#. I have MainForm which includes Parent usercontol, and this parent usercontrol also contains child usercontrol. MainForm --> Parent usercontrol --> child...
0
by: Joe | last post by:
Anyone have any experience using custom snaplines? I have a usercontrol that acts as a container for several child controls. I wrote an inherited ControlDesigner to handle some custom actions...
10
by: Benton | last post by:
Hi there, I have a UserControl with a couple of textboxes and a couple of buttons ("Save" and "Cancel"). The Click event for this buttons is in the UserControl's codebehind of course, so here's...
3
by: COHENMARVIN | last post by:
I have an aspx page that loads a usercontrol. Can that usercontrol load another usercontrol into part of it? Thanks, Marv
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...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
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...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
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: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?

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.