大橙子网站建设,新征程启航

为企业提供网站建设、域名注册、服务器等服务

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添加按钮控件
网站路径:http://dzwzjz.com/article/phsigg.html
在线咨询
服务热线
服务热线:028-86922220
TOP