Click to See Complete Forum and Search --> : Windows Form
staclite
April 10th, 2009, 12:19 PM
Hi Every one
I trying to put windows form into an other windows form
or put a usercontrol into a panel
do someone know how to do this
thx
Shuja Ali
April 10th, 2009, 12:59 PM
Welcome to the Forum :wave:
Your question is little confusing. If you want to make one form parent and the other child, you will have to use MDI Form. There is a property in the Windows Form that sets it as MDIForm. Once that is done, you then need to set the second forms MDIParent property to the first form.
staclite
April 10th, 2009, 01:21 PM
Thx for your reply
Ok i confused my self with your explabation but I will explan more what I want.
I want to make a application with different panel with visual studio.
I know I can make panel and hide them or show them with my menu but I if there is a way that I can change the object in the panel like windows for or user control that will be the best because I will have all my interface design separatly and not in the same form
I don't know if I explained it well
Sorry if not
Thx
Shuja Ali
April 10th, 2009, 01:31 PM
To answer your question of whether you can put a User Control in the panel, yes you can. You can create a user control that will hold all your UI elements and then host it on to a Panel or the Form directly.
In Visual Studio, just select project menu and then click User Control.
staclite
April 10th, 2009, 01:39 PM
Ok but how can I host the user control into a panel
He there a conde line easy to put the user control in a panel
thx
Shuja Ali
April 10th, 2009, 02:04 PM
A user control is just like any other control you find on the Toolbox in Visual Studio. Like you put a text box inside a panel, same way you will put a User Control inside a panel.
staclite
April 11th, 2009, 10:14 AM
Ya I know How to put a user control like this but is there a way that I can change the user control inside my panel during the application is running when I click on different thing on my menu??
Thx for help it's really appreciate
Shuja Ali
April 11th, 2009, 01:21 PM
Ya I know How to put a user control like this but is there a way that I can change the user control inside my panel during the application is running when I click on different thing on my menu??
Thx for help it's really appreciate
I don't quite understand what you are trying to do.
A user control is just like any other control and you can use it just like any other control.
mariocatch
April 11th, 2009, 05:23 PM
Assuming you have 2 UserControls in your project. The following will switch out a Container's child control with a new one each time a button is clicked.
using System;
using System.Windows.Forms;
namespace DynamicUserControls
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
int mCurControl = 0;
private void button1_Click(object sender, EventArgs e)
{
this.groupBox1.Controls.Clear();
switch (mCurControl)
{
case 0:
case 2:
this.groupBox1.Controls.Add(new Control1());
mCurControl = 1;
break;
case 1:
this.groupBox1.Controls.Add(new Control2());
mCurControl = 2;
break;
}
}
}
}
staclite
April 12th, 2009, 08:06 PM
Thank you so much Mariocatch this make exactly what I wanted to do
JonnyPoet
April 13th, 2009, 11:01 AM
Ya I know How to put a user control like this but is there a way that I can change the user control inside my panel during the application is running when I click on different thing on my menu??
Thx for help it's really appreciateThe standard way to do this would be to use different Usercontrols and one and the same interface for the data for each usercontrol. Use a Bulider pattern for doing this. A Factory can be used to create and switch between which Usercontrol is built and is shown on screen. As you are using the same interface for all of the usercontrols which should able to be presented its easily to add / read data to / from that controls.
In fact I dont know whats your usercontrol contains. ( Dataaccess, database connection ...) The way already shown by mariocatch is a simple beginning if you have a simple situation. The patterns I mentioned are able to handle more complex situations too. If you have a very complex datahandling and different Usercontrols and you want to have an easy to maintainable code then google for Bridge pattern too.
codeguru.com
Copyright Internet.com Inc., All Rights Reserved.