VB动态控件加载
当鼠标双击的时候,把用于文字输入的文本框显示出来,当回车的时候,说明文字输入完毕,然后可以动态Load一个Label,把文字赋予Label并在双击的位置显示即可。请问这一...
当鼠标双击的时候,把用于文字输入的文本框显示出来,当回车的时候,说明文字输入完毕,然后可以动态Load一个Label,把文字赋予Label并在双击的位置显示即可。
请问这一段的程序是什么呢?
谢谢啦 展开
请问这一段的程序是什么呢?
谢谢啦 展开
3个回答
展开全部
下面举例说明,请参考
在窗体上加入控件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
在窗体上加入控件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
网易云信
2023-12-06 广告
2023-12-06 广告
UIkit是一套轻量级、模块化且易于使用的开源UI组件库,由YOOtheme团队开发。它提供了丰富的界面元素,包括按钮、表单、表格、对话框、滑块、下拉菜单、选项卡等等,适用于各种类型的网站和应用程序。UIkit还支持响应式设计,可以根据不同...
点击进入详情页
本回答由网易云信提供
展开全部
Dim X0, Y0 As Long
Dim l1 As Control
Dim WithEvents t1 As TextBox '是创建出来的控件能响应事件
Private Declare Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) As Long '获得鼠标位置的API函数。
Private Type POINTAPI
X As Long
Y As Long
End Type
Private Sub Form_DblClick()
Dim P As POINTAPI
GetCursorPos P
X0 = P.X: Y0 = P.Y
Set t1 = Controls.Add("VB.Textbox", "Text1")
With t1:
.Left = 1000
.Top = 400
.FontSize = 24
.Visible = True
.Text = ""
End With
End Sub
Private Sub t1_KeyPress(KeyAscii As Integer)
If KeyAscii = 13 Then
Set l1 = Controls.Add("VB.Label", "Label1")
With l1
.Visible = True
.Caption = t1.Text
.Left = X0
.Top = Y0
.AutoSize = True
.FontSize = 24
End With
End If
End Sub
Dim l1 As Control
Dim WithEvents t1 As TextBox '是创建出来的控件能响应事件
Private Declare Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) As Long '获得鼠标位置的API函数。
Private Type POINTAPI
X As Long
Y As Long
End Type
Private Sub Form_DblClick()
Dim P As POINTAPI
GetCursorPos P
X0 = P.X: Y0 = P.Y
Set t1 = Controls.Add("VB.Textbox", "Text1")
With t1:
.Left = 1000
.Top = 400
.FontSize = 24
.Visible = True
.Text = ""
End With
End Sub
Private Sub t1_KeyPress(KeyAscii As Integer)
If KeyAscii = 13 Then
Set l1 = Controls.Add("VB.Label", "Label1")
With l1
.Visible = True
.Caption = t1.Text
.Left = X0
.Top = Y0
.AutoSize = True
.FontSize = 24
End With
End If
End Sub
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
代码:
Private Declare Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) As Long
Private Type POINTAPI
x As Long
y As Long
End Type
prive from_dbclick()
dim ShowLabel as vb.label
Dim pt As POINTAPI
dim x as long
dim y as long
x=pt.x
y=pt.y
dim labelX as label
labelx=load(showlabel)
labelx.top=y
labelx.left=x
labelx.caption="动态加载的LABEL"
labelx=new showlabel
end sub
Private Declare Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) As Long
Private Type POINTAPI
x As Long
y As Long
End Type
prive from_dbclick()
dim ShowLabel as vb.label
Dim pt As POINTAPI
dim x as long
dim y as long
x=pt.x
y=pt.y
dim labelX as label
labelx=load(showlabel)
labelx.top=y
labelx.left=x
labelx.caption="动态加载的LABEL"
labelx=new showlabel
end sub
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询