WinForm Maximize On Tray Restore? - c#

I have a little problem where if I have a WinForm and maximize it, and send it to the system tray, when I restore it, it isn't the maximum size any longer.
I'm trying to set a flag IsMaximized to true if the form is maximized when it is sent to the tray, but when it is being sent to the tray, the form state is minimized, so it doesn't catch when it is maximized.
Any thoughts on how I can work around this?
Thanks!

Try this:
if (this.WindowState == FormWindowState.Maximized)
{
if (this.Size != this.MaximumSize)
{
this.Size = this.MaximumSize;
this.WindwoState = FormWindowState.Maximized;
}
}

Related

How to run winform with showing taskbar?

I have a C#.2017 project, Home form is none border (set in properties). It always start with maximize and startposition is windowsdefaultlocation/manual (I tried). I try many code but it still runs and hide taskbar.
I want to run the form in none border, maximize/full screen mode, the form doesn't hide the taskbar of windows 10.
Tried this links:
https://social.msdn.microsoft.com/Forums/windows/en-US/e81dc341-720e-474a-9c37-75eac3a130cb/howto-show-window-form-on-top-of-taskbar-in-every-resolution?forum=winforms
https://www.c-sharpcorner.com/UploadFile/shubham0987/display-app-in-full-screen-with-windows-taskbar/
How to display a Windows Form in full screen on top of the taskbar?
private void Form1_Load(object sender, EventArgs e)
{
this.Height = Screen.PrimaryScreen.WorkingArea.Height;
this.Width = Screen.PrimaryScreen.WorkingArea.Width;
this.Location = Screen.PrimaryScreen.WorkingArea.Location;
//Screen currentScreen = Screen.FromHandle(this.Handle);
//this.Size = new System.Drawing.Size(currentScreen.Bounds.Width, currentScreen.Bounds.Height);
}
It doesn't help me anything. If you have some solution better help me please.
Much thank to all.
Setting a Forms WindowState to Maximized when your BorderStyle is none will always lay over the taskbar. This is a typical behaviour of a "Fullscreen" application.
However you are on the right track. If you want to have a semi-fullscreen experience without laying over the taskbar you have to set the Location and Size of your Form manually.
Important here is that you not only set these values manually but also take away control from the OS itself as it will always try to position a Form by some ruleset.
private void Form1_Load(object sender, EventArgs e)
{
//Hiding the Border to simulate a fullscreen-experience
this.FormBorderStyle = FormBorderStyle.None;
//Telling the operating system that we want to set the start position manually
this.StartPosition = FormStartPosition.Manual;
//Actually setting our Width, Height, and Location
this.Height = Screen.PrimaryScreen.WorkingArea.Height;
this.Width = Screen.PrimaryScreen.WorkingArea.Width;
this.Location = Screen.PrimaryScreen.WorkingArea.Location;
}
Just a little side node: You might want to think about people with multiple screens and on which screen your application should appear (maybe let the user decide by some setting etc).
Maybe this one is quite similar to something I need:
this.MaximumSize = Screen.PrimaryScreen.WorkingArea.Size ;

How to fit Windows Form to screen in Windows 8?

I am working with windows application i have removed maximized property to all windows. My doubt is how to fix the windows only upto toolbar in windows 8.
I have verified the below link: Didn't Resolve my problem
How to fit Windows Form to any screen resolution?
Check The Image
You have to maximize the form in order for it to fit to any screen resolution
public Form1()
{
InitializeComponent();
this.WindowState = FormWindowState.Normal;
this.StartPosition = FormStartPosition.Manual;
this.Size = Screen.PrimaryScreen.WorkingArea.Size;
}

Event for exiting the screen monitor (with WPF)

I am writing a program that uses a WPF window. I use the next code to maximize the window:
this.WindowStyle = WindowStyle.None;
this.WindowState = WindowState.Maximized;
this.Topmost = true;
When the window is maximized, I want to know if the mouse exits the border of my monitor so I can open a new window that offers some new controls (just like in BsPlayer: when the mouse exits the screen a window opens that gives you access to buttons like play, pause, stop etc.).
I tried to use this.MouseLeave, but no event appeared to be triggered when the window is maximized. After some tests I've discovered that the problem might be that when the my window is maximized, it is actually larger than the resolution of the monitor. On a basic example: if your monitor has a resolution of 1280 x 1024, the window has a dimension (according to this.Width and this.Height) of 1294 x 1038. So what should I do ? How should I approach the problem ?
You could handle the Window's MouseMove event and check the mouse's position.
private void Window_MouseMove(object sender, MouseEventArgs e)
{
//PrimaryScreenWidth - 1 to account for the cursor itself
if (e.GetPosition(this).X >= SystemParameters.PrimaryScreenWidth - 1 || e.GetPosition(this).X <= 1)
MessageBox.Show("Edge hit");
}
If you're running multiple monitors, you could also handle the MouseLeave event to handle the case where the mouse has moved to the second monitor.
private void Window_MouseLeave(object sender, MouseEventArgs e)
{
MessageBox.Show("Edge hit");
}

Get size of window in maximized version in winforms

How can I get the size a form would have in Maximized windowstate without maximizing it ?
I am doing a snapshot of a map control. I want to maximize the window when doing the snapshot but without the user noticing. It seems that the form windows state doesn't change the form size when it is hidden :
this.Hide();
this.WindowState = FormWindowState.Maximized;
// Snapshot but this.Size didn't change
this.WindowState = FormWindowState.Normal;
this.Show();
It works fine when not hiding.
So I'm trying to set the size manually but need to know the Maximized state width and height:
// x & y ???
this.Size = new Size(x,y);
You can read the workingarea-screen size.
Try the SuspendLayout() function to suspend layout updates to your screen. By calling ResumeLayout() you can resume this.

C# - Why won't a fullscreen winform app ALWAYS cover the taskbar?

I'm using Windows Vista and C#.net 3.5, but I had my friend run the program on XP and has the same problem.
So I have a C# program that I have running in the background with an icon in the SystemTray. I have a low level keyboard hook so when I press two keys (Ctr+windows in this case) it'll pull of the application's main form. The form is set to be full screen in the combo key press even handler:
this.FormBorderStyle = FormBorderStyle.None;
this.WindowState = FormWindowState.Maximized;
So it basically works. When I hit CTR+Windows it brings up the form, no matter what program I have given focus to. But sometimes, the taskbar will still show up over the form, which I don't want. I want it to always be full screen when I hit that key combo.
I figure it has something to do with what application has focus originally. But even when I click on my main form, the taskbar sometimes stays there. So I wonder if focus really is the problem. It just seems like sometimes the taskbar is being stubborn and doesn't want to sit behind my program.
Anyone have any ideas how I can fix this?
EDIT: More details-
I'm trying to achieve the same effect that a web browser has when you put it into fullscreen mode, or when you put powerpoint into presentation mode.
In a windows form you do that by putting the border style to none and maximizing the window. But sometimes the window won't cover the taskbar for some reason. Half the time it will.
If I have the main window topmost, the others will fall behind it when I click on it, which I don't want if the taskbar is hidden.
Try this (where this is your form):
this.Bounds = Screen.PrimaryScreen.Bounds;
this.TopMost = true;
That'll set the form to fullscreen, and it'll cover the taskbar.
I've tried so many solutions, some of them works on Windows XP and all of them did NOT work on Windows 7. After all I write a simple method to do so.
private void GoFullscreen(bool fullscreen)
{
if (fullscreen)
{
this.WindowState = FormWindowState.Normal;
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None;
this.Bounds = Screen.PrimaryScreen.Bounds;
}
else
{
this.WindowState = FormWindowState.Maximized;
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.Sizable;
}
}
the order of code is important and will not work if you change the place of WindwosState and FormBorderStyle.
One of the advantages of this method is leaving the TOPMOST on false that allow other forms to come over the main form.
It absolutely solved my problem.
private void Form1_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.F11)
if (FormBorderStyle == FormBorderStyle.None)
{
FormBorderStyle = FormBorderStyle.Sizable;
WindowState = FormWindowState.Normal;
}
else
{
SuspendLayout();
FormBorderStyle = FormBorderStyle.None;
WindowState = FormWindowState.Maximized;
ResumeLayout();
}
}
As far as I know, the taskbar is either above or below windows based on the "Keep the taskbar on top of other windows" setting. (At least, that's the wording in XP.) I suppose you could try to see if you can detect this setting and toggle it if needed?
Try resizing the form and bringing it to the front of the z-order like so:
Rectangle screenRect = Screen.GetBounds(this);
this.Location = screenRect.Location;
this.Size = screenRect.Size;
this.BringToFront();

Categories

Resources