5 Replies - 3401 Views - Last Post: 05 May 2011 - 08:06 AM Rate Topic: -----

#1 ispiro  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 27
  • Joined: 06-April 11

Showing a second form in the first formís window

Posted 04 May 2011 - 01:36 PM

How do you show a second form in the same window as the previous one?
Someone suggested having two panels and hiding the first and showing the second. But how do you design that? The panels overlap. (In design view)
Maybe there is a way that a form can use the same window as the previous one?
(I do know how to hide/show a panel/form.)
Is This A Good Question/Topic? 0
  • +

Replies To: Showing a second form in the first formís window

#2 tlhIn`toq  Icon User is offline

  • Xamarin Cert. Dev.
  • member icon

Reputation: 6507
  • View blog
  • Posts: 14,379
  • Joined: 02-June 10

Re: Showing a second form in the first formís window

Posted 04 May 2011 - 01:47 PM

A form is the window.
You don't show one form in the same window as another.

As for controls overlapping in Design View... So what? Make one visible=true and one visible=false. Then change those as you need to programmatically; perhaps when a button is clicked etc.

I usually make UserControls then put a panel on the form and swap which UserControl is in the panel.

This gives me a lot of flexibility because if I need to use the UserControl in an existing form I can. Or if I need it as it's own dialog I can make a form, then put the UserControl in it.


myPanel.Controls.Clear();
myPanel.Controls.Add(new ucLogInUserControl());


Form tempForm = new Form();
tempForm.Controls.Add(new ucSaveChangesUserControl());
tempForm.ShowDialog();


I think I did some of this in these tutorials. They should help.

Bulding an application - Part 1
Building an application - Part 2

View Postispiro, on 04 May 2011 - 02:36 PM, said:

I do know how to hide/show a panel/form.


I would recommend you start with "Hello World" just like the other million+ coders out there. Then work your way up to the more advanced tasks like this.

The problem with taking on large, complex tasks like this when you are new to coding is that
  • it will frustrate you to the point of quitting,
  • you don't know enough about coding to know where to start or in what direction to design your program
  • You risk learning via the 'Swiss cheese' method where you only learn certain bits and pieces for the one project but have huge holes in your education.



Standard resources, references and suggestions for new programmers.

I am going to guess that you are trying to teach yourself C# without much guidance, a decent book or without knowing where to look. Sometimes just knowing where to look can make all the difference. Google is your friend.
Search with either "C#" or "MSDN" as the first word: "MSDN Picturebox", "C# Custom Events", "MSDN timer" etc.

But honestly, just typing away and seeing what pops up in Intellisense is going to make your self-education take 20 years. You can learn by trying to reverse engineer the language through banging on the keyboard experimentation - or you can learn by doing the tutorials and following a good "How to learn C#" book.

Free editions of Visual Studio 2010

May I suggest picking up a basic C# introductory book? There are so many great "How do I build my first application" tutorials on the web... There are dozens of "Learn C# in 21 days", "My first C# program" type books at your local book seller or even public library.

D.I.C. C# Resource page Start here
Intro to C# online tutorial then here...
C# control structures then here.
MSDN Beginner Developer video series
MSDN video on OOP principals, making classes, constructors, accessors and method overloading
MSDN Top guideline violations, know what to avoid before you do it.

The tutorials below walk through making an application including inheritance, custom events and custom controls.
Quick and easy custom events
Bulding an application - Part 1
Building an application - Part 2
Passing values between forms/classes

Working with environmental variables

Debugging tutorial
Debugging tips
Great debugging tips
It still doesn't work, article

Build a Program Now! in Visual C# by Microsoft Press, ISBN 0-7356-2542-5
is a terrific book that has you build a Windows Forms application, a WPF app, a database application, your own web browser.

C# Cookbooks
Are a great place to get good code, broken down by need, written by coding professionals. You can use the code as-is, but take the time to actually study it. These professionals write in a certain style for a reason developed by years of experience and heartache.

Microsoft Visual Studio Tips, 251 ways to improve your productivity, Microsoft press, ISBN 0-7356-2640-5
Has many, many great, real-world tips that I use all the time.

Writing a text file is always one of the first things people want to do, in order to store data like high-scores, preferences and so on
Writing a text file tutorial.
Reading a text file tutorial.


These are just good every-day references to put in your bookmarks.
MSDN C# Developers Center with tutorials
Welcome to Visual Studio

Have you seen the 500+ MSDN Code Samples? They spent a lot of time creating samples and demos. It seems a shame to not use them.

Let me also throw in a couple tips:
  • You have to program as if everything breaks, nothing works, the cyberworld is not perfect, the attached hardware is flakey, the network is slow and unreliable, the harddrive is about to fail, every method will return an error and every user will do their best to break your software. Confirm everything. Range check every value. Make no assumptions or presumptions.
  • Take the extra 3 seconds to rename your controls each time you drag them onto a form. The default names of button1, button2... button54 aren't very helpful. If you rename them right away to something like btnOk, btnCancel, btnSend etc. it helps tremendously when you make the methods for them because they are named after the button by the designer.
    btnSend_Click(object sender, eventargs e) is a lot easier to maintain than button1_click(object sender, eventargs e)
  • You aren't paying for variable names by the byte. So instead of variables names of a, b, c go ahead and use meaningful names like Index, TimeOut, Row, Column and so on

This post has been edited by tlhIn`toq: 04 May 2011 - 01:48 PM

Was This Post Helpful? 0
  • +
  • -

#3 ispiro  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 27
  • Joined: 06-April 11

Re: Showing a second form in the first formís window

Posted 04 May 2011 - 02:08 PM

Quote

As for controls overlapping in Design View... So what? Make one visible=true and one visible=false. Then change those as you need to programmatically; perhaps when a button is clicked etc.


a: Thanks for the reply.
b: If you make it visible=false , it doesn't hide it in Design View. So how can you see each separately?

This post has been edited by ispiro: 04 May 2011 - 02:10 PM

Was This Post Helpful? 0
  • +
  • -

#4 Curtis Rutland  Icon User is offline

  • (╯į□į)╯︵ (~ .o.)~
  • member icon


Reputation: 5101
  • View blog
  • Posts: 9,283
  • Joined: 08-June 10

Re: Showing a second form in the first formís window

Posted 04 May 2011 - 02:12 PM

Again, who cares about design view? Design view isn't important at runtime.

If you mean you can't see the panel to design it, here's what you should do:

Instead of designing your UI around one space, make UserControls that are basically a functional unit. You can design each separately, then just add as a single unit to the panel.

Also, have you considered using a TabControl? That's usually the answer for 90% of these questions.
Was This Post Helpful? 0
  • +
  • -

#5 tlhIn`toq  Icon User is offline

  • Xamarin Cert. Dev.
  • member icon

Reputation: 6507
  • View blog
  • Posts: 14,379
  • Joined: 02-June 10

Re: Showing a second form in the first formís window

Posted 04 May 2011 - 02:37 PM

View Postispiro, on 04 May 2011 - 03:08 PM, said:

Quote

As for controls overlapping in Design View... So what? Make one visible=true and one visible=false. Then change those as you need to programmatically; perhaps when a button is clicked etc.


a: Thanks for the reply.
b: If you make it visible=false , it doesn't hide it in Design View. So how can you see each separately?


You don't. If it hid it in Design View then how could you ever edit it again? Or even select it?

Notice in the toolbar the Send to back and Send to front buttons?
You can select the one on top and send it to the back so you can see and edit the other panel.
Attached Image

And as an FYI: If you right-click on overlaying controls you can choose which buried control to select - then move it with the arrow keys.

I will point out that you now have two experts suggesting you DON'T follow this route but instead make UserControls. The tutorials I linked to you in response #2 really will save you a lot of headache.

This post has been edited by tlhIn`toq: 04 May 2011 - 02:38 PM

Was This Post Helpful? 1
  • +
  • -

#6 ispiro  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 27
  • Joined: 06-April 11

Re: Showing a second form in the first formís window

Posted 05 May 2011 - 08:06 AM

Thanks
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1