How to set winform start position at top right?

2019-02-18 12:58发布

问题:

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:

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


回答6:

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.



回答7:

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