Search code examples
.netvb.netwinformsstartup

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?


Solution

  • 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