Reputation: 1809
How to set winform
start position at top right? I mean when user click (start) my winform application the winform will appear at the top right of the screen?
Upvotes: 4
Views: 21314
Reputation: 323
to show on the primary monitor if you have multi monitor useful for multi monitor setup
Start on Upper Right
Public Class Form1
Protected Overrides Sub OnLoad(ByVal e As System.EventArgs)
Dim scr = Screen.AllScreens(0)
Me.Location = New Point(scr.WorkingArea.Right - Me.Width, scr.WorkingArea.Top)
MyBase.OnLoad(e)
End Sub
End Class
Start on Upper Left
Public Class Form1
Protected Overrides Sub OnLoad(ByVal e As System.EventArgs)
Dim scr = Screen.AllScreens(0)
Me.Location = New Point(scr.WorkingArea.Right - Me.Width - scr.WorkingArea.Right + Me.Width, scr.WorkingArea.Top)
MyBase.OnLoad(e)
End Sub
End Class
Upvotes: 1
Reputation: 11
you can use this in OnLoad Event of your Form
private void dlgTTMSContract_Load(object sender, EventArgs e) {
int screenWidth = Screen.PrimaryScreen.Bounds.Size.Width;
int formWidth = this.Width;
this.Location = new Point(screenWidth - formWidth, 0);
}
Upvotes: 0
Reputation: 26
Add the line of code in frm.Designer.cs file
this.Location = new Point(0,0);
Note: Check if the location is already set in frm.resX file you can change it there. Or remove from .resX file and add the above line in frm.Designer.cs
Any way it will work.
Upvotes: 1
Reputation: 3303
In form load even send the windows position to y=0 and x= Screen width - form width.
e.g.
private void Form1_Load(object sender, EventArgs e)
{
this.Location = new Point( Screen.PrimaryScreen.Bounds.Right - this.Width,0);
}
You can alternatively use "Screen.GetBounds(this).Right". This will give you the coordinates of screen which contain your form.
Upvotes: 3
Reputation: 187
It works fine for you:
private void Form1_Load(object sender, EventArgs e)
{
this.Location = new Point(Screen.FromPoint(this.Location).WorkingArea.Right - this.Width, 0);
}
Upvotes: -1
Reputation: 941545
Use the Load event to change the position, the earliest you'll know the actual size of the window after user preferences and automatic scaling are applied:
Public Class Form1
Protected Overrides Sub OnLoad(ByVal e As System.EventArgs)
Dim scr = Screen.FromPoint(Me.Location)
Me.Location = New Point(scr.WorkingArea.Right - Me.Width, scr.WorkingArea.Top)
MyBase.OnLoad(e)
End Sub
End Class
Upvotes: 15
Reputation: 39898
You can use Form.Location to set the location to a Point that represents the top left corner of the form.
So if you set this to 'Screenwidth - Formwidth' you can position the Form in the top right. To get the screen width you can use the Screen.Bounds property.
Upvotes: 2