十年网站开发经验 + 多家企业客户 + 靠谱的建站团队
量身定制 + 运营维护+专业推广+无忧售后,网站问题一站解决
见下面代码,放置定时器,按钮,标签各一个
创新互联是网站建设技术企业,为成都企业提供专业的网站制作、网站建设,网站设计,网站制作,网站改版等技术服务。拥有十余年丰富建站经验和众多成功案例,为您定制适合企业的网站。十余年品质,值得信赖!
Public Class Form1
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick '定时器
If Label1.Right Me.Width Then
Label1.Left += 10'移动距离
Else
Label1.Left = 0
End If
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click '开启或者关闭定时器
Timer1.Interval = 1000 '1秒
If Timer1.Enabled = False Then
Timer1.Start() '开定时器
Else
Timer1.Stop() '关定时器
End If
End Sub
End Class
建立滚动条的方法如下:
(1)将鼠标移到ToolBox内的WinForm标签页的HscrollBar控件上,单击鼠标左键。
(2)将指针移至窗体中适当的位置,按住鼠标左键并拖动鼠标将HscrollBar控件调整到合适的大小放开左键。
(3)同样,再在Form上设置一个VscrollBar控件。
Dim i As Integer
For i = 0 To Me.Width - Button1.Width 'me为容器,典型的是form1
Button1.Left += 1
Windows.Forms.Application.DoEvents()
Next
原理:不断地变化button1的X轴,使其向右移,同样,只要控制好其x,y轴,就可以变化button的变化
如果是做小游戏,建议弄成类吧,把其中的左(右)移或对角其它移动弄成其接口,以便操作。
由于涉及内容太多,不再详述。原理都一样
'我试过可以,你试试
Imports System.Drawing
Imports System.Windows.Forms
Public Class Form1
'******************************************
Private oOriginalRegion As Region = Nothing
' 用于窗体移动
Private bFormDragging As Boolean = False
Private oPointClicked As Point
'******************************************
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
End Sub
Private Sub Form1_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Me.MouseDown
Me.bFormDragging = True
Me.oPointClicked = New Point(e.X, e.Y)
End Sub
Private Sub Form1_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Me.MouseMove
If Me.bFormDragging Then
Dim oMoveToPoint As Point
' 以当前鼠标位置为基础,找出目标位置
oMoveToPoint = Me.PointToScreen(New Point(e.X, e.Y))
' 根据开始位置作出调整
oMoveToPoint.Offset(Me.oPointClicked.X * -1, _
(Me.oPointClicked.Y + _
SystemInformation.CaptionHeight + _
SystemInformation.BorderSize.Height) * -1)
' 移动窗体
Me.Location = oMoveToPoint
End If
End Sub
Private Sub Form1_MouseUp(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Me.MouseUp
Me.bFormDragging = False
End Sub
End Class