How to set winform start position at top right?

删除回忆录丶 提交于 2019-12-18 17:26:12

问题


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?


回答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



回答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.




回答3:


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.




回答4:


Just Add This to your OnLoad Event

    Me.Location = New Point(1, 1)  



回答5:


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.




回答6:


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



回答7:


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


来源:https://stackoverflow.com/questions/7892090/how-to-set-winform-start-position-at-top-right

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