9

How can I position a form at the bottom right corner of the screen when the form loads? I'm using Visual Basic 2010 Express.

Thanks

EDIT: I did this and it seems to work great.

Dim x As Integer
Dim y As Integer
x = Screen.PrimaryScreen.WorkingArea.Width - 400
y = Screen.PrimaryScreen.WorkingArea.Height - 270
Me.Location = New Point(x, y)
Chad
  • 1,531
  • 3
  • 20
  • 46
Utku Dalmaz
  • 9,780
  • 28
  • 90
  • 130

8 Answers8

8
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    Me.Visible = True
    Dim x As Integer
    Dim y As Integer
    x = Screen.PrimaryScreen.WorkingArea.Width
    y = Screen.PrimaryScreen.WorkingArea.Height - Me.Height

    Do Until x = Screen.PrimaryScreen.WorkingArea.Width - Me.Width
        x = x - 1
        Me.Location = New Point(x, y)
    Loop

End Sub
Kirk Woll
  • 76,112
  • 22
  • 180
  • 195
Lost
  • 89
  • 1
  • 1
  • As the name suggests, this only locates it in the corner of the *primary* screen. With multiple monitors, that's often going to be the wrong one and annoy the user. – user1318499 Dec 18 '13 at 01:01
  • Oh wow, somebody who dislikes maths as much as I do. The code is great, but the approach with the "Do Until" is not beautiful. – tmighty Sep 17 '14 at 21:55
6

You need to change the Form.StartPosition to Manual and change the Location property of the form

eg how to set form startup location/position manually?

or

VB.net - Form Start Position Upper Left

using Form.StartPosition Property and Form.Location Property

Adriaan Stander
  • 162,879
  • 31
  • 289
  • 284
  • That's only half the answer - equally as important and *much* harder to track down though its actually something that every desktop programmer should know (and the really key question) is how to get the size and location of the work area of the desktop. I last did this in Delphi, longer ago than I care to remember and I haven't yet found the .NET answer... (or at least I can't recall so doing). – Murph Dec 04 '09 at 11:36
  • 2
    Screen.GetWorkingArea returns the size and location of the useful part of the display. Or in excruciating detail, the desktop area of the display, excluding taskbars, docked windows, and docked tool bars. You pass in a control, because there might be multiple monitors, in which case it uses the control to decide which monitor you meant. http://msdn.microsoft.com/en-us/library/45zswy9x.aspx – MarkJ Dec 04 '09 at 11:52
  • 1
    Here's some sample code in C#, it translates to VB.Net pretty directly. (`This` is `Me`) http://stackoverflow.com/questions/1385674/place-winform-on-bottom-right/1385691#1385691 – MarkJ Dec 04 '09 at 11:54
  • yeah i edited my question with the code i wrote and it seems to work – Utku Dalmaz Dec 04 '09 at 11:57
4

Center Screen:

Me.Location = New Point((Screen.PrimaryScreen.WorkingArea.Width - Me.Width) / 2, (Screen.PrimaryScreen.WorkingArea.Height - Me.Height) / 2)

Right Bottom Corner Screen:

Me.Location = New Point(Screen.PrimaryScreen.WorkingArea.Width - Me.Width, Screen.PrimaryScreen.WorkingArea.Height - Me.Height)
Zunair
  • 1,085
  • 1
  • 13
  • 21
3

simply this does the trick for me: poitions just above/left of taskar s the case may be.

Dim x As Integer
        Dim y As Integer
        x = Screen.PrimaryScreen.WorkingArea.Width - Me.Width
        y = Screen.PrimaryScreen.WorkingArea.Height - Me.Height
        Me.Location = New Point(x, y)
rDroid
  • 4,875
  • 3
  • 25
  • 30
1

If you want to position the form on the screen cursor is on, use:

' Get Active Screen Cursor is On, rather than assuming user on PrimaryScreen
Dim scr As Screen = Screen.FromPoint(Cursor.Position)

Me.Location = New Point(scr.WorkingArea.Right - Me.Width, scr.WorkingArea.Bottom - Me.Height)
Gordon Bell
  • 13,337
  • 3
  • 45
  • 64
1

you can try like

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load Me.StartPosition = FormStartPosition.Manual Me.Location = Screen.GetWorkingArea(Me).Location End Sub

betrice mpalanzi
  • 1,436
  • 12
  • 16
0

You can loop through the child forms and do some calculations based on the top and left properties (might want to combine those calcs with Width and Height properties depending on what your requirement is for "bottom left")

HTH, Mark

Mark Cooper
  • 6,738
  • 5
  • 54
  • 92
0

Try this solution. It working for me at VS 2019

Protected Overrides Sub OnLoad(ByVal e As System.EventArgs)
    Me.Top = System.Windows.Forms.Screen.PrimaryScreen.Bounds.Height - Me.Height
    Me.Left = System.Windows.Forms.Screen.PrimaryScreen.Bounds.Width - Me.Width
    MyBase.OnLoad(e)
End Sub

goodluck

Dũng IT
  • 2,751
  • 30
  • 29