9 Replies - 3956 Views - Last Post: 05 June 2012 - 02:24 PM Rate Topic: -----

#1 Samms  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 12
  • Joined: 20-May 12

More forms in panel (this panel is in Form1)

Posted 04 June 2012 - 12:17 PM

Hi,
I have problem - I am making program where I have more forms (these forms are derived from Form2) in form (in panel in Form1). All forms derived from Form2 are activate. And by clicking outside forms derived from Form2 not deactivates these forms - as it is normally (when are forms free on your desktop). But I need normal behavior of these forms - so that was activated only one form derived from Form2. Most likely I can not do other thing than deactivated forms manually. But the method Deactivate() can not applicable. What do you advise? Thanks for any help!

Is This A Good Question/Topic? 0
  • +

Replies To: More forms in panel (this panel is in Form1)

#2 tlhIn`toq  Icon User is offline

  • Please show what you have already tried when asking a question.
  • member icon

Reputation: 5535
  • View blog
  • Posts: 11,861
  • Joined: 02-June 10

Re: More forms in panel (this panel is in Form1)

Posted 04 June 2012 - 02:13 PM

I advise you get someone else to translate your question into English.

What you have here makes little sense.

Perhaps a screen capture of your program with comments about what is wrong and an example from a program that does what you want.
Was This Post Helpful? 1
  • +
  • -

#3 Samms  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 12
  • Joined: 20-May 12

Re: More forms in panel (this panel is in Form1)

Posted 04 June 2012 - 09:11 PM

Into the panel I added Form2 - using this.panel1.Controls.Add(p); (p is new Form2) These Forms2 are creates by a user - number of Forms2 there may be infinite. All Forms2 in panel are activated. (If you do not understand what I mean - I mean method Activate() - later method Deactivate()) . By clicking outside these Formy2 these Formy2 are not deactivated (Method Deactivate()). Manualy I can not use method Deactivate() - I can use only method Activate(). Now - what I must do? Thanks.
Was This Post Helpful? 0
  • +
  • -

#4 tlhIn`toq  Icon User is offline

  • Please show what you have already tried when asking a question.
  • member icon

Reputation: 5535
  • View blog
  • Posts: 11,861
  • Joined: 02-June 10

Re: More forms in panel (this panel is in Form1)

Posted 05 June 2012 - 05:38 AM

What you are describing doesn't make sense.
You can't add a form to a panel. It will generate an error like this one.

Attached Image
Was This Post Helpful? 0
  • +
  • -

#5 Samms  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 12
  • Joined: 20-May 12

Re: More forms in panel (this panel is in Form1)

Posted 05 June 2012 - 05:53 AM

:) Therefore, you must do untrue the top level: this.p.TopLevel = false; My program working good - only all forms in panel is activate - i need normal behavior,...
Was This Post Helpful? 0
  • +
  • -

#6 Skydiver  Icon User is offline

  • Code herder
  • member icon

Reputation: 3589
  • View blog
  • Posts: 11,165
  • Joined: 05-May 12

Re: More forms in panel (this panel is in Form1)

Posted 05 June 2012 - 11:45 AM

View PostSamms, on 05 June 2012 - 05:53 AM, said:

:) Therefore, you must do untrue the top level: this.p.TopLevel = false; My program working good - only all forms in panel is activate - i need normal behavior,...


Then for correctness, you should not be using the Form control. You should be using the ContainerControl. That way you don't have to be playing games with the TopLevel property.
Was This Post Helpful? 1
  • +
  • -

#7 Samms  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 12
  • Joined: 20-May 12

Re: More forms in panel (this panel is in Form1)

Posted 05 June 2012 - 12:37 PM

OK - how exactly should I do it? Thanks.
Was This Post Helpful? 0
  • +
  • -

#8 Skydiver  Icon User is offline

  • Code herder
  • member icon

Reputation: 3589
  • View blog
  • Posts: 11,165
  • Joined: 05-May 12

Re: More forms in panel (this panel is in Form1)

Posted 05 June 2012 - 01:19 PM

The same way forms are built up using:
var form = new Form();
form.Controls.Add(...);
:



You would do the same:
var container = new ContainerControl();
container.Controls.Add(...);
:



Don't like to handwrite your controls? Use the VS forms designer to create a dummy form and then cut and paste the code from InitializeComponent(), as well as any event handlers you may have defined.
Was This Post Helpful? 0
  • +
  • -

#9 Skydiver  Icon User is offline

  • Code herder
  • member icon

Reputation: 3589
  • View blog
  • Posts: 11,165
  • Joined: 05-May 12

Re: More forms in panel (this panel is in Form1)

Posted 05 June 2012 - 01:24 PM

Or even easier, just right click on your project, Add>User Control... and then design away visually.

A UserControl derives from ContainerControl. Additionally, it should have the correct activation/deactivation behavior without you having to play tricks with Activate() and Deactivate() calls explicitly.
Was This Post Helpful? 1
  • +
  • -

#10 tlhIn`toq  Icon User is offline

  • Please show what you have already tried when asking a question.
  • member icon

Reputation: 5535
  • View blog
  • Posts: 11,861
  • Joined: 02-June 10

Re: More forms in panel (this panel is in Form1)

Posted 05 June 2012 - 02:24 PM

A UserControl is definitely the way to go. These tutorials should help you out.


Bulding an application - Part 1
Building an application - Part 2
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1