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. Open Form Incide another Form

Open Form Incide another Form

Scheduled Pinned Locked Moved C#
data-structuressalestutorialquestion
13 Posts 7 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.
  • C Offline
    C Offline
    CristianConrads
    wrote on last edited by
    #1

    Hi I create a main Form with a splitContainer In the Left panel I put a Tree View In the Right panel I like to open diferent forms according to de selected information in the treeview. Example Tre view - Item - Customer xxx When double click on on this customer a new CustomerFor with customer details open in Right panel If anoter customer yyy is selected a second CustomerForm open in the same panel A sort of tabContol cold be use to swich between Customer xxx and Customer yyy I try with MDE but I dont know hot to restrict the opening of the Child forms to the right panel of the splitContainer or anoder object capable of containing Forms. any clue?

    H P L 0 L 6 Replies Last reply
    0
    • C CristianConrads

      Hi I create a main Form with a splitContainer In the Left panel I put a Tree View In the Right panel I like to open diferent forms according to de selected information in the treeview. Example Tre view - Item - Customer xxx When double click on on this customer a new CustomerFor with customer details open in Right panel If anoter customer yyy is selected a second CustomerForm open in the same panel A sort of tabContol cold be use to swich between Customer xxx and Customer yyy I try with MDE but I dont know hot to restrict the opening of the Child forms to the right panel of the splitContainer or anoder object capable of containing Forms. any clue?

      H Offline
      H Offline
      Henry Minute
      wrote on last edited by
      #2

      I do not know of a way to constrain a form within another form. I don't think that it is possible in C#, perhaps someone with more knowledge will respond and let you know. However, what you can do is build a 'customer' control. Add a new User Control to your project and design it like you would a form. Add this control to the right panel. Then, when the TreeView is clicked, just fill whatever controls you have put on your 'customer' control with the data for that customer. You can then have a separate form just containing the new control, for occasions when it is more appropriate to display it as a form.

      Henry Minute Do not read medical books! You could die of a misprint. - Mark Twain Girl: (staring) "Why do you need an icy cucumber?" “I want to report a fraud. The government is lying to us all.”

      T C 2 Replies Last reply
      0
      • C CristianConrads

        Hi I create a main Form with a splitContainer In the Left panel I put a Tree View In the Right panel I like to open diferent forms according to de selected information in the treeview. Example Tre view - Item - Customer xxx When double click on on this customer a new CustomerFor with customer details open in Right panel If anoter customer yyy is selected a second CustomerForm open in the same panel A sort of tabContol cold be use to swich between Customer xxx and Customer yyy I try with MDE but I dont know hot to restrict the opening of the Child forms to the right panel of the splitContainer or anoder object capable of containing Forms. any clue?

        P Offline
        P Offline
        Peter_Weber
        wrote on last edited by
        #3

        Hey Christian, I am having exactly the same problem. I use a SplitContainer and and have placed a TreeView control inside. In the right side of the split container, one of five different Forms shall be loaded, depending on what's selected in the TreeView. Up to now, I unfortunately have not found a solution, but I'm new to C#, so this does not mean anything ;-) "SubForms" even work in LabVIEW, so I would be very amazed, if C# would be unable to do the same... Peter

        C 1 Reply Last reply
        0
        • P Peter_Weber

          Hey Christian, I am having exactly the same problem. I use a SplitContainer and and have placed a TreeView control inside. In the right side of the split container, one of five different Forms shall be loaded, depending on what's selected in the TreeView. Up to now, I unfortunately have not found a solution, but I'm new to C#, so this does not mean anything ;-) "SubForms" even work in LabVIEW, so I would be very amazed, if C# would be unable to do the same... Peter

          C Offline
          C Offline
          CristianConrads
          wrote on last edited by
          #4

          I have seen this in 3P Component, I think it was .Net Bar But this is out of my budget, So I'm trying to develop a solution with the component that come with C#. If I find something I let you know. Cristian

          P 1 Reply Last reply
          0
          • H Henry Minute

            I do not know of a way to constrain a form within another form. I don't think that it is possible in C#, perhaps someone with more knowledge will respond and let you know. However, what you can do is build a 'customer' control. Add a new User Control to your project and design it like you would a form. Add this control to the right panel. Then, when the TreeView is clicked, just fill whatever controls you have put on your 'customer' control with the data for that customer. You can then have a separate form just containing the new control, for occasions when it is more appropriate to display it as a form.

            Henry Minute Do not read medical books! You could die of a misprint. - Mark Twain Girl: (staring) "Why do you need an icy cucumber?" “I want to report a fraud. The government is lying to us all.”

            T Offline
            T Offline
            Trooks
            wrote on last edited by
            #5

            Henry is definitely on the right track. Think of forms as layouts. Which in turn have panels. You then create a user control for the "subform" and load it into the right panel of the main form. This works extremely well and now you can decouple your views and reuse them in different layouts and containers. I hope that this helps you.

            1 Reply Last reply
            0
            • C CristianConrads

              I have seen this in 3P Component, I think it was .Net Bar But this is out of my budget, So I'm trying to develop a solution with the component that come with C#. If I find something I let you know. Cristian

              P Offline
              P Offline
              Peter_Weber
              wrote on last edited by
              #6

              Ok, that sounds fine. Thank you! Peter

              1 Reply Last reply
              0
              • H Henry Minute

                I do not know of a way to constrain a form within another form. I don't think that it is possible in C#, perhaps someone with more knowledge will respond and let you know. However, what you can do is build a 'customer' control. Add a new User Control to your project and design it like you would a form. Add this control to the right panel. Then, when the TreeView is clicked, just fill whatever controls you have put on your 'customer' control with the data for that customer. You can then have a separate form just containing the new control, for occasions when it is more appropriate to display it as a form.

                Henry Minute Do not read medical books! You could die of a misprint. - Mark Twain Girl: (staring) "Why do you need an icy cucumber?" “I want to report a fraud. The government is lying to us all.”

                C Offline
                C Offline
                CristianConrads
                wrote on last edited by
                #7

                I think is a good idea But very complex to maintain We are all use of this kind of interface The IDE work exactly as I want: Multiple pages, im my case Forms The tree view is the solution explorer. How could be this so dificult to replicate. :( Cristian

                H 2 Replies Last reply
                0
                • C CristianConrads

                  Hi I create a main Form with a splitContainer In the Left panel I put a Tree View In the Right panel I like to open diferent forms according to de selected information in the treeview. Example Tre view - Item - Customer xxx When double click on on this customer a new CustomerFor with customer details open in Right panel If anoter customer yyy is selected a second CustomerForm open in the same panel A sort of tabContol cold be use to swich between Customer xxx and Customer yyy I try with MDE but I dont know hot to restrict the opening of the Child forms to the right panel of the splitContainer or anoder object capable of containing Forms. any clue?

                  L Offline
                  L Offline
                  Lost User
                  wrote on last edited by
                  #8

                  A form inside a form;

                  Form newForm = new Form();
                  newForm.TopLevel = false;
                  newForm.Parent = this;
                  newForm.Visible = true;
                  newForm.Location = new Point(10, 10);
                  this.Controls.Add(newForm);
                  

                  Is this what you're after? Happy Programming :)

                  I are troll :)

                  1 Reply Last reply
                  0
                  • C CristianConrads

                    Hi I create a main Form with a splitContainer In the Left panel I put a Tree View In the Right panel I like to open diferent forms according to de selected information in the treeview. Example Tre view - Item - Customer xxx When double click on on this customer a new CustomerFor with customer details open in Right panel If anoter customer yyy is selected a second CustomerForm open in the same panel A sort of tabContol cold be use to swich between Customer xxx and Customer yyy I try with MDE but I dont know hot to restrict the opening of the Child forms to the right panel of the splitContainer or anoder object capable of containing Forms. any clue?

                    0 Offline
                    0 Offline
                    0x3c0
                    wrote on last edited by
                    #9

                    Perhaps you could use the NativeWindow class, passing a CreateParams structure with its Parent property set to the Handle property of the right handle Panel. Then, display the form and use the SetParent PInvoke call to make it a child window of the parent Pseudocode:

                    NativeWindow wnd = new NativeWindow(new CreateParams()
                    {
                    Parent = rightHandPanel.Handle,
                    Height = rightHandPanel.Height,
                    Width = rightHandPanel.Width,
                    X = Y = 0
                    }
                    Form display = formYouWantToDisplay;

                    wnd.CreateHandle();
                    display.Show(wnd); //This works because NativeWindow implements IWin32Window

                    This would require quite a bit of research to work properly I think. Are you sure you don't just want to have an MDI parent, and dock a panel containing a treeview to the left hand side?

                    modified on Sunday, March 1, 2009 1:54 PM

                    1 Reply Last reply
                    0
                    • C CristianConrads

                      I think is a good idea But very complex to maintain We are all use of this kind of interface The IDE work exactly as I want: Multiple pages, im my case Forms The tree view is the solution explorer. How could be this so dificult to replicate. :( Cristian

                      H Offline
                      H Offline
                      Henry Minute
                      wrote on last edited by
                      #10

                      If you are absolutely determined to do 'Form Docking', it can be done. But not in pure c#. A great deal of P/Invoke is required, to get this functionality. Take a look at this[^] for examples.

                      Henry Minute Do not read medical books! You could die of a misprint. - Mark Twain Girl: (staring) "Why do you need an icy cucumber?" “I want to report a fraud. The government is lying to us all.”

                      1 Reply Last reply
                      0
                      • C CristianConrads

                        I think is a good idea But very complex to maintain We are all use of this kind of interface The IDE work exactly as I want: Multiple pages, im my case Forms The tree view is the solution explorer. How could be this so dificult to replicate. :( Cristian

                        H Offline
                        H Offline
                        Henry Minute
                        wrote on last edited by
                        #11

                        I take back some of my last post. I have just read Eddy Vluggens response. This definitely CAN be done in pure c#. :) Very slight modification to his code

                        	private void btnForm\_Click(object sender, EventArgs e)
                        	{
                        		Form newForm = new Form();
                        		newForm.TopLevel = false;
                        		newForm.Parent = this;
                        		newForm.Visible = true;
                        		newForm.Location = new Point(10, 10);
                        		newForm.Size = new Size(this.ClientSize.Width - 20, this.ClientSize.Height - this.panel1.Height - 20);
                        		newForm.BackColor = Color.Bisque;
                        		newForm.FormBorderStyle = FormBorderStyle.None;
                        		this.Controls.Add(newForm);
                                    }
                        

                        getting rid of the border, to save you having to look it up if you weren't aware of it already.

                        Henry Minute Do not read medical books! You could die of a misprint. - Mark Twain Girl: (staring) "Why do you need an icy cucumber?" “I want to report a fraud. The government is lying to us all.”

                        1 Reply Last reply
                        0
                        • C CristianConrads

                          Hi I create a main Form with a splitContainer In the Left panel I put a Tree View In the Right panel I like to open diferent forms according to de selected information in the treeview. Example Tre view - Item - Customer xxx When double click on on this customer a new CustomerFor with customer details open in Right panel If anoter customer yyy is selected a second CustomerForm open in the same panel A sort of tabContol cold be use to swich between Customer xxx and Customer yyy I try with MDE but I dont know hot to restrict the opening of the Child forms to the right panel of the splitContainer or anoder object capable of containing Forms. any clue?

                          L Offline
                          L Offline
                          Luis Alonso Ramos
                          wrote on last edited by
                          #12

                          If you use MDI, you can't exactly control where the MdiClient (which is where MDI children are located) window goes. However, I would try this (I once tried something similar and it worked): 1. Create your main form 2. Set its IsMdiContainer property to true 3. Add a panel and dock it to the left of your main form. [EDIT: If you want a splitter, add it here and also dock it to the left. But don't add a SplitContainer, but an original Splitter[^] control.] 4. Add the TreeView and whatever else inside that panel When you create MDI children, they will be located inside the MDI client area, which will be to the right of your tree view. I hope this helps :)

                          Luis Alonso Ramos Intelectix Chihuahua, Mexico My Blog!

                          1 Reply Last reply
                          0
                          • C CristianConrads

                            Hi I create a main Form with a splitContainer In the Left panel I put a Tree View In the Right panel I like to open diferent forms according to de selected information in the treeview. Example Tre view - Item - Customer xxx When double click on on this customer a new CustomerFor with customer details open in Right panel If anoter customer yyy is selected a second CustomerForm open in the same panel A sort of tabContol cold be use to swich between Customer xxx and Customer yyy I try with MDE but I dont know hot to restrict the opening of the Child forms to the right panel of the splitContainer or anoder object capable of containing Forms. any clue?

                            C Offline
                            C Offline
                            CristianConrads
                            wrote on last edited by
                            #13

                            Hi evirione For any one interest in this Here I publish my solution Object in Form1 splitContainer1 tabControl1 (in the right panel of the splitContainer1) The tabControl does not have any page on design. The left panel I intent to put a treeView, but for this code, there is a button button1 (in the left panel of the splitContainer1) this is the code for the button click event

                              private void button1\_Click(object sender, EventArgs e)
                              {
                                 TabPage newTabPage = new TabPage("Form " + tabControl1.TabPages.Count);
                                 newTabPage.Size = new Size(tabControl1.Width, tabControl1.Height);
                                 Form2 newForm = new Form2(); 
                                 newForm.TopLevel = false; 
                                 newForm.Parent = this;
                                 newForm.Visible = true;
                                 newForm.Location = newTabPage.Location;
                                 newForm.Location = new Point(3, 3);
                                 newForm.Size = new Size(newTabPage.Width - 3, newTabPage.Height - 3); 
                                 newForm.FormBorderStyle = FormBorderStyle.None;
                                 newTabPage.Controls.Add(newForm);
                                 tabControl1.TabPages.Add(newTabPage);
                              }
                            

                            Becaus Microsoft does not provide the Tab control we all use in the IDE, that allow to close a tabpage with an X in the upper right corner, I have no alternative and just use a normal tabControl Now, in order to destroy the tabpage when closing the form created on each page. In Form2 I add a button, and the followin code.( this close the form and destroy the tab page.

                              private void button1\_Click(object sender, EventArgs e)
                              {
                                 TabPage tab = this.Parent as TabPage;
                                 TabControl tabControl = tab.Parent as TabControl;
                                 tabControl.TabPages.Remove(tab);
                                 this.Dispose();
                              }
                            

                            Hope this help Cristian Conrads

                            modified on Monday, March 2, 2009 7:05 PM

                            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