I have a fullscreen window with the Topmost property set to true. Whenever an application changes its WindowState property, my window is automatically minimized even though it has the active focus. For example, the code below exemplifies the problem. 3 seconds after the window is deactivated, it changes from Minimized to Normal, minimizing the other fullscreen application.
// Topmost = false
private void Form1_Deactivate(object sender, EventArgs e)
{
System.Threading.Thread.Sleep(3000);
this.WindowState = FormWindowState.Normal;
}
Is there a way to preserve the fullscreen window's WindowState property in such a case? I want the user to choose to minimize the fullscreen app, so I want to stop other programs from stealing the focus.
You may want to investigate "Kiosk Mode".
If this is a kiosk application and you are the only program running on the computer then fine. Otherwise this is a really bad idea and that's why there is not a documented way of doing it.
As Raymund Chen says this kind of question should be followed with the thought experiment "what if two programs did this?":
http://blogs.msdn.com/oldnewthing/archive/2005/06/07/426294.aspx
Perhaps this is what you want: Windows Form in Full Screen "Kiosk Mode".
Otherwise I'll second Henk's recomendation.
Related
In Windows 10, switching to Tablet Mode forces active windows to take the entire width and black out any underlying windows. We use small WPF windows as popup overlays for a dictionary tool. Most of the time they are not in focus, so the size stays right. However, if the user interacts with the popup, it will immediately expand. I can see several options for detecting Tablet Mode, but is there any way to prevent this from happening?
Update. Found this - perhaps it might help. https://social.msdn.microsoft.com/Forums/sqlserver/en-US/81bc4436-998e-4f4c-beb2-7c5edc36047b/how-to-prevent-form-from-being-maximized?forum=vbgeneral
If I understand you correctly, your windows are not supposed to be maximized at all. Then why not just prevent it with:
protected override void OnStateChanged(EventArgs e) {
base.OnStateChanged(e);
if (this.WindowState == WindowState.Maximized)
this.WindowState = WindowState.Normal;
}
In your window class.
I have a form application, i want to it to be the the top most. i use
SetWindowPos(this.Handle, HWND_TOPMOST, 0, 0, 0, 0, TOPMOST_FLAGS);
this function, it works fine.But when task manager property always on top is checked it fails. And task manager will appear as the top most window.
So my concern is, if there any way to achieve it, or we cant not do it with task manager. it will always appear on the top, or anything else i was missing, or doing wrong.
The MSDN say that HWND_TOPMOST simply Places the window above all non-topmost windows. In other words there are two groups of windows: non-topmost (usual) and topmost and you just sent your window to the other group.
If there is any other topmost window (= task manager in your case), you can switch between them as you normally would between non-topmost windows and they will be overlapping depending on which one is currently active.
If you would like to force your window to be always topmost, I guess you would have to watch for the window deactivation (WM_ACTIVATE message) and then move your window up in the Z-order and also focus your window back - this way you would prevent problems like having your window the only one visible, but having the keyboard focus on another window.
you can try this if you just want your application is always at the top of other application.
private void timer1_Tick(object sender, EventArgs e)
{
this.TopMost = true;
}
I am currently using the following code to allow the user to resize and maximize the window:
Window.AllowUserResizing = true;
Window.ClientSizeChanged += Window_ClientSizeChanged;
with the Window_ClientSizeChanged event handling the changes and re-scaling the drawn images etc.
This allows me to resize the window however much I want and also maximize it using the standard button in the window's handle. I would like to be able to start the application with the window in its maximized mode but can't figure out how to do so. I know I can use graphics.IsFullScreen = true; to show it in full screen mode but I would like to be able to run the program in a maximized, windowed mode. Any ideas?
You can put this code in the constructor to do what you want:
Form form = (Form)Control.FromHandle(Window.Handle);
form.WindowState = FormWindowState.Maximized;
This requires that you add a reference to System.Windows.Forms to your project.
This does have the downside that it actually sets up the graphics device twice on startup. Once in the normal way, and then once again because the window was resized. (Although this all happens before the form is first displayed.)
It has the advantage of being extremely simple to implement.
I'm going to poke around for awhile and see if the initialisation order can be changed...
There really is no simple way to get around this problem, it would seem.
I have been working on a windows form application based in c# and I am in need of some assistance. I am trying to recreate the window flicker that most windows applications have when a form loses focus to a parent form. Best way I can explain this is open up calculator open the help window and try to click the calculator, the help window then without falling behind the calculator flickers losing and gaining the shadowing around the edges.
I have managed to regain the focus on the child window when the parent is clicked but this creates a odd flickering effect as the parent window is momentarily brought in front of the child window. I am only guessing but that effect I am looking for appears to be that the calculator is never brought in front of the help window and then the help window is simply activated and deactivated a few times.
I tried doing some searches and I have seen a few topics relating to this but none of the solutions quite match. I am fairly new to making windows form applications so there are still a things I don't understand so be patient with me if I don't understand something at first.
Thank you in advance
An elaboration on the calculator example:
1) open up calculator from windows accessories
2) in the toolbar go to the help tab and open the about calculator option
3) click on the calculator window
4) the about calculator window will then flicker while never falling behind the calculator
The only progress I have made towards this is
private void MainForm_Activated(object sender, EventArgs e)
{
if (Open == true)
{
//blink active window
_addForm.Activate(); //makes window active
}
}
The open variable is something I use to keep track of if open forms and is made true when I show another form.
In your example the About window is called a modal window. A modal window prevents the user from interacting with the parent window until it is closed. Use Form.ShowDialog instead of Form.Show to present a Form to the user as a modal window.
Make the child form modal. This means that the child must be closed properly before focus can be transferred back to the parent.
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.