VB动态控件加载

来源:百度知道 编辑:UC知道 时间:2024/06/07 00:20:05
当鼠标双击的时候,把用于文字输入的文本框显示出来,当回车的时候,说明文字输入完毕,然后可以动态Load一个Label,把文字赋予Label并在双击的位置显示即可。
请问这一段的程序是什么呢?
谢谢啦

下面举例说明,请参考

在窗体上加入控件text1,label1(在属性窗口内设置index=0),然后复制下面代码,运行即可:

Option Explicit
Dim Mx As Integer, My As Integer

Private Sub Form_DblClick()
With Text1
.Text = ""
.Left = Mx
.Top = My
.Visible = True
End With
End Sub

Private Sub Form_Load()
Text1.Visible = False
Label1(0).Visible = False
Label1(0).AutoSize = True
End Sub

Private Sub Form_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
Mx = X
My = Y
End Sub

Private Sub Text1_KeyPress(KeyAscii As Integer)
If KeyAscii = 13 Then
Dim i As Integer
i = Label1.UBound + 1
Load Label1(i)
With Label1(i)
.Top = Text1.Top
.Left = Text1.Left
.Caption = Text1.Text
.Visible = True
End With
Text1.Visible = False
End If
End Sub

代码:
Private Declare Function GetCursorPos Lib "user32" (lpPoint