vb 中两张图片,两个按钮,两个计时器
vb程序。有两张图片,两个计时器,两个按钮。要求单击“交换按钮”时,两图片1s交换一次;单击“闪烁按“接上面,单击闪烁按钮,每1s两图同时出现或消失...
vb 程序。有两张图片,两个计时器,两个按钮。要求单击“交换按钮”时,两图片1s交换一次;单击“闪烁按“
接上面,单击闪烁按钮,每1s两图同时出现或消失 展开
接上面,单击闪烁按钮,每1s两图同时出现或消失 展开
3个回答
展开全部
建议利用 imaglist 控件
或者 你可以颂禅轿互换另个picturebox 的位置,通往目的的路很多,你何必不变通下呢,先在两个图片框设置好图片试试我的代码吧,嘿嘿!
代码如下:
Private Sub Command1_Click()
Timer1.Enabled = Not Timer1.Enabled '按一野肆下开始 再按一下袭睁停止
Timer1.Interval = 1000
End Sub
Private Sub Command2_Click()
Timer2.Enabled = Not Timer2.Enabled '按一下开始 再按一下停止
Timer2.Interval = 1000
End Sub
Private Sub Form_Load()
Timer1.Enabled = False
Timer2.Enabled = False
End Sub
Private Sub Timer1_Timer()
Picture1.Visible = False '隐藏
Picture2.Visible = False
'下面交换位置
temx = Picture2.Left
temy = Picture2.Top
Picture2.Left = Picture1.Left
Picture2.Top = Picture1.Top
Picture1.Left = temx
Picture1.Top = temy
'下面显示
Picture1.Visible = True
Picture2.Visible = True
End Sub
Private Sub Timer2_Timer()
Picture1.Visible = Not Picture1.Visible
Picture2.Visible = Not Picture2.Visible
End Sub
或者 你可以颂禅轿互换另个picturebox 的位置,通往目的的路很多,你何必不变通下呢,先在两个图片框设置好图片试试我的代码吧,嘿嘿!
代码如下:
Private Sub Command1_Click()
Timer1.Enabled = Not Timer1.Enabled '按一野肆下开始 再按一下袭睁停止
Timer1.Interval = 1000
End Sub
Private Sub Command2_Click()
Timer2.Enabled = Not Timer2.Enabled '按一下开始 再按一下停止
Timer2.Interval = 1000
End Sub
Private Sub Form_Load()
Timer1.Enabled = False
Timer2.Enabled = False
End Sub
Private Sub Timer1_Timer()
Picture1.Visible = False '隐藏
Picture2.Visible = False
'下面交换位置
temx = Picture2.Left
temy = Picture2.Top
Picture2.Left = Picture1.Left
Picture2.Top = Picture1.Top
Picture1.Left = temx
Picture1.Top = temy
'下面显示
Picture1.Visible = True
Picture2.Visible = True
End Sub
Private Sub Timer2_Timer()
Picture1.Visible = Not Picture1.Visible
Picture2.Visible = Not Picture2.Visible
End Sub
展开全部
两个图片框 起名字起成唯顷 a b
两穗山烂个计猜漏时器 事件间隔 1000 是否有效 改成无效 false
代码如下
Dim x As Object
Private Sub Command1_Click()
Timer1 = True
Timer2 = False
End Sub
Private Sub Command2_Click()
Timer1 = False
Timer2 = True
End Sub
Private Sub Form_Load()
Set x = Controls.Add("VB.PictureBox", "x")
End Sub
Private Sub Timer1_Timer()
x.Picture = a.Picture
a.Picture = b.Picture
b.Picture = x.Picture
End Sub
Private Sub Timer2_Timer()
a.Visible = Not a.Visible
b.Visible = Not b.Visible
End Sub
两穗山烂个计猜漏时器 事件间隔 1000 是否有效 改成无效 false
代码如下
Dim x As Object
Private Sub Command1_Click()
Timer1 = True
Timer2 = False
End Sub
Private Sub Command2_Click()
Timer1 = False
Timer2 = True
End Sub
Private Sub Form_Load()
Set x = Controls.Add("VB.PictureBox", "x")
End Sub
Private Sub Timer1_Timer()
x.Picture = a.Picture
a.Picture = b.Picture
b.Picture = x.Picture
End Sub
Private Sub Timer2_Timer()
a.Visible = Not a.Visible
b.Visible = Not b.Visible
End Sub
追问
如果不选择再添加x,就是我只用两张图片来做这个。
追答
那你只能保存图片了。
然后换着LoadPicture了
修改如下
Dim x As Object 改成 dim x as integer
删除form load事件
Private Sub Form_Load()
Set x = Controls.Add("VB.PictureBox", "x")
End Sub
timer1事件修改如下
Private Sub Timer1_Timer()
if x=0 then
a.picture=loadpicture("c:\图片1.jpg")
b.picture=loadpicture("c:\图片2.jpg")
x=1
else
a.picture=loadpicture("c:\图片2.jpg")
b.picture=loadpicture("c:\图片1.jpg")
x=0
end if
End Sub
可以了
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
调试了半天终于搞好了一定要采纳啊。笑稿亏。。把2个图片放到D盘根目录并命名为0.jpg 和 1.jpg
Private Sub Command1_Click()
Timer1.Enabled = True
End Sub
Private Sub Command2_Click()
Image1.Picture = LoadPicture("d:\1.jpg")
Image2.Picture = LoadPicture("d:\0.jpg")
Image1.Visible = True
Timer2.Enabled = True
End Sub
Private Sub Form_Load()
Timer1.Enabled = False
Timer2.Enabled = False
Command1.Caption = "碰神交换"敬慎
Command2.Caption = "闪烁"
Timer1.Interval = 1000
Timer2.Interval = 1000
End Sub
Private Sub Timer1_Timer()
Static a As Integer
If a = 0 Then
a = a + 1
Else
If a = 1 Then
a = 0
End If
End If
Image1.Picture = LoadPicture("d:\" & a & ".jpg")
End Sub
Private Sub Timer2_Timer()
If Command2.Caption = "闪烁" Then
Image1.Visible = True
Image2.Visible = True
Command2.Caption = "闪烁中..."
Else
If Command2.Caption = "闪烁中..." Then
Image1.Visible = False
Image2.Visible = False
Command2.Caption = "闪烁"
End If
End If
End Sub
Private Sub Command1_Click()
Timer1.Enabled = True
End Sub
Private Sub Command2_Click()
Image1.Picture = LoadPicture("d:\1.jpg")
Image2.Picture = LoadPicture("d:\0.jpg")
Image1.Visible = True
Timer2.Enabled = True
End Sub
Private Sub Form_Load()
Timer1.Enabled = False
Timer2.Enabled = False
Command1.Caption = "碰神交换"敬慎
Command2.Caption = "闪烁"
Timer1.Interval = 1000
Timer2.Interval = 1000
End Sub
Private Sub Timer1_Timer()
Static a As Integer
If a = 0 Then
a = a + 1
Else
If a = 1 Then
a = 0
End If
End If
Image1.Picture = LoadPicture("d:\" & a & ".jpg")
End Sub
Private Sub Timer2_Timer()
If Command2.Caption = "闪烁" Then
Image1.Visible = True
Image2.Visible = True
Command2.Caption = "闪烁中..."
Else
If Command2.Caption = "闪烁中..." Then
Image1.Visible = False
Image2.Visible = False
Command2.Caption = "闪烁"
End If
End If
End Sub
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询