Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do you move controls in VB during runtime and save the location data?

I got a small code that enables a control to be moved during runtime:

 Public Const WM_NCLBUTTONDOWN = &HA1
 Public Const HTCAPTION = 2

Private Sub Button1_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Button1.MouseDown
    If e.Button = Windows.Forms.MouseButtons.Left = True Then
        Button1.Capture = False
        Dim msg As Message = _
        Message.Create(Button1.Handle, WM_NCLBUTTONDOWN, _
        New IntPtr(HTCAPTION), IntPtr.Zero)
        Me.DefWndProc(msg)
    End If
End Sub

I need to save the button's new location after it has been moved and load it as well. I would like to use My.Settings for this but I do not know what values should I store.

like image 301
dgzz Avatar asked Nov 20 '25 04:11

dgzz


1 Answers

For example:

Create a New Setting: Project menu-> Properties -> Settings ->create a setting as below

Name         Type               Scope      Value
myLoc   System.Drawing.Point    User       2;2

Applied to app

Read Settings when Form_Load

Button1.Location = My.Settings.myLoc

Change and save Settings

My.Settings.myLoc = Button1.Location
My.Settings.Save()
like image 83
matzone Avatar answered Nov 22 '25 18:11

matzone



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!