我们专注攀枝花网站设计 攀枝花网站制作 攀枝花网站建设
成都网站建设公司服务热线:400-028-6601

网站建设知识

十年网站开发经验 + 多家企业客户 + 靠谱的建站团队

量身定制 + 运营维护+专业推广+无忧售后,网站问题一站解决

vb.net动态添加按钮,vb添加按钮控件

怎样指定一个动态增加按钮的事件(vb.net)

''' summary

成都创新互联公司从2013年开始,先为金昌等服务建站,金昌等地企业,进行企业商务咨询服务。为金昌企业网站制作PC+手机+微官网三网同步一站式服务解决您的所有建站问题。

''' 添加多个按钮到一个容器中.

''' /summary

''' param name="StartPos"所有按钮开始点./param

''' param name="ButtonSize"按钮的大小./param

''' param name="ButtonSpace"按钮的间距/param

''' param name="ButtonCount"按钮的总数/param

''' param name="AddingContainer"被添加到的容器/param

''' remarks/remarks

Private Sub AddButtons(ByVal StartPos As Point, ByVal ButtonSize As Size, _

ByVal ButtonSpace As Size, ByVal ButtonCount As Integer, _

ByVal AddingContainer As Control)

Dim mBtnPos As Point = StartPos

For ItemTemp As Integer = 0 To ButtonCount - 1

Dim NewButton As Button = New Button() With

mBtnPos.Y += ButtonSpace.Height + ButtonSize.Height

If mBtnPos.Y AddingContainer.Height Then

mBtnPos.Y = StartPos.Y

mBtnPos.X += ButtonSpace.Width + ButtonSize.Width

End If

NewButton.Text = String.Format(":", CStr(ItemTemp + 1))

AddHandler NewButton.Click, AddressOf btnzh_Click

AddingContainer.Controls.Add(NewButton)

Next

End Sub

Private Sub btnzh_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnzh.Click

Dim ItemCount As Integer = 0

Try

ItemCount = CInt(txtChoice.Text)

Catch ex As Exception

MessageBox.Show("您输入的数字无法解析为数字.")

Return

End Try

AddButtons(New Point(2, 2), New Size(60, 40), New Size(20, 30), ItemCount, Me)

End Sub

Private Sub btnzh_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)

End Sub

如何在vb.net里面动态添加控件

Private WithEvents NewTextBox As TextBox

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

Private Sub Command1_Click()

If NewTextBox Is Nothing Then

Set NewTextBox = Controls.Add("VB.TextBox", "cmdNew", Form1)

NewTextBox.Move 200, 200

NewTextBox.Width = Form1.Width - 450

NewTextBox.Height = Form1.Height - 1400

NewTextBox.Visible = True

End If

End Sub

Private Sub Command2_Click()

If NewTextBox Is Nothing Then

Exit Sub

Else

Controls.Remove NewTextBox

Set NewTextBox = Nothing

End If

End Sub

vb.net 动态填加按钮,点击按钮时在TextBox1中显示被点击的按钮名如button1

'vb.net2008

Public Class Form1

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

Dim j_MyButton As New ArrayList

For i = 0 To 5

Dim k1 As New Button

k1.SetBounds(20, 22 * i, 100, 20) '设置位置和大小(x y w h)

k1.Visible = True

AddHandler k1.Click, AddressOf my_button '委托点击事件

Me.Controls.Add(k1) '在主窗口内加入控件

j_MyButton.Add(k1)

j_MyButton(i).name = "发现" i "个MM"

j_MyButton(i).text = "My butten " i

Next

End Sub

Private Sub my_button(ByVal sender As System.Object, ByVal e As System.EventArgs)

TextBox1.AppendText(sender.name vbCrLf)

End Sub

End Class


网站名称:vb.net动态添加按钮,vb添加按钮控件
URL标题:http://mswzjz.cn/article/phsigg.html

其他资讯