Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set winform start position at top right?

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?

like image 832
user774411 Avatar asked Dec 02 '22 01:12

user774411


2 Answers

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
like image 193
Hans Passant Avatar answered Dec 04 '22 23:12

Hans Passant


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.

like image 22
Wouter de Kort Avatar answered Dec 05 '22 00:12

Wouter de Kort