Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. problems with panals

problems with panals

Scheduled Pinned Locked Moved C#
helpcsharpquestion
8 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • R Offline
    R Offline
    Rmokkenstorm
    wrote on last edited by
    #1

    I have a problem. On my form (mainform) is use a panal wich should load another form (form1) now i placed the panal en he should load the form1 when the mainform loads. but i get this error: Top-level control cannot be added to a control. i don't know what to do whit this error. public partial class main : Form { Form1 from1; public main() { InitializeComponent(); } internal Form1 From1 { get { if (this.from1 == null) { this.from1 = new Form1(); this.panel1.Controls.Add(this.from1); this.from1.Dock = DockStyle.Fill; } return this.from1; } } private void main_Load(System.Object sender, System.EventArgs e) { this.FFrom1(); } internal void FFrom1() { this.From1.Visible = true; } this is my code i use visual C# 2005 and offcourse writing in C# can anyone help me?

    R 1 Reply Last reply
    0
    • R Rmokkenstorm

      I have a problem. On my form (mainform) is use a panal wich should load another form (form1) now i placed the panal en he should load the form1 when the mainform loads. but i get this error: Top-level control cannot be added to a control. i don't know what to do whit this error. public partial class main : Form { Form1 from1; public main() { InitializeComponent(); } internal Form1 From1 { get { if (this.from1 == null) { this.from1 = new Form1(); this.panel1.Controls.Add(this.from1); this.from1.Dock = DockStyle.Fill; } return this.from1; } } private void main_Load(System.Object sender, System.EventArgs e) { this.FFrom1(); } internal void FFrom1() { this.From1.Visible = true; } this is my code i use visual C# 2005 and offcourse writing in C# can anyone help me?

      R Offline
      R Offline
      Robert Rohde
      wrote on last edited by
      #2

      Set the TopLevel property of your Form to false prior to adding it.

      R 1 Reply Last reply
      0
      • R Robert Rohde

        Set the TopLevel property of your Form to false prior to adding it.

        R Offline
        R Offline
        Rmokkenstorm
        wrote on last edited by
        #3

        thanks for your fast reply where acactly should i'de be doing that. on the Mainform (the form with the panal) or Form1 (the form that's load) toplevel = false; or something like that was the code but where should i put this. before the panal loads or somewhere else?

        R 1 Reply Last reply
        0
        • R Rmokkenstorm

          thanks for your fast reply where acactly should i'de be doing that. on the Mainform (the form with the panal) or Form1 (the form that's load) toplevel = false; or something like that was the code but where should i put this. before the panal loads or somewhere else?

          R Offline
          R Offline
          Robert Rohde
          wrote on last edited by
          #4

          In the getter of Form1 right before adding it to the Panel:

          internal Form1 From1
          {
          get
          {
          if (this.from1 == null)
          {
          this.from1 = new Form1();

               this.from1.TopLevel = false; //HERE!!!!
               this.panel1.Controls.Add(this.from1);
               this.from1.Dock = DockStyle.Fill;
            }
          
            return this.from1;
          

          }
          }

          R 1 Reply Last reply
          0
          • R Robert Rohde

            In the getter of Form1 right before adding it to the Panel:

            internal Form1 From1
            {
            get
            {
            if (this.from1 == null)
            {
            this.from1 = new Form1();

                 this.from1.TopLevel = false; //HERE!!!!
                 this.panel1.Controls.Add(this.from1);
                 this.from1.Dock = DockStyle.Fill;
              }
            
              return this.from1;
            

            }
            }

            R Offline
            R Offline
            Rmokkenstorm
            wrote on last edited by
            #5

            oh great that works but can you give one last advise? now if i select a row or something he opens a new form but this he opens outside the panal? how can i do this?

            R 1 Reply Last reply
            0
            • R Rmokkenstorm

              oh great that works but can you give one last advise? now if i select a row or something he opens a new form but this he opens outside the panal? how can i do this?

              R Offline
              R Offline
              Robert Rohde
              wrote on last edited by
              #6

              Hi, sorry but I don't understand your question. What rows are you referring to? If you wish to show a Form normally just leave TopLevel to true and call either Show or ShowDialog on it.

              R 1 Reply Last reply
              0
              • R Robert Rohde

                Hi, sorry but I don't understand your question. What rows are you referring to? If you wish to show a Form normally just leave TopLevel to true and call either Show or ShowDialog on it.

                R Offline
                R Offline
                Rmokkenstorm
                wrote on last edited by
                #7

                inside the Form1 there is for example a data grid.. with a selectrow command he opens another form with the details of the selected row. this form should be opend inside the panal also

                R 1 Reply Last reply
                0
                • R Rmokkenstorm

                  inside the Form1 there is for example a data grid.. with a selectrow command he opens another form with the details of the selected row. this form should be opend inside the panal also

                  R Offline
                  R Offline
                  Robert Rohde
                  wrote on last edited by
                  #8

                  First of all you should consider creating user controls instead of forms all the time. Then its the same procedure with any form you have. Set TopLevel to false and then you can insert it into any panel you like. If you want to exchange the contents of a panel then call panel.Controls.Clear() prior to adding the other form. If you want to have several items in one panel you can either set them location and size programmatically or (better) just create two panels (one holding formA and one holding formB).

                  1 Reply Last reply
                  0
                  Reply
                  • Reply as topic
                  Log in to reply
                  • Oldest to Newest
                  • Newest to Oldest
                  • Most Votes


                  • Login

                  • Don't have an account? Register

                  • Login or register to search.
                  • First post
                    Last post
                  0
                  • Categories
                  • Recent
                  • Tags
                  • Popular
                  • World
                  • Users
                  • Groups