I have an application with a main form that acts as a sort of frame and an area inside the main form where I open other forms. These forms must not be closed ever so when a new one is opened I use this code to open it for the first time:
frm.WindowState = FormWindowState.Maximized;
frm.BringToFront();
And then if another form gets opened on top of that and I need to show it again I just use:
frm.Show();
The problem is when I open the form the first time its positioned perfectly and the borders line up nice. When I use frm.Show() to bring it back it moves it slightly to the left and down. Any clue why?
You should set the StartPosition property to 'manual' in form properties window
or
frm.StartPosition = System.Windows.Forms.FormStartPosition.Manual;
From your explanations, I understand you're using a parent form to contain MDI child forms (correct me if I'm wrong)
When a new MDI child form is shown, it is placed so that child forms are in "cascade", i.e. each child form is at the same position of the previous one plus an offset. When you hide a child form and show it again, the MDI container probably considers that it's a new child form, and it places accordingly...
I think you need to save the location of the child form before you hide it, so that you can restore it when you show it again
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.
When I set the main window's visibility to hidden, No icon is shown in taskbar, so I have no control over the window to show it again. I want for the application's icon to be visible even when I hide the window, and to show the window when I click it's button in the taskbar. (something like minimize behavior)
How can I achieve that using WPF and .Net 4.0 in C#?
Edit: I mean the icon in taskbar (usually in the left and middle of the horizontal taskbar) not the notifyicon in system tray.
So, based on "comments" section, what you are looking to do is minimize or hide a window but still show some windows or dialogues that the window opens. First if you want to keep your window in the task bar, you should minimize with:
this.WindowState = WindowState.Minimized
That can be called from anywhere within the form. As you mentioned, though, this will close hide any dialogues that have this window set as the parent. The key, then is to not use this window as the parent. Lets say your dialogues inherit from form. You want to use:
newWindow.Show();
I am guessing that you are calling "ShowDialog", which ties the window state to the parent window state. Try this out and hopefully it will help!
Edit
One more note: the same is actually true of MessageBoxes, but the way to control the parent form is with the first parameter of the MessageBox.Show() call. If you pass in a form as the first parameter, that will be the parent, otherwise the parent will not be set.
How to popup a child form when I click the button. I want to child winform to be in the centre of the screen and the whole background screen should be blurred. and a small close button should be visible in the right corner of the form. I have searched the web but found nothing.
Using Winforms.
Make a new windows form. it has a close button by default. Set it default position to center screen. Then on your button click.
Lets say your new form is Form2
Form2 frm = new Form2();
frm.ShowDialog();
it will not make the rest of screen blurred but user will not be able to do anything with it.
For blurry effect a workaround has been posted here
You can trigger event from click button like this
Form form1=new Form();
form1.show;
and after that to blurr the parent screen use opacity property of and increase or decrease it accord to your requirement.
you can also control the transparency of the child form using a timer and increase paacity with timer click it will make it more dynamic and interactive.
I have a parent form and some child forms. Each of the child form has an icon at the top and left of the form. I would like to discard those icons but when I click on the icon property, I can only browse another icon and not delete the existing one. For that reason I set the showIcon property in each child form to false and the icons are not visible any more on the forms. So far so good.
My problem is that when a child form is open and maximized, the icon is shown. I want to make it go away and unfortunately I didn't find a way to do this. Any suggestions?
Thanks!
EDIT: I added a screenshot of the form, the unwanted icon is shown above menu strip. I want it to go away. When child form is NOT maximized, the icon disappears.
I guess you need to create a custom form border.
Please check http://geekswithblogs.net/kobush/articles/CustomBorderForms3.aspx
When I maximize 1 MDI child form, all MDI child forms would be maximized too. Is it possible to have 1 form maximized and another one not?
Thanks in advance.
A maximized MDI child form should occupy the entire child area and so the state of the other children should not really matter as they are not visible.
If you want to see a maximized window with another smaller window in front of it, I think some kind of user interface with docking and floating panels would be a better choice. Something like the way it works in Visual Studio.
Creating custom MDI/Non-MDI functionality is very time consuming and frustrating work, and the end result can be confusing to users who are used to standard MDI.
Not possible. Only thing you can do is to set the window in front non MDI and taskbar = no
Yes, you CAN do this - use the API Call SetParent instead of setting .MDIParent.
The Maximized Form will need to be an MDI Child called with Child1.Show().
The non-Maximized Form will need to NOT be an MDI Child called with Form1.Show(this) or Form1.ShowDialog(this).