vb.net改变按钮位置,vb控件在窗体上的位置

VB.net 控件的位置如何随窗口的变化而变化

两种方法,一种是固定窗口大小,一种是控件在窗口大小改变时,自动按窗口位置进行改变;

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

以上为个人看法,手打很辛苦,希望采纳,谢谢您的支持。

谢谢您的支持,有任何疑问欢迎您再次通过此渠道提问,让大家共同解决,共同进步!

以上回答仅为“百度规则”,没有任何违法行为,请楼主采纳,谢谢!

VB.net怎么制作一个可以拖动的button?

基本思路是在按钮的 MouseMove 事件中检测鼠标左键的状态,如果是按下就跟着移动按钮的位置。

VB.net如何让按钮在窗体随机移动

按钮对象.left=rnd*100

按钮对象.top=rnd*100

把100这个值替换成实际窗体大小即可

vb使按钮左右移动

比如有3个按钮,1,2,3,3在1,2之间。

取得1按钮的右边位置,left属性+width属性,2按钮的左位置,就是left属性。

再定位3的left就可以了。

Dim

a

Private

Sub

Command2_Click()

Timer1.Enabled

=

True

End

Sub

Private

Sub

Form_Click()

Timer1.Enabled

=

False

End

Sub

Private

Sub

Form_Load()

Timer1.Interval

=

100

a

=

20

End

Sub

Private

Sub

Timer1_Timer()

If

Command3.Left

Command1.Left

+

Command1.Width

Then

a

=

20

If

Command3.Left

+

Command3.Width

Command2.Left

Then

a

=

-20

Command3.Left

=

Command3.Left

+

a

End

Sub

VB.NET改变鼠标位置和让鼠标消失

几乎找不到真正VB.NET的api,都是自己将VB的api改成VB.NET的api,我的理解是声明中对应输入是H的地方保留Long,其他的Long改成Integer,既然VB.NET连MSDN都找不到较全的api说明,不保证api的用法在VB.NET其他版本中适用。

给你个好玩的例子,包括鼠标的隐藏(Ctrl_↓)、显示(Ctrl_↑),移动、点击

在Form1上放上2个TextBox,其中TextBox1.Multiline = True,并且面积大些,2个Button,运行后在TextBox1中点击一下会记录位置,移开鼠标,点击移动或点击Button,可模拟在TextBox1中的点击

Public Class Form1

Public My_MousePosition As Point

'模拟鼠标移动、点击

Declare Sub mouse_event Lib "user32" (ByVal dwFlags As Long, ByVal dx As Integer, ByVal dy As Integer, ByVal cButtons As Long, ByVal dwExtraInfo As Long)

'定义光标的位置

Declare Function SetCursorPos Lib "user32" Alias "SetCursorPos" (ByVal x As Integer, ByVal y As Integer) As Integer

'鼠标的隐藏

Declare Function ShowCursor Lib "user32" Alias "ShowCursor" (ByVal bShow As Integer) As Integer

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

TextBox1.Multiline = True

Button1.Text = "点击"

Button2.Text = "移动"

Me.KeyPreview = True

End Sub

Private Sub Form1_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles Me.KeyDown

If e.Control And e.KeyCode = Keys.Down Then ShowCursor(0)

If e.Control And e.KeyCode = Keys.Up Then ShowCursor(1)

End Sub

Private Sub Form1_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Me.MouseMove

TextBox2.Text = MousePosition.X " " MousePosition.Y

End Sub

Private Sub TextBox1_MouseClick(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles TextBox1.MouseClick

My_MousePosition = MousePosition

TextBox1.Text = My_MousePosition.X " " My_MousePosition.Y vbCrLf

End Sub

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

SetCursorPos(My_MousePosition.X, My_MousePosition.Y)

mouse_event(H2, 0, 0, 0, 0)

mouse_event(H4, 0, 0, 0, 0)

End Sub

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click

SetCursorPos(My_MousePosition.X, My_MousePosition.Y)

End Sub

End Class

其中

mouse_event Lib "user32" (ByVal dwFlags As Long

的dwFlags的代码是

Const MOUSEEVENTF_LEFTDOWN = H2

Const MOUSEEVENTF_LEFTUP = H4

Const MOUSEEVENTF_MIDDLEDOWN = H20

Const MOUSEEVENTF_MIDDLEUP = H40

Const MOUSEEVENTF_MOVE = H1

Const MOUSEEVENTF_ABSOLUTE = H8000

Const MOUSEEVENTF_RIGHTDOWN = H8

Const MOUSEEVENTF_RIGHTUP = H10


分享标题:vb.net改变按钮位置,vb控件在窗体上的位置
路径分享:http://azwzsj.com/article/hegise.html