Public Sub GenerateDynamiceButton()
'建立 坐标位置的变数, 方便一会儿安排 自动生产的button 的位置
Dim x As Integer = 0
' 建造新的 button
Dim MyButton As New Button
'设定这新的button 的阔度
'设定这新的button 的高度
' 和重设x 坐标+ = 0, 令到位置由头开始
'设定 TOP 的 坐标位置令他可以和上一排的有10个PIXEL 的距离
y += MyButton.Height + 10
x = 0
End If
'设定文字 和 位置
' Set the text and set its top and left based on its dimensions and count
MyButton.Text = "My Button" ButtonIndex
'设定 TOP 的 坐标位置
MyButton.Top = y
x += 1
'设定 BUTTON CLICK EVENT
AddHandler MyButton.Click, AddressOf MyButton_Click
'把button 加到 form 中
Me.Controls.Add(MyButton)
Next
End Sub
'处理 button click event
Private Sub MyButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
Dim btn As Button = sender
'pop up 一个自己button 的字的message
MsgBox(btn.Text)
本来有个属性FlatStyle设置为Popup基本上能实现这个情况,怎奈有个线框怎么也弄不掉.FlatAppearance.BorderSize设置为0不起作用,只对Flat有用,所以用代码在Flat和Popup两种风格之间切换.
'在鼠标进入时设置为浮雕风格
Private Sub Button1_MouseEnter(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.MouseEnter
Button1.FlatStyle = FlatStyle.Popup
'离开时设置为平面风格,这样像标签一样只剩下文字,当然要FlatAppearance.BorderSize设置为0
Private Sub Button1_MouseLeave(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.MouseLeave
Button1.FlatStyle = FlatStyle.Flat
'另外把UseVisualStyleBackColor 设置为 False也会好看一点.
最简单的方法是鼠标选中,然后按上下左右方向键移动,然后再属性中锁定位置
基本思路是在按钮的 MouseMove 事件中检测鼠标左键的状态,如果是按下就跟着移动按钮的位置.
制作一个按钮:
Dim my_Button As New Button
Me.Controls.Add(my_Button)
以上就是土嘎嘎小编为大家整理的vb.net按钮位置相关主题介绍,如果您觉得小编更新的文章只要能对粉丝们有用,就是我们最大的鼓励和动力,不要忘记讲本站分享给您身边的朋友哦!!