VB.NET如何用代码的方式添加按钮
添加一个FlowLayoutPanel1(在工具箱--容器里面) 一个Button1
代码如下:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim url As String = InputBox("输入网站地址?", "输入", "http://")
If url = "" Then Return
Dim link As New LinkLabel
link.Text = url
link.AutoSize = True
FlowLayoutPanel1.Controls.Add(link)
AddHandler link.LinkClicked, AddressOf Link_LinkClicked
End Sub
Private Sub Link_LinkClicked(ByVal sender As System.Object, ByVal e As System.Windows.Forms.LinkLabelLinkClickedEventArgs)
Dim url As String = CType(sender, LinkLabel).Text
Process.Start(url)
End Sub
效果如图: