Form in Bottom Right Corner Close, But Not Perfect

Rich Goldberg 161 Reputation points
2022-02-13T21:21:52.677+00:00

After following the advice from so many posts about correctly positioning a form in the bottom right corner of the screen, I can’t believe it’s not working correctly for me.

I display my main form, which is MDI. In its Shown routine, it shows the frmSearch form:

Private Sub FrmMain_Shown(sender As Object, e As EventArgs) Handles Me.Shown  
    Dim Search As New frmSearch ' Create a Search form  
    Search.MdiParent = Me ' Tell it who's the boss: frmMain  
    Search.Show()  
End Sub  

In the frmSearch Load routine, I set the location of the frmSearch form to what -should- properly position it in the bottom right corner of my screen:

Private Sub FrmSearch_Load(sender As Object, e As EventArgs) Handles MyBase.Load  
    Dim scr As Screen = Screen.FromPoint(Cursor.Position)  
    Me.Location = New Point(scr.Bounds.Right - Me.Width, scr.WorkingArea.Bottom - Me.Height)  
End Sub  

The screen shows up basically in the bottom right corner, but there are horizontal and vertical slide bars:
173769-lower-right-corner-1.jpg

Even stranger, when I then slide the right bar down, then slide the bottom bar to the right, the slidebars disappear, leaving the form right-justified, but higher than the bottom:
173849-lower-right-corner-2.jpg

If I run it again and reverse the order, sliding bottom first, then the right bar, the form ends up bottom-justified and away from the right side.

I’m stumped. Anybody have a suggestion?

Using Visual Studio 2022 and VB.Net on Windows 11.

Developer technologies | Windows Forms
0 comments No comments
{count} votes

Accepted answer
  1. Viorel 122.6K Reputation points
    2022-02-13T22:00:43.827+00:00

    Check this approach:

    Private Sub FrmSearch_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        Me.Left = Parent.ClientSize.Width - Me.Width
        Me.Top = Parent.ClientSize.Height - Me.Height
    End Sub
    
    1 person found this answer helpful.

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.