How to set winform start position at top right?

南楼画角 提交于 2019-11-30 16:00:31

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

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.

Jimut

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.

Just Add This to your OnLoad Event

    Me.Location = New Point(1, 1)  

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.

kamal mansouri

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);
 }

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);
        }
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!