Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

C# - Joining Forms Together.... 1

Status
Not open for further replies.

TotalInsanity

Programmer
Oct 18, 2006
20
GB
Hey All.

I am new here so I'll ssay Hi!

I could do with some help here with c# as i am new to this language.

Can anyone explain how I can join two forms together?

By this I mean Take the Main Form (Form1) and place a button component on it.

In the click event, I would like to pop up another form (form2) but join one edge of it to one of the edges of the first form...

So If I move the first form around the screen, the second will move with it joined to the first ones edge...

If you can can you point me in the right direction or provide a simple (ish) example for me...

I would very much appeciate your advanced knowledge!!
 
There's 2 good ways to do this that I can think of...

The first option is better if you can get away without using a second form.

Instead of using a second form - turn the form into a usercontrol and add the usercontrol to a specified point on the form (example: usercontrol1.Location = new Point(100,100)) and then just change the size of your form to show that usercontrol when needed.

You will probably find that this works best.



If you really want to use separate forms then I would attach to the LocationChanged event of the form. When the location moves you simply have to tell the second form how far to move off its original location.

In terms of positioning the second form initially, you have to say:

private void button1_click(object sender, EventArgs e)
{
Form2 frm = new Form2();

frm.StartPosition = FormStartPosition.Manual;
frm.Location = new Point(this.Location.X + this.Width,
this.Location.Y); //this will attach to the right edge of the form

frm.Show();
}


I hope that gets you started.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top