如何在窗口中自动添加控件,如text

lubberland 2003-08-21 03:59:00
窗口打开,自动出现不定的控件,不能用隐藏。
...全文
93 10 打赏 收藏 转发到动态 举报
写回复
用AI写文章
10 条回复
切换为时间正序
请发表友善的回复…
发表回复
lubberland 2003-08-21
  • 打赏
  • 举报
回复
thanks ,xayzmb(行者), Apple200228(Apple)
lihonggen0 2003-08-21
  • 打赏
  • 举报
回复
'先有form1上加一个text1 (0)

Private Sub Form_Load()
For i = 1 To 10
Load Text1(i)
Text1(i).Top = 400 * i + 200
Text1(i).Left = 20
Text1(i).Visible = True
Next
End Sub
didishu0807 2003-08-21
  • 打赏
  • 举报
回复
Set aa = Controls.Add("vb.combobox", "aa1", Me)
aa.Top = 1500
aa.Left = 1000
aa.Visible = True
didishu0807 2003-08-21
  • 打赏
  • 举报
回复
Set aa = Controls.Add("vb.combobox", "aa1", Me)
aa.Top = 1500
aa.Left = 1000
aa.Visible = True
射天狼 2003-08-21
  • 打赏
  • 举报
回复
对了,要事先将TEXT控件的INDEX 属性设置为 0
xayzmb 2003-08-21
  • 打赏
  • 举报
回复
1.用数组
2.下面有个例子,举一反三吧:
'向窗体中动态增加两个图片控件(pictureBox)
'并且
'将第一个图片控件做为第二个图片控件的容器

Option Explicit
Private WithEvents pic1 As PictureBox
Private WithEvents pic2 As PictureBox

Private Sub Form_Load()
Set pic1 = frmTest.Controls.Add("vb.picturebox", "pic1")
Set pic2 = frmTest.Controls.Add("vb.picturebox", "pic2")
Set pic2.Container = pic1
pic1.Top = 0
pic1.Left = 0
pic1.Width = 4000
pic1.Height = 3000
pic1.Visible = True
pic2.Top = 300
pic2.Left = 400
pic2.Width = 3000
pic2.Height = 2000
pic2.Visible = True
End Sub
xayzmb 2003-08-21
  • 打赏
  • 举报
回复
1.用数组;
2.下面有个例子:
'向窗体中动态增加两个图片控件(pictureBox)
'并且
'将第一个图片控件做为第二个图片控件的容器

Option Explicit
Private WithEvents pic1 As PictureBox
Private WithEvents pic2 As PictureBox

Private Sub Form_Load()
Set pic1 = frmTest.Controls.Add("vb.picturebox", "pic1")
Set pic2 = frmTest.Controls.Add("vb.picturebox", "pic2")
Set pic2.Container = pic1
pic1.Top = 0
pic1.Left = 0
pic1.Width = 4000
pic1.Height = 3000
pic1.Visible = True
pic2.Top = 300
pic2.Left = 400
pic2.Width = 3000
pic2.Height = 2000
pic2.Visible = True
End Sub

举一反三吧
lisong770818 2003-08-21
  • 打赏
  • 举报
回复
同cuizm(射天狼) 的方法
Apple200228 2003-08-21
  • 打赏
  • 举报
回复

Option Explicit

'通过使用WithEvents关键字声明一个对象变量为新的命令按钮

Private WithEvents NewButton As PictureBox
Private WithEvents NewLabel As Label
'增加控件

Private Sub Command1_Click()
Static i As Long
' If NewButton Is Nothing Then

'增加新的按钮cmdNew

Set NewButton = Controls.Add("VB.picturebox", "cmdNew" & CStr(i), Me)
' set NewButton.Index
'确定新增按钮cmdNew的位置

NewButton.Move 1240 + i * 300, Command1.Top, 200, 4000

' NewButton.Caption = "新增的按钮"

NewButton.Visible = True
' MsgBox NewButton.Name

' End If
i = i + 1

End Sub

Private Sub Command2_Click()
If NewLabel Is Nothing Then
'增加新的按钮cmdNew
Set NewLabel = Controls.Add("VB.Label", "lblNew", NewButton)
'确定新增按钮cmdNew的位置
NewLabel.Left = 10
NewLabel.Top = 20
NewLabel.Caption = "121"
NewLabel.BorderStyle = 1
NewLabel.Visible = True
End If

End Sub

Private Sub Command3_Click()
Controls.Remove NewButton
Set NewButton = Nothing
Set NewLabel = Nothing

End Sub

'新增控件的单击事件

Private Sub NewButton_Click()

MsgBox "您选中的是动态增加的按钮!"

End Sub
射天狼 2003-08-21
  • 打赏
  • 举报
回复
Private Sub Command1_Click()
Dim num As Long

num = Text1.UBound + 1
Load Text1(num)
Text1(num).Visible = True

End Sub

7,762

社区成员

发帖
与我相关
我的任务
社区描述
VB 基础类
社区管理员
  • VB基础类社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧