单击图片框时如何使图片框从左向右移动一次? [英] How to make picture box move from left to right to left once when picture box is clicked?

查看:170
本文介绍了单击图片框时如何使图片框从左向右移动一次?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在制作一个程序来移动我的图片框,当从表格的左侧点击图片框到右侧然后从左侧点击并停止。

I'm working on a program to move my picture box when the picture box is clicked from the left side of the form to the right side then back to left and stops.

这些是我拥有的变量

我想弄清楚的是当我选择我的单选按钮0%然后点击我的图片框时我的图片将留在其中位置,只需一直移动到窗体的右侧,然后返回到窗体的左侧一次

what im trying to figure out is when i select my radio button 0% and then click my picturebox my picture will stay in its position and just move all the way to right side of the form and then back to the left side of the form once

推荐答案

试试这段代码,看看是否有帮助。它会将其移动到Form的右边缘然后返回到开始位置。

Try this code and see if it helps. It will move it to right edge of Form and then back to start position.

Option Strict On
Option Explicit On
Public Class Form1
    Dim pb As Point
    Dim clicked As Boolean
    Dim stp As Integer = 4
    Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        pb = PictureBox1.Location
        clicked = False
        Timer1.Interval = 50 ' milliseconds
    End Sub
    Private Sub PictureBox1_Click(sender As Object, e As EventArgs) Handles PictureBox1.Click
        If clicked Then Exit Sub
        clicked = True
        Timer1.Enabled = True
    End Sub
    Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick
        PictureBox1.Location = New Point(PictureBox1.Location.X + stp, PictureBox1.Location.Y)
        If PictureBox1.Right > ClientRectangle.Right Then stp = -stp
        If PictureBox1.Location.X <= pb.X Then Timer1.Enabled = False
    End Sub
End Class


这篇关于单击图片框时如何使图片框从左向右移动一次?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆