I am trying to set a window at the bottom right of my screen. Its FormBorderStyle is set to None. I don't want the user to have the ability to move it around. Unfortunately, if the user presses Winkey+Up (maximize in Win7), it will relocate the form to (0,0) on my desktop.
I tried resetting the location in the LocationChanged event but when I changed the Left/Top or Location properties, they would not actually change.
Does anybody have any ideas on how I can resolve this?
Thanks!
You can't programmatically change your form's location if it is maximized. You'll need to change its WindowState property to FormWindowState.Normal before trying to set its location.
You need a GlobalSystemHook, and itsn't a trivial work.
At this url (CodeProject) there is an useful example.
Set your FormBorderStyle to one of FixedSingle, Fixed3D, FixedDialog or FixedToolWindow AND set MaximizeBox and MinimizeBox to false.
Related
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();
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.
Here's my problem: I have a winform with controls on it. Many of these controls have their Anchor property set to Top|Right. The size of the form in the designer is set to 1680x1050. If my resolution is set to 1680x1050 then it always comes up correctly.
If I change to a smaller resolution(say 1600x900) and the form is set to open as Maximized, then none of my controls move themselves to maintain their distance from the right edge. The controls on the right edge are all sticking out off the form a little. But, if I then unmaximize the window, and I can resize the window and all the controls will maintain their current, incorrect distance from the right edge.
If I set the form to start as normal(not maximized) then it opens up with all the controls in the right place, and everything stays in the right place if I resize the form.
This has been a very frustrating problem. Do any of you kind souls have advice for me?
Id recommend just using my proposed solution of:
theForm.WindowState = FormWindowState.Maximized;
My guess is that the property "Maximized" that is set during the initialization call of the form and may be causing the problems. (It's hard to say without seeing the project code). The Load even gets called after some of the more important events, so if there is some sort of existing problem with that property, it is avoided using the FormWindowState.Maximized code.
If you wish to post the actual code of what you think may be causing the problems, I'll edit this answer to help.
-J
I Solve my problem by:
Set the Control AutoSize property to false.
private void Form_Load(object sender, EventArgs e)
{
dataGridView1.AutoSize = false; //true;
}
Put all controls in SplitContainer and set Dock property of splitcontainer and control such as datagridview = Fill
In my C# application I have set the form border to Fixed3D, as I don't want to re-size it. However, the arrow on the bottom right of the form still appears for re-size even though it doesn't allow re-sizing.
How do I hide that arrow?
My best guess is you have a StatusStrip on the form. If so, set the SizingGrip property to false.
What you are looking for is:
this.SizeGripStyle = System.Windows.Forms.SizeGripStyle.Hide;
or it can be set in form designer property window.
Correction:
On the form, setting the Border to Fixed3D will remove the sizing grip from the form... UNLESS you have a status strip on the form with a SizingGrip set to true.
Solution: insure that your form's statusStrip1.SizingGrip = false;
See: http://msdn.microsoft.com/en-us/library/system.windows.forms.form.sizegripstyle.aspx
there should be a property of the form called ShowSizeGrip, just set it to False.
I want that the user shouldn't be able to resize the window form. I was able to disable the maximize button but wasn't able to find any property to disable resizing.
Any help?
You need to set the FormBorderStyle property to one of the fixed values.
Change the FormBorderStyle to FixedSingle. Also set MinimizeBox and MaximizeBox to False. Even double clicking the title will not maximize the form.
Assuming you are talking about a WinForms form, you can disable resizing by changing the FormBorderStyle property to one of the Fixed values, such as FixedSingle. There are also MaximumSize and MinimumSize properties that may be set if you want to allow some, but not total, resizing.
If you are talking about a WPF application, then you can set the ResizeMode property to NoResize, or you can set the MaxHeight, MaxWidth, MinHeight, and MinWidth properties.
As noted in the comments for the question, make sure you have a good reason to disable resizing. Most of the time, there are better alternatives that allow resizing (especially in WPF).
Set MaximumSize and MinimumSize to the current form size
this.MaximumSize = new System.Drawing.Size(x, y);
this.MinimumSize = new System.Drawing.Size(x, y);
Change the frame/border type to a non-resizeable type.