i want to make one form contain another form ;
For the sake of browsing different sub-forms in the same Parent Form using parent controls .
You can use a TabControl to group different controls together, however if you REALLY need to have a subform, you can use MDI forms.
This is a tabcontrol:
It basically has a groupbox for each individual tab, so you can add and remove as you please.
From the docs for tabcontrol:
A TabControl contains tab pages, which are represented by TabPage
objects that you add through the TabPages property. The order of tab
pages in this collection reflects the order the tabs appear in the
control. The user can change the current TabPage by clicking one of
the tabs in the control.
And MDI:
Multiple-document interface (MDI) applications allow you to display
multiple documents at the same time, with each document displayed in
its own window. MDI applications often have a Window menu item with
submenus for switching between windows or documents.
Solution is to set the parent form property
IsMdiContainer = true ;
and set child forms with
childForm.MdiParent = parentForm;
I believe that you are looking for TabControl in C#. This allows to to browse through different tabs in the same parent form. You may refer to TabControl in C# for more information.
Hope this helps.
Related
I've simply added a control to my form and now I can't even see it on the form. But it is still there. How can I find it?
In situations that it is not possible to simply click on design surface and select your control, you can select your control using either of these options:
Document Outline Window
You can open Document Outline Window using menu View → Other Windows → Document Outline Also using Ctrl+Alt+T shortcut.
The Document Outline is most useful when you need to put design focus on controls that are deeply embedded within other controls, or that might be hard to select using a mouse or the TAB key.
View the logical structure of a Form or a UserControl.
Put user input focus on deeply nested controls that may be hard to select on the Form itself or the UserControl itself.
Move controls from one parent to another parent.
Locate controls that may be visually hidden by other controls.
Propertie Window
You can open Propertie Window using menu View → Properties Window Also using F4 shortcut.
You can select the control form the drop-down which contains all controls.
Or use the Document Outline window. You can also drag your controls here if they were accidentally misplaced or if you want to change the order of the docked controls.
In WPF, since there is no MDI concept, I used a TabControl. But in WinForms with MDI, I could put two MDI Child forms side by side to compare some data. Resizing of the MDI Child is also possible. How can I achieve the same with WPF TabControl. I want the TabPage to undock as we can do in Visual Studio IDE and enable user to resize the child window. I am not permitted to use any third party tools or source code for this task. So can anyone guide me with example if possible?
So far, I have added a TabControl. I am adding/removing Tabs to/from the TabControl through MenuItem click. I have added a ContextMenu to the Tabs with an Undock MenuItem. When this is clicked, I am displaying the same UserControl which I used as the TabPage content, but with a title bar and a close button. Now I am stuck on adding the UserControl back to the tabs group.
I have got a control with a Splitcontainer added. I want to place
another forms on the second panel (Panel2). However, it is not possible to
set the MDIParent property of a brand new form to Panel2.
Thus, the question is - how can I set the SplitContainer's panel as the MDIParent for another controls?
Thank you in advance for the clues!
cheers
If you want to make Panel-Splitter-MdiClient Form see panel and MDI in c#
An MDIParent can only be another Form. What you need to do is set TopLevel to False on the child Form. Then you can add it to any control just like it was any other control (by adding it to the parent control's Controls collection). However, it won't work like it does in an MDI container (as in you won't be able to minimize or maximize it).
If your intent is to use the splitcontainer to load different subforms this may help. Instead of using WinForms, you could use classes derived from panels containing all the widgets that a normal WinForm would have. To display them, simply add them to your splitcontainer's Panel2 controls collection.
Some events and methods to keep in mind are:
subformPanel.ParentChanged (do some initialization and subscribe to any parent events)
subformPanel.ParentChanged (do some cleaning up and unsubscribe to parent events)
Parent.Controls.Remove (destroy the subformPanel)
I have thought of this idea where you could have a tab control on a form, but instead of defining each tabs controls before runtime, inherit or use another form's controls.
Basically a tab control is in place on the main form that has no tabs on it before runtime. When runtime comes along I want to create tabs, but the controls that would be on each tab would be from seperate already created forms.
Each form would be a seperate tab that had been created prior to runtime.
Is this possible? Is so, how?
Thanks in advance
EDIT
I'm using 3.5
first create a User Control and design it as you would a regular form, then add it to your TabControl.TabPages
TabPage page = new TabPage("Title");
page.Controls.Add(new CustomUserControl()); //your user control
this.tabControl1.TabPages.Add(page);
If all you'll be doing is copying controls from a TabControl on one form to a TabControl on another form:
Instantiate the form you want to copy from
Find the TabControl on that form
Iterate through Controls on the TabPages inside that TabControl
Add each Control you find in that collection to the tab(s) in the control you want to copy to
Close and Dispose of the form you created in step 1
Yes, it is possible. You have to add the controls onto the TabPage, then add the TabPage to the TabControl.TabPages
I have a WPF tabcontrol with 3 tabs. On the top of the first page is a scrollviewer with a couple buttons which make up a menu of common tasks (save, load etc). I would like this scroll viewer to appear at the top of every tab. Is it possible to do this without simply copying and pasting the code to every tab?
You can make a custom control that contains the UI and logic for the buttons, and then include that control on each tab. The best way to do this is to create a subclass of ScrollViewer, and in the XAML define each of the buttons. On each of your tab pages you can create and create an instance of your new subclass.
This will result in a different instance of your class on each page, but the logic for the buttons will only exist in the code once.
You could implement the scroll viewer and buttons outside and on top of the tabcontrol.