Prevent Tablet Mode from maximizing window width - c#

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.

Related

Disable Windows 10 "scroll inactive windows" in C# Winforms

I have a question regarding C#, Winforms and "Scroll inactive windows when I hover over them" in Windows 10.
I have a flow layout panel, which i dynamically fill with custom controls.
The controls have a zoom in zoom out feature that is controlled by the mouse wheel.
When the number of controls exceed the flow layout panel size i got AutoScroll = true, so the panel gets a vertical scroll bar. I do not want to scroll the panel with the mouse wheel, i want the user to manually do it.
Everything works fine in Windows 7, but in Windows 10, if the user has the "Scroll inactive windows when I hover over them" turned on, when the mouse is over a control and the user uses the mouse wheel, the control zooms in or out, but the panel also scrolls.
I debugged, and i found that Win10 scrolls the panel even before the form/panel's MouseWheel event.
How can I disable the "Scroll inactive.." temporarily in my code ? or at least disable its behavior?
Thanks !
The only thing comes to my mind to disable the behavior is to check whether the window is TopMost or lost focus.
This can be done by using the form.TopMost property or the Activated and Deactivate events.
Using the events:
public Form1()
{
InitializeComponent();
this.Deactivate += Form1_Deactivate;
this.Activated += Form1_Activated;
}
private void Form1_Activated(object sender, EventArgs e)//The form gained focus
{
panel1.Enabled = true;
}
private void Form1_Deactivate(object sender, EventArgs e)// The form lost focus
{
panel1.Enabled = false;
}
These will work just fine but using some controls it will make them change appearance on some OS.
If you don't mind that, great.
If you do, you should go for the same concept using the events only disabling the scroll itself once the form lost focus and enabling it when its regained.
Cheers.

Maximize window in XNA 4.0

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.

Irregualr behaviour with windows taskbar when making my application 'full screen' (WPF)

I am working on an application that has a full screen mode. When the full screen button/key is pressed the application should take up the entire screen i.e. the windows taskbar also disappears.
this.Window= WindowState.Maximized;
this.Window= WindowStyle.None;
this.Fullscreen = true;
When I first start the application my fullscreen mode works as planned and the windows taskbar disappears. The problem is when I resize the window. After any resizing the full screen mode no longer takes up the entire screen. The windows taskbar is still there. It is not reasonable for me to disable window resizing (although that does solve the problem).
It was my understanding that WindowStyle.None removed the taskbar (it does at first). Does anyone know if resizing the window changes something that stops the WindowStyle.None from doing what it does upon first starting up.
EDIT:
I am using a viewbox to scale my content to fullscreen and the stretch of the viewbox in full screen mode is set to Fill
Try applying the WindowStyle first (before WindowState). That fixed it for me.
Edit: I also noticed that this doesn't work when the window is already maximized. Try this:
this.WindowState = WindowState.Normal;
this.WindowStyle = WindowStyle.None;
this.WindowState = WindowState.Maximized;
Instead of using WindowState
use SystemParameters
In your Window's constructor set the width and height
this.Width=SystemParameters.FullPrimaryScreenWidth;
this.Height=SystemParameters.FullPrimaryScreenHeight;
You can also have a look here

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.

How can I prevent other apps from stealing the focus?

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.

Categories