Home > front end >  vb.net Why doesn't My.setting make my form's location sticky?
vb.net Why doesn't My.setting make my form's location sticky?

Time:12-29

I can't get my form's screen location to be sticky.

My form is named "GUI".

I added the x & y variables to project > Settings tab.

' app boots, form loads, and should set its screen location...
Private Sub GUI_Load(sender As Object, e As EventArgs) Handles MyBase.Load
    IF Not ( MY.Settings.Window_Location_Setting_X = 0  And  MY.Settings.Window_Location_Setting_Y = 0 )
        Me.StartPosition = FormStartPosition.Manual
        Me.Location = New Point( MY.Settings.Window_Location_Setting_X, MY.Settings.Window_Location_Setting_Y )
    END IF
END SUB

' I click and drag form to new locatin.......
Private Sub GUI_LocationChanged(sender As Object, e As EventArgs) Handles MyBase.LocationChanged
    MY.Settings.Window_Location_Setting_X = sender.Location.X
    MY.Settings.Window_Location_Setting_Y = sender.Location.y
End Sub

CodePudding user response:

This seems clearer and much shorter. The forms StartPosition is set to FormStartPosition.Manual in the designer. Note that the .Shown event is used instead of the .Load event.

'My.Settings.Loc  is  System.Drawing.Point
Private Sub Form1_Shown(sender As Object, e As EventArgs) Handles Me.Shown
    Me.Location = My.Settings.Loc
End Sub

Private Sub Form1_ResizeEnd(sender As Object, e As EventArgs) Handles Me.ResizeEnd
    My.Settings.Loc = Me.Location
End Sub

ResizeEnd

CodePudding user response:

Solution was to set a variable is_booting = true at boot time, then set it false at end of form load.

then,

Private Sub GUI_LocationChanged(sender As Object, e As EventArgs) Handles MyBase.LocationChanged
    IF Not is_booting
         PRINT("window moved sender.Location.X " & sender.Location.X )
         PRINT("window moved sender.Location.X " & sender.Location.Y )
        MY.Settings.Window_Location_Setting_X = sender.Location.X
        MY.Settings.Window_Location_Setting_Y = sender.Location.y
    END IF
End Sub
  • Related