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.
Related
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 ;
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;
}
I am trying to bring my Form to the top, take screenshot, save it and then minimize it back using the following code.
this.WindowState = FormWindowState.Maximized;
this.FormBorderStyle = FormBorderStyle.None;
this.TopMost = true;
Application.DoEvents();
string keys = "%" + "{PrtSc}";
SendKeys.SendWait(keys);
Clipboard.GetImage().Save(imagePath, ImageFormat.Jpeg);
this.FormBorderStyle = FormBorderStyle.Sizable;
this.WindowState = FormWindowState.Minimized;
this.TopMost = false;
I thought the code will always bring the window on top and take the screenshot. However I noticed that its not 100% working:
The machine is too slow, so when the code that bring the window to top executes, the entire window does not appear.
Sometimes It does not bring it to top, so the pic contains some user activity.
How can I bring it completely to the top and wait till its done complete and then take a screenshot and reverse it.
Please note that there is a single form in the application.
Perhaps add a timer. run the first part of the code(up until and including:"Application.DoEvents();"), and start the timer. On the tick code check the "this.TopMost" status and only if it is the topmost form take the screen shot and stop the timer.
I have a windows form. I'm setting it's size using the following code. My desired behaviour is to have it take the full width and half the height of the primary display.
this.Location = new Point(0, 0);
this.WindowState = FormWindowState.Normal;
this.Size = new System.Drawing.Size(Screen.PrimaryScreen.Bounds.Width,Screen.PrimaryScreen.Bounds.Height / 2);
The problem is there is a space on the right form (it's not taking up the full screen). Does anyone have any suggestions as to why?
Thanks
Try use
Screen.PrimaryScreen.WorkingArea
Two ways to make it fullscreen:
// maximize the form
this.WindowState = FormWindowState.Maximized;
or
// hide the border
this.FormBorderStyle = FormBorderStyle.None;
You can try them together but have to notice the order, hide the border first, then set the window state to maximized.
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();