如何在运行时在VB中移动控件并保存位置数据? [英] How do you move controls in VB during runtime and save the location data?
本文介绍了如何在运行时在VB中移动控件并保存位置数据?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个小代码,可以在运行时移动控件:
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
按钮移动后,我需要保存新位置并加载它.我想为此使用My.Settings,但是我不知道应该存储什么值.
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.
推荐答案
例如:
创建新设置:项目菜单->属性->设置->创建如下设置
Create a New Setting: Project menu-> Properties -> Settings ->create a setting as below
Name Type Scope Value
myLoc System.Drawing.Point User 2;2
应用于应用
在Form_Load时读取设置
Read Settings when Form_Load
Button1.Location = My.Settings.myLoc
更改并保存设置
My.Settings.myLoc = Button1.Location
My.Settings.Save()
这篇关于如何在运行时在VB中移动控件并保存位置数据?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文