3

我有一个小代码,可以在运行时移动控件:

 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

我需要在按钮移动后保存按钮的新位置并加载它。我想为此使用 My.Settings,但我不知道应该存储什么值。

4

1 回答 1

4

例如:

创建新设置:项目菜单->属性->设置->创建如下设置

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

应用到应用

Form_Load 时读取设置

Button1.Location = My.Settings.myLoc

更改和保存设置

My.Settings.myLoc = Button1.Location
My.Settings.Save()
于 2013-06-04T02:55:12.277 回答