In MdiParent toolstripmenuItem, I'm writing the code to show all the windows in cascade or Tile Horizontal style.
My code is:
this.LayoutMdi(MdiLayout.Cascade);
this.LayoutMdi(MdiLayout.TileHorizontal);
This code will work in mdi parent only. But now I'm using a Split container in my Parent Form. In Panel1 I have buttons to Show the Form. In Panel2 My Forms will display, as:
Forms.paymentPaid paidFm = new SalesandPurchases.Forms.paymentPaid();
paidFm.MdiParent = this;
paidFm.Left = (this.myPanel.Width - paidFm.Width) / 2;
paidFm.Top = (this.myPanel.Height - paidFm.Height) / 2;
myPanel.Controls.Add(paidFm);
paidFm.Show();
Now Because of my Split Container my code( this.LayoutMdi(MdiLayout.Cascade)) is not working for cascade the windows in Panel2. Please tell me any other way.
By merely changing the container of your controls without moving the MDI container itself will not work - as you have experienced. I think what you will need to do is to move your MDI container to the panel in which you want to display the child windows (panel 2). Basically you now want to have what you had before in the main window of your form in panel 2 of your split container.
I hope this helps.
Related
I have an MDI app, and I have recently added a new control to the MDI container, which covers the client area (the area where the children appear and function). The trouble is, when they try to maximise their forms, it appears behind the sidebar:
Original form for comparison (to see the overlap)
I know that I can restrict the total size of each form that gets maximised, using the Form.MaximumSize property, however I'm not sure how to set the x/y location of the form to sit next to the sidebar.
I could use the side panel as a marker, i.e. x = sidepanel.Width because that will never change, but I don't know how to apply that to a maximised form.
Alternatively, is it possible to give the sidebar the same behaviour as the menu bar? That is - the menu bar is not considered to be in the client area; so when a form is maximised it will not overlap the child form?
Ok, so after some fiddling around, I found the main problem was that since I was adding the control dynamically, control of it was a bit difficult. So instead I did this:
Added a panel (using the forms designer) to the MDI Parent
Set the Dock property to "left"
Added the custom control dynamically to the panel:
SidePanel = new Menu_SidePanel();
SidePanel.Location = new System.Drawing.Point(0, 0);
SidePanel.Anchor = (AnchorStyles.Top | AnchorStyles.Bottom | AnchorStyles.Left);
panel1.Controls.Add(SidePanel);
Now, because the panel has been added to, and "docked" on the Parent form, the rest of the child forms, when maximised, use the Side Panel as another boundary.
I'm populating a self-made Windows Explorer which simulate the Microsoft Windows Explorer. This is the layout of my Windows Form:
What I want it to be is:
But when I maximized the windows, it looks like this:
The problem is that the treeView's width got increased, too. How to stop that ?
Any ideas? I've tried many ways but nothing works.
Try to add a second splitcontainer around the groupbox and the splitcontainer you already have. Then set the panel at the bottom as the fixed panel.
You can set the SplitContainer.FixedPanel property to disable automatic resizing of one of the panels. This way the specified panel will remain the same width/height even when the container itself is resized.
You could use Anchoring (each control will have that in the Properties menu), and select what you want it "anchored" to. That should allow your controls to stetch to fit the form.
It can be fiddly, so you have to anchor each control and think about how to wish to set it. EG to make a control extend if you increase the height of your form, click the top and bottom anchors.
I have a WinForms application which has two panels which individually contain a usercontrol component (one in each panel). How ever, because both panels are the same size and in the same location, the top most panel becomes a child of the other panel. I want to be able to hide one panel and then show the other panel:
this.panel1.visibile = false;
this.panel2.visibile = true;
But when I hide panel1, the second panel is hidden as well.
How can I make panel2 a non-child of panel1?
I like to keep things simple because I'm new to C# Programming.
This is a common accident in the designer. Dropping the second panel on top of the first one will make it a child of the first panel. Two basic strategies to fix this:
View + Other Windows + Document Outline. Click the second panel in the list and drag it to the form. You'll need to fix up the Location property by hand by typing its value in the Property window.
Keep the upper left corner of the second panel just a bit to the left or top of the first panel. Put it in the right place in the form's constructor by assigning its Location property after the InitializeComponent() call.
Check this answer for a control that works well at design time and lets you easily flip panels at runtime.
The designer will do this automatically because it assumes that when you drag one control over another, you want to make it a child of that control.
What I usually do to get around this is to create the control in a different place on the form, and then use the properties to manually match the positions of sizes of the two controls.
If you imagine a win form with a line drawn vertically down the middle. On the left i have a graph, and when you click the graph certain forms open on the right in an mdi type panel.
I am trying to figure out how to logically get this to look like a proper application should but am failing!
The whole form loads in a maximised view. I first set the panel width to 0 then when i add a form i check if the panels width is less than the forms, if it is then change the panels width to that of the forms.
This doesn't look great tho tbh, resizing makes strange things happen and i see a lot of grey. Does anyone have any ideas?
Use a SplitContainer on your main form. Ensure it's Dock property is set to Fill
Put your graph stuff on the left panel, and your other stuff on the right side.
When creating a MDI parent, the entire "inside" of the form is made the MDI region.
If you add a menustrip to the MDI parent, the MDI region is scaled down a bit to make room for the menustrip.
But if you add a panel to the top of the MDI parent, the entire inside is still the MDI region. Which means that you can move MDI children up behind the panel, and hide their title line. If you move MDI children behind a menustrip, scrollbars appear, and you can scroll higher up to access the title line. But the scrollbars doesn't appear when you are using a panel instead of a menustrip. Because the MDI region doesn't know about the panel, I suppose.
How can I scale the MDI region to start below a given Y value?
Well the short of it is you can't modify the MDI parent/container window in .Net. The window is still there and you can find it with Win32 apis if you really desire.
However, what you describe as your goal is doable. Since there isn't any code I can't tell what your doing wrong, but the following demonstrates this working:
public class Form1 : Form
{
static void Main(string[] args) { Application.Run(new Form1()); }
public Form1()
{
this.IsMdiContainer = true;
Panel test = new Panel();
test.Dock = DockStyle.Top;
test.Height = 100;
this.Controls.Add(test);
Form child = new Form();
child.MdiParent = this;
child.Text = "Child";
child.Show();
}
}
If csharptest.net is right, and one cannot change the MDI region, I've found two ways to do it:
Add multiple MenuStrip objects (each of those moves the MDI region 24 pixels lower on the parent form).
Use the LocationChanged event of the MDI children, and manually check that their Y value is larger than the border you wish to keep them below.