window state maximize not working - c#

I am opening a form in a mdi parent. I show the form in the parent and the window state of the new form in the designer is maximized. For some reason, the form appears in the top left corner of the mdi parent, and the control box is way over to the right as if it was maximized, but the size of the window is not filling up the screen. So the behavior is as if it were maximized, but it is not filling the screen. What should I do?
I'm using C#.Net Winform.

Set your child form's window state to maximized.
This will maximize your form.
childForm.WindowState = FormWindowState.Maximized;
You can do this on load of your MdiParent form, or whenever you open show this child form.

Make sure your MdiChilds MaximumSize Property is not set. If it is it will look like this, which looks like what you have described in your question.

Coming in late, but I too am having this problem and so far nobody's answered why it's happening. I found this discussion on MSDN that explains more of what is really a workaround suggested by #nunespascal:
Basically I can't set WindowState to Maximised in the Designer, but if I leave it set to Normal and then when loading the form in code I set it to Maximised it works.
This is also the answer provided in this StackOverflow post.

Related

Automatically open maximized and fit correctly

Does anyone at all know how to get C# GUI programs to automatically open maximized and fit correctly in whatever screen resolution is on the computer?when I run and maximize the application the tablepage(Control) is not maximize and as well as other controls.please help me with details...
Use the WindowState property: https://msdn.microsoft.com/en-us/library/system.windows.forms.form.windowstate(v=vs.110).aspx
Set the property to Maximized before you show the form.
If you want your controls to resize with the window, use the Anchor and Dock properties in the Forms Designer.
Use Anchor to have a control's edge be a fixed distance from a given edge, and use the Dock property to have a control fill an area.

Show icon in taskbar for hidden windows

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.

Skip Aero Window Animation

How can I disable the "opening" animation of a window under Aero programatically?
When opening a new Form it "pops in" (fade in + a slight scaling transformation).
I want to stop this animation and show the window instantly.
I already tried to set the Location property of the Form to somewhere offscreen, then calling Show(), and then moving it at its correct location.
But that doesn't help, the animation will continue.
Maybe there is some hidden property I can set?
I don't want to disable open/close/minimize/maximize animations globally!
I just want to skip the "window-open" animation of my window.
I already played around with single and multiple calls ShowWindow(...) directly after Form.Show(). But no matter what parameters I pass, doesn't abort the opening-animation.
I've got it! After some trying around with ShowWindow, BorderStyles I found my exact solution:
Change the initial "FormBorderStyle" property of the form to one of those:
None
FixedToolWindow
SizeableToolWindow
Add a eventhandler to the Forms "Shown" event.
Inside the eventhandler, change the FormBorderStyle to "Sizeable" (or any other).
Now the trick is that "none" and "*toolwindow" borderstyles will suppress the opening/popup animation for that form. Than, as soon as the form is being displayed the borderstyle is changed, giving it the original functionality (Icon in the Control-Bar, Minimize/Maximize Buttons etc...)
Edit: For everyone who might want to try this too, I have to point out that this can will screw with the actual size of the window when done with PInvoke commands.
If you rely on the size of the window being correct, be sure to resize the the window to its intended size after you done this.
This is part of windows visual effects and can be adjusted using the SystemParametersInfo Method.
I found that the animation is only take place when the form is shown for the first time.
So here is the trick:
var form = new Form();
form.Show();
form.Hide();
form.Show();
I tested it only in Windows 8
You can change the style before and after, like this, which will prevent the fade-out animation.
this.FormBorderStyle = FormBorderStyle.Sizable;
this.Show();
// Do whatever
this.FormBorderStyle = FormBorderStyle.Sizable;
this.Show();

how to remove the default control buttons from a windows form

The image describes what I am trying to do.
I have a "connect four" game which works perfectly well but I want to remove the default buttons provided at the top right hand corner of the window. Any quick help on this?
Click here to view steps in video
Please Set ControlBox Value as "False" of your desire form.
The ControlBox property of Forms does this after hiding the Minimize and Maximize buttons.
MSDN - Form.ControlBox Property
In the properties window for your form designer, there should be a listing for MaximizeBox and MinimizeBox that you can set to false to disable the maximize and minimize buttons on the form. AFAIK there is no way to disable the close button.

MDI child form problem in C#

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).

Categories