dgzz
dgzz

Reputation: 3009

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.

Upvotes: 3

Views: 3772

Answers (1)

matzone
matzone

Reputation: 5719

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()

Upvotes: 4

Related Questions