Skip Aero Window Animation - c#

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();

Related

How to make a window partially clickthrough?

I'm attempting to create a window with the following properties:
Completely invisible except for a small, moving region
Can be clicked through to windows below it, EXCEPT if you click in that small region
Doesn't show up on the taskbar (although this one isn't as pressing at the moment)
I can figure out how to make the WHOLE window transparent (partially or entirely) and click-through using WS_EX_LAYERED and WS_EX_TRANSPARENT, setting TopMost, and changing the opacity, but I can't figure out how to make these requirements true for the window EXCEPT for a limited part. Any idea where to start?
EDIT: It's been pointed out to me that making a huge, invisible window is rather pointless, and it would be smarter to create a small window and use FormBorderStyle.FixedToolWindow and ShowInTaskbar to make it borderless and not present on the task bar, then move it around. I still need to figure out how to make the "background" of the window transparent and click-through, so I'm leaving this question up.
So, I managed to figure it out through trial and error, and I apologize for taking people's time.
The solution here is to:
Override OnPaintBackground to be an empty method, so nothing actually gets painted on the back
Set the style so it supports Transparent as a back color, then set the back color and TransparencyKey to Transparent
Set FormBorderStyle to None, TopMost to True, ControlBox to False, ShowInTaskbar to False, and Text to String.Empty
End result: A form that is completely invisible and that can be clicked through, while still letting the user interact with any controls placed on the form.

Preventing automatic offsetting when opening a new window

In WPF, when a new Window is shown, it is offset by maybe 10 pixels horizontally and vertically. Is there an easy way to prevent this, so the window opens directly over the one that triggered it? (They are the same size - consider it similar to an installer's behavior)
You should set the WindowStartupLocation property of all windows to CenterScreen value.
You can set the Left and Top properties of the new window to be the same as the owner window.
You should do this before you call the Show or ShowDialog methods.
Good luck,
M. Moshe

"Tint" an entire window, or alternative method of making window look inactive

I have a winforms C# application that opens multiple dialog boxes. To suit the style of the application, I have removed the default title bars for each window and created my own (with control buttons and drag-to-move function).
The problem that now faces me is that without a titlebar, the user has no way of telling which window is the 'active' window when they are manually moved apart (so they are not overlapping).
In any windows application (that uses titlebars), when you try to navigate away from a dialog box back to the main program (without closing the dialog box) - it wont let you. The border of the dialog box flashes and you hear a windows error sound. Some kind of equivalent visual feedback would be great without needing to have the default titlebars - and tinting an entire window darker seems like it would do the trick nicely.
Something like this in pseudo-code, which would nicely tint the parent window whilst a dialog is open:
// tint window now
window.ShowDialog();
// un-tint window
I have tried to place a panel covering everything with colour set to 'transparent' (with the intention of later controlling the opacity of the panel) but the transparency does not seem to work. Any other ideas of accomplishing this? Or does anyone have a better suggestion to achieve the same level of visual feedback?
Summary:
Is there any way to tint an entire window, or overlay it with a colour? If not, could anyone suggest an alternate method of making the window appear 'inactive'?
I would suggest you to create a method in forms you want to disable:
void DisableForm()
{
//some fancy color
this.BackColor = System.Drawing.Color.Khaki;
//and disable all controls owned by form, just to be sure
foreach (var s in this.Controls)
{
((Control)s).Enabled = false;
}
}
and functions which enables back those forms of course.
edit.
also you can set visibility property of controls to false

Control anchor property not working when form starts maximized

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

C# Fullscreen, hiding the taskbar

I have recently written an application for my daughter, which is a kid-free zone where she has all unnecessary key presses ignored (windows key, Esc etc) but the problem I am having is that when I use the following code:
targetForm.WindowState = FormWindowState.Maximized;
targetForm.FormBorderStyle = FormBorderStyle.None;
targetForm.TopMost = true;
I am able to HIDE the taskbar, but it is not truly overlayed. When I move the mouse to where the taskbar would be, and click, it pops up, also, using this code and running external applications withing my windows form, I am left with this windows form keeping itself on top.
If anyone could help me with a proper way to display my windows form as a true fullscreen application, and be able to run external applications from within the form and have them prioritize themselves on top, that would be greatly appreciated.
In case you missed it, I am using VS2010, C# and winforms.
Thanks in advance!
The proper way to make a full-screen app is to just put something like Bounds = Screen.PrimaryScreen.Bounds; in your main form. Then when your app has focus it will cover the task bar.
You also probably want FormBorderStyle = FormBorderStyle.None;
The order of the performed actions is incorrect.
You should first hide the border (FormBorderStyle=None), and then set the window state to maximized. You even don't have to set TopMost to true.

Categories