I’m trying to design a feature in my C# application. If the user has multiple forms opened, like for example 3 forms. I want to use the click event to position the 3 forms side to side fitting the screen. I can do that if I determined 3 forms for the incident. But I want to apply the feature towards (any) multiple opened forms.. Any help will be much appreciated. Thank you!
Use MDI container for solving this problem,
for example,
Create main form and set it's IsMdiContainer property value to "true",
for adding child forms you may use like this code:
var frm = new ChildForm();
frm.MdiParent = this;
frm.Show();
For changing child forms position:
var a = 0;
var b = 0;
foreach (var form in this.MdiChildren)
{
form.Location = new Point(a, b);
a = a + form.Width + 5;
}
result after click "Side to side position" button:
Related
I want to create a TreeView that contains complex forms of EmployeeNode as nodes. When you add the node I will call InitializeComponent(). So that the expected result will be something like
Or codewise:
EmployeeNode EMPND = new EmployeeNode(new Employee());
EMPND.Draw();
VisualTree.Nodes.Add(EMPND);
//Draw (at EmployeeNode form class)
public void Draw()
{
InitializeComponent();
}
Is this possible?
edit
If this cant be done using TreeView, I am open to hear about other ways to store forms, other then TreeView, that offers similar hierarchy - based WinForm visual solutions (maybe a generic version?)
Set the TopLevel property of the form you want to add as false.
var form = new Form { TopLevel = false };
treeView.Controls.Add(form);
form.Show();
I have two forms that I am trying to display on a master form using a tabControl element in C#.
I have had no luck so far. How does one go about it?
In your "Child" form, put all your control in a Panel (let's call it "movingPanel") with its Dock property set to Fill and its Modifiers property set to internal. After creating, the child form in the master form, simply do:
theChildForm.movingPanel.Parent = tabControl1.TabPages["The_tabPage_Name"] ;
If you want to host your form into a tab page I think this part of code helps :
newForm.TopLevel = false;
newForm.ControlBox = false;
newForm.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None;
newForm.Dock = DockStyle.Fill;
var newTab = new TabPage()
newTab.Controls.Add(newForm);
this.MainTabControl.TabPages.Add(newTab);
this.MainTabControl.SelectedTab = newTab;
newForm.Show();
I hope this is what you are looking for.
Well, I'm writing a simple application which will have multiple forms inside it. Now say one form will be the base window i.e. the parent and all other will be child of it. So for this I'm trying to opening the child window by below method.
//Inside class FormBaseWindow
private void linkLabelReservation_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
{
Point childLocation = new Point(this.Location.X + 100, this.Location.Y + 120);
FormReservation formReserve = new FormReservation();
formReserve.Location = childLocation;
formReserve.MdiParent = this.MdiParent;
formReserve.Show();
}
And also set the IsMdiContainer attribute of FormBaseWindow class to true. Now the things is, I want to have feel like dragging the FormBaseWindow window will drag the whole thing including the child window inside it. Currently once I click on the FormBaseWindow window its coming foreground and the child is going behind it.
In MFC I was able to do it by setting the window style Child and set it as a child window, but here the story is bit different.
I'm using C# Winforms with VS 2012.
Change :
formReserve.MdiParent = this.MdiParent;
to
formReserve.MdiParent = this;
NB: You should use
formReserve.MdiParent = this.MdiParent;
when you open a child form from another child form to make it under the same MdiParent.
I created a Form with menu strip. When I click on a menu item I want to open a new From in my main From.
It works but a part of the form is behind the menu like this :
my code :
WindowDossierProtection wdPr = new WindowDossierProtection();
wdPr.TopLevel = false;
this.Controls.Add(wdPr);
wdPr.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None;
wdPr.Dock = DockStyle.Fill;
wdPr.Show();
Can you help me ? thanks !!
Use BringToFront() to get your desired result:
WindowDossierProtection wdPr = new WindowDossierProtection();
wdPr.TopLevel = false;
this.Controls.Add(wdPr);
wdPr.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None;
wdPr.Dock = DockStyle.Fill;
wdPr.BringToFront();
wdPr.Show();
Do you use Visual Studio or something else?
This can be easily done by the Document Outline.
In Visual Studio go to :
View /
Other Windows /
Document Outline
Or use the shortcut:
Ctrl+W, U
Then, choose your form (in design view).
In the Document Outline window you will see all your controls and the order that exist in your form.
You simply have to drag your menuStrip in the end. (After your new form control)
And voila.
(I use VS2010)
All, I have a WinForms MDI control and in it I dock several child windows. When I first did this I managed (somehow) to get rid of the window list (shown above the tabbed forms below)
I am not talking about the double window menu (on the right) I know that this is due to a bug in the WinForms control and that if you add MdiChild elements in the Load event instead of the Constructor, this behaviour resolves itsef (see this post for details).
Here I am talking about the menu strip itself, I don't want it! How do I get rid of it? Any advice is much appreciated...
Note: I am adding MdiChild forms in the following way:
foreach (Form mdiChild in MdiChildForms)
{
mdiChild.MdiParent = this;
mdiChild.Show();
}
where MdiChildForms is a List<Form>.
Here is the possible solution:
public MainForm() {
IsMdiContainer = true;
InitializeComponent();
this.MainMenuStrip = new MenuStrip(); // create our own menu strip
this.MainMenuStrip.Visible = false;
}