How to set winform start position at top right?

19,573

Solution 1

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

Solution 2

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.

Solution 3

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.

Solution 4

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.

Solution 5

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
Share:
19,573
user774411
Author by

user774411

Updated on June 05, 2022

Comments

  • user774411
    user774411 almost 2 years

    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?