본문 바로가기
Programing/vb.net

visual basic,비주얼베이직,vb .net 강좌-size mode,Timer,PictureBox 자동으로 이동하는 이미지

by 고니피즈 2017. 1. 27.
반응형


타이머를 이용하여 자동적으로 좌측으로 움직이다가 버튼 클릭시 스톱 또는 재시작하는 프로그램입니다..

타이머 와 버튼2개 픽쳐박스를 세팅합니다.


픽쳐박스 상단 역삼각형을 클릭해서 이미지를 임포트 하고 size mode  도 위와 같이 셋팅합니다.



타이머의 속성을 위와같이 해줍니다.


Public Class Form1


    Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick

        If PictureBox1.Left <= 0 Then '이미지가 화면밖으로 나가면 처음부터 다시 시작하도록 세팅

            PictureBox1.Left = Me.Width

        End If


        PictureBox1.Left -= 20

    End Sub


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


        Timer1.Start()

    End Sub


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

        Timer1.Stop()

    End Sub

End Class


반응형