问题描述
我正在添加运行时要形成的控件.我正在执行以下操作,没有任何问题:
将5个面板"添加到表单中
私有属性lstGlbBox1作为新对象
私有财产btnBack作为新对象
私有属性panTop4作为新对象
昏暗的panTop4作为新面板
Me.Controls.Add(panTop4)
'---
panTop4.Location =新点(0,0) '好的
panTop4.Size =新大小(frmWth,BorderWide)
panTop4W = panTop4.Size.Width
panTop4H = panTop4.Size.Height
panTop4.BackColor = Color.LightGray
'----按钮后退------------------------------------------- ---------------------------------------
将btnBack变暗为新按钮 b好的
panTop4.Controls.Add(btnBack)
'---
btnBack.Location =新点(1200,20)
btnBack.Text =后退"
btnBack.BackColor =颜色.黄色
btnBack.ForeColor =颜色.红色
btnBack.Width = 60
btnBack.Height = 25
btnBack.Name ="btnBack"
AddHandler btnBack.Click,AddressOf btnBack_Click
这是我的问题:
' - - 列表框 - - - - - - - - - - - - - - - - - - - - - - --------------------------------------
将lstGlbBox1变暗为新的ListBox
panBod4.Controls.Add(lstGlbBox1)
'---
lstGlbBox1.Location =新点(300,300)
lstGlbBox1.Text ="lstbox"
lstGlbBox1.BackColor =颜色.黄色
lstGlbBox1.ForeColor =颜色.黑色
lstGlbBox1.Width = 300
lstGlbBox1.Height = 300
lstGlbBox1.Name ="lstGlbBox1"
AddHandler lstGlbBox1.SelectedIndexChanged,AddressOf lstGlbBox1_SelectedIndexChanged
'------------------------------------------------- -----------------------------------
运行时错误:Private Sub Jumpto()
lstGlbBox1.Items.Clear()
类型为'object'的公共成员'item'不是founf."
I am adding controls to form at run time.I am doing the following with no problem:
add 5 'panels' to form
Private Property lstGlbBox1 As New Object
Private Property btnBack As New Object
Private Property panTop4 As New Object
Dim panTop4 As New Panel
Me.Controls.Add(panTop4)
'---
panTop4.Location = New Point(0, 0) 'OK
panTop4.Size = New Size(frmWth, BorderWide)
panTop4W = panTop4.Size.Width
panTop4H = panTop4.Size.Height
panTop4.BackColor = Color.LightGray
'----button back----------------------------------------------------------------------------------
Dim btnBack As New Button 'OK
panTop4.Controls.Add(btnBack)
'---
btnBack.Location = New Point(1200, 20)
btnBack.Text = "back"
btnBack.BackColor = Color.Yellow
btnBack.ForeColor = Color.Red
btnBack.Width = 60
btnBack.Height = 25
btnBack.Name = "btnBack"
AddHandler btnBack.Click, AddressOf btnBack_Click
This is my problem:
'----listbox----------------------------------------------------------------------------------
Dim lstGlbBox1 As New ListBox
panBod4.Controls.Add(lstGlbBox1)
'---
lstGlbBox1.Location = New Point(300, 300)
lstGlbBox1.Text = "lstbox"
lstGlbBox1.BackColor = Color.Yellow
lstGlbBox1.ForeColor = Color.Black
lstGlbBox1.Width = 300
lstGlbBox1.Height = 300
lstGlbBox1.Name = "lstGlbBox1"
AddHandler lstGlbBox1.SelectedIndexChanged, AddressOf lstGlbBox1_SelectedIndexChanged
'------------------------------------------------------------------------------------
Run time errors: Private Sub Jumpto()
lstGlbBox1.Items.Clear()
"Public member 'item' on type 'object' not founf."
'将选择模式设置为多个和扩展/简单.
lstGlbBox1.SelectionMode = SelectionMode.One
] lstGlbBox1.Items.Clear()
类型为对象"而不是基础上的公共成员项目"." ETC.
ETC.
' Set the selection mode to multiple and extended/simple.
lstGlbBox1.SelectionMode = SelectionMode.One
lstGlbBox1.Items.Clear()
"Public member 'item' on type 'object' not founf." ETC.
ETC.
'添加项目时,关闭ListBox的绘制.
lstGlbBox1.BeginUpdate()
因为表单空间被面板覆盖,所以我所有的控件都必须是gen.在程序中!
您能帮我吗?
' Shutdown the painting of the ListBox as items are added.
lstGlbBox1.BeginUpdate()
Because the form space is covered with panels, all my controls must be gen. in the program!
Can you help me?
推荐答案
我会尝试使用这样的语句
I would try to use statements like this
CType
( lstGlbBox1,System.ComponentModel.ISupportInitialize).BeginInit()跨度>
开始添加之前,
和
CType ( lstGlbBox1,System.ComponentModel.ISupportInitialize).EndInit()
完成后;
它可能会阻止事件在所有内容出现之前被触发
it might stop events being fired before everything's there
这篇关于面板上的控件,运行时生成的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!