I have a windows Form Application.I want that when the application will run my window will always just on Taskbar and on the Right side means on the bottom-right of a user screen.It doesn't matter what is a user screen resolution is.So how can i do that ???
To build on MeNoMore's answer, to make your form show up in the bottom right corner of the primary screen (the screen with the task bar is usually the primary screen) you would set the following in the constructor of your form.
this.StartPosition = FormStartPosition.Manual;
this.Location = new Point(Screen.PrimaryScreen.WorkingArea.Width - this.Width,
Screen.PrimaryScreen.WorkingArea.Height - this.Height);
Other answers will not work. You have to do two things:
Set form's StartPosition to Manual
Set form's Location to what point you want
E.g. inside form's constructor:
StartPosition = FormStartPosition.Manual;
Location = new Point(Screen.PrimaryScreen.WorkingArea.Width - Width,
Screen.PrimaryScreen.WorkingArea.Height - Height);
You can try to use:
Form1.Location = new Point(x, y);
Take a look here
Use Form.StartPosition property
You use the WinTaskBar component for considering other factors on a desktop/screen.
[DllImport("SHELL32", CallingConvention = CallingConvention.StdCall)]
static extern uint SHAppBarMessage(int dwMessage, ref APPBARDATA pData);
It will let you control the positions (left & top).
Example:
formStartLeft = Screen.PrimaryScreen.WorkingArea.Width - this.Width;
formStartTop = taskBarHeight + Screen.PrimaryScreen.WorkingArea.Height;
Related
How can I make a form fill all the screen (in terms of size) when clicked (not
fullscreen like f11). At design - time (Not on code behind)?
If I understand your question correctly, making your form in run time isn't an problem but you want to design also in that form size. You could just set your form's height and width properties according to your resolution. Like for 1366x768, width-1366 height-768.
Yes, Resolution differences will be a major problem and I don't see anything you can do other than building an responsive layout. In that case design size doesn't matter (full screen or not).
At design time: use the WindowsState property defined to Maximized.
At runtime without using this property: you can use this:
static public class FormHelper
{
static public void SetSizeToScreen(this Form form)
{
int left = Screen.PrimaryScreen.Bounds.Left;
int top = Screen.PrimaryScreen.Bounds.Top;
int width = Screen.PrimaryScreen.Bounds.Width;
int height = Screen.PrimaryScreen.Bounds.Height;
form.Location = new Point(left, top);
form.Size = new Size(width, height);
}
static public void SetSizeToDesktop(this Form form)
{
int left = SystemInformation.WorkingArea.Left;
int top = SystemInformation.WorkingArea.Top;
int width = SystemInformation.WorkingArea.Width;
int height = SystemInformation.WorkingArea.Height;
form.Location = new Point(left, top);
form.Size = new Size(width, height);
}
}
Usage:
this.SetSizeToDesktop();
I have a C# WinForms application and when I give the executable to different users the application displays in different sizes (based on their screen resolution). Some of the parts of the application can't be seen.
how can I set absolute 1280X800 for my forms and make sure that the form size will not be changed whatever resolution is!
You can use Control.ScaleControl and Control.Scale
private void MainForm_Load( object sender, EventArgs e )
{
float width_ratio = (Screen.PrimaryScreen.Bounds.Width / 1280);
float heigh_ratio = (Screen.PrimaryScreen.Bounds.Height / 800f);
SizeF scale = new SizeF(width_ratio, heigh_ratio);
this.Scale(scale);
//And for font size
foreach (Control control in this.Controls)
{
control.Font = new Font("Microsoft Sans Serif", c.Font.SizeInPoints * heigh_ratio * width_ratio);
}
}
Hope this helps.
Use the MaximumSize property of the form.
form.MaximumSize = new Size(1280, 800);
You can also set a MinimumSize if you don't want the user to make it smaller than a desired size.
You can instead design the GUI so it scrolls up and down more easily.You can make use of the following
Layout Managers
Docking
Anchors
The property
Screen.PrimaryScreen.WorkingArea
is very useful for form sizing and positioning. For example this code:
this.Width = Screen.PrimaryScreen.WorkingArea.Width/2;
this.Height = Screen.PrimaryScreen.WorkingArea.Height/2;
this.Top = (Screen.PrimaryScreen.WorkingArea.Top + Screen.PrimaryScreen.WorkingArea.Height)/4;
this.Left = (Screen.PrimaryScreen.WorkingArea.Left + Screen.PrimaryScreen.WorkingArea.Width)/4;
will place the form in which it is executed in the middle of the screen and size it to half the screen.
The WorkingArea var is used to exclude stuff like the task bar and other docked items on the desktop when calculating the size of the screen.
Hope this helps.
const int SWP_SHOWWINDOW = 0x0040;
int Left = Convert.ToInt32(LeftSizeTextBox.Text);
int Top = Convert.ToInt32(TopSizeTextBox.Text);
int Width = Convert.ToInt32(WidthSizeTextBox.Text);
int Height = Convert.ToInt32(HeightSizeTextBox.Text);
IntPtr handle = FindWindow(null, WindowTextBox.Text);
SetWindowPos(handle, -2, Top - 8, Left - 30, Width + 32, Height + 38, SWP_SHOWWINDOW);
SetForegroundWindow(handle);
I want TRUE fullscreen. Currently mine only puts it mostly fullscreen but it stops slightly below the bottom, and doesn't cover the taskbar. How do I made it completely (Windowed borderless) while still being able to alt tab? If you've ever used shiftwindow, that is my desired effect.
To make a (border less) window go true fullscreen, go to your Form's properties (CTRL + W, P) then set ControlBox to false and WindowState to Maximized. This should display your form over the taskbar. Here is the code of you want to do it dynamically:
//ControlBox
this.ControlBox = false;
//WindowState
this.WindowState = System.Windows.Forms.FormWindowState.Maximized;
Edit: This will only make your form go true fullscreen. Looking at your code I think you are trying to make other forms go fullscreen.
I work on VS 2008 with C#. This below code does not work for me. My form was designed in 1024 x 768 resolution.
Our clients laptop is in 1366 x 768 resolution. To solve this problem, I set below code in Form Load event:
this.Location = new Point(0, 0);
this.Size = Screen.PrimaryScreen.WorkingArea.Size;
but the form does not resize as per screen resolution and bottom of my form gets hidden or cut or I miss the scroll bar.
Is there any way to solve this problem? Please show me the syntax.
Can't you start maximized?
Set the System.Windows.Forms.Form.WindowState property to FormWindowState.Maximized
If you want to set the form size programmatically, set the form's StartPosition property to Manual. Otherwise the form's own positioning and sizing algorithm will interfere with yours. This is why you are experiencing the problems mentioned in your question.
Example: Here is how I resize the form to a size half-way between its original size and the size of the screen's working area. I also center the form in the working area.
On computers with multiple monitors, the user probably expects the form to open on the same screen that the mouse pointer is on. We can get it with Screen.FromPoint(Cursor.Position).
public MainView()
{
InitializeComponent();
StartPosition = FormStartPosition.Manual;
Rectangle screen = Screen.FromPoint(Cursor.Position).WorkingArea;
int w = Width >= screen.Width ? screen.Width : (screen.Width + Width) / 2;
int h = Height >= screen.Height ? screen.Height : (screen.Height + Height) / 2;
Location = new Point(screen.Left + (screen.Width - w) / 2, screen.Top + (screen.Height - h) / 2);
Size = new Size(w, h);
}
Note that setting WindowState to FormWindowState.Maximized alone does not change the size of the restored window. So the window might look good as long as it is maximized, but when restored, the window size and location can still be wrong. So I suggest setting size and location even when you intend to open the window as maximized.
Probably a maximized Form helps, or you can do this manually upon form load:
Code Block
this.Location = new Point(0, 0);
this.Size = Screen.PrimaryScreen.WorkingArea.Size;
And then, play with anchoring, so the child controls inside your form automatically fit in your form's new size.
Set the form property to open in maximized state.
this.WindowState = FormWindowState.Maximized;
int h = Screen.PrimaryScreen.WorkingArea.Height;
int w = Screen.PrimaryScreen.WorkingArea.Width;
this.ClientSize = new Size(w , h);
You can simply set the window state
this.WindowState = System.Windows.Forms.FormWindowState.Maximized;
simply set Autoscroll = true for ur windows form.. (its not good solution but helpful)..
try for panel also(Autoscroll property = true)
You can always tell the window to start in maximized... it should give you the same result... Like this: this.WindowState = FormWindowState.Maximized;
P.S. You could also try (and I'm not recommending this) to subtract the taskbar height.
I am starting a winform application[.NET 3.5, C#], where in the the main form of the application starts at a particular specified location. Am calling the following code in the constructor for this
private void SetFormPosition()
{
this.StartPosition = FormStartPosition.Manual;
this.Left = Screen.PrimaryScreen.WorkingArea.Right - this.Width;
this.Top = Screen.PrimaryScreen.WorkingArea.Bottom - this.Height;
}
After the application starts, I would like to keep the location of the form fixed throughout the application lifetime.
Perhaps, I could 'tap' the Location event changed but am not sure if that would be very elegant.
Please suggest.
Thanks.
I agree with others that you probably shouldn't be doing this, but if you must, read on.
You can override the SetBoundsCore method and prevent any movement. We use this to prevent vertical resizing on some UserControl implementations (such as those that contain a ComboBox or other fixed height control), but it is also responsible for the location changing.
The following should get you started:
protected override void SetBoundsCore(
int x, int y, int width, int height, BoundsSpecified specified)
{
x = this.Location.X;
y = this.Location.Y;
//...etc...
base.SetBoundsCore(x, y, width, height, specified);
}
You could set the FormBorderStyle to None. This has the added benefit of removing the bar at the top of the window that would give users a false sense that they should be able to move the window.
Just change this
Location = new Point(this.Width,this.Height);