开发者

Position form at the bottom right corner of the screen in visual basic

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.

开发者_如何学C

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)


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


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


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)


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)


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)


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


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


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜