~~~~~高手帮小弟一个棘手问题~~~~~

vbchuxue 2010-05-19 09:43:33

一个窗体mainform在屏幕中任意位置,要求当单击cmdmove按钮后,程序在700毫秒内平滑移动到屏幕的最右端,并且窗体左端压线(窗体的left等于屏幕的宽度),再经800毫秒,窗体移动到单击cmdmove之前的位置(平滑)!
...全文
41 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
舉杯邀明月 2010-05-20
  • 打赏
  • 举报
回复
楼主可以把分给我了,
试一下这个代码:
Private Sub Command1_Click()
startleft = mainform.Left
endleft = Screen.Width
starttime = GetTickCount
'nowtemp = GetTickCount
nowtemp = 0
Do While (nowtemp <= 700)
'sleep 10
nowtemp = GetTickCount - starttime
If (nowtemp < 700) Then
steplength = nowtemp * (endleft - startleft) / 700
mainform.Left = startleft + steplength
Else
mainform.Left = endleft
End If
DoEvents
Loop
starttime = GetTickCount
'nowtemp = GetTickCount
nowtemp = 0
Do While (nowtemp <= 800)
'sleep 10
nowtemp = GetTickCount - starttime
If (nowtemp < 800) Then
steplength = nowtemp * (endleft - startleft) / 800
mainform.Left = endleft - steplength
Else
mainform.Left = startleft
enidf
DoEvents
Loop
End Sub

vbchuxue 2010-05-19
  • 打赏
  • 举报
回复
现在有代码如下:

Private Declare Function GetTickCount Lib "kernel32" () As Long
Private Sub Command1_Click()

startleft = mainform.Left
endleft = Screen.Width
starttime = GetTickCount
nowtemp = GetTickCount

Do While (nowtemp - starttime < 700)
'sleep 10
nowtemp = GetTickCount
steplength = (nowtemp - starttime) / 700* (endleft - startleft)
mainform.Left = startleft + steplength
DoEvents
Loop

starttime = GetTickCount
nowtemp = GetTickCount

Do While (nowtemp - starttime < 800)
'sleep 10
nowtemp = GetTickCount
steplength = (nowtemp - starttime) / 800* (endleft - startleft)
mainform.Left = endleft - steplength
DoEvents
Loop

End Sub

程序运行后,从右到左的过程有问题,不能回到原始位,而是比原始位稍左的位置,如何解决?
gilbe 2010-05-19
  • 打赏
  • 举报
回复
用timer控件,要平滑的话,每次移动距离小一点,比如1px,但是timer周期需要和屏幕右端的距离进行计算。
比如:窗体右端到屏幕右端的距离是700px,每次移动1px,那么timer=1,如果窗体右端到屏幕右端的距离是350px,每次移动1px,那么timer=700/350=2,如果距离超过700px,那么每次移动距离就得大于等于2px了。反之亦然。

7,763

社区成员

发帖
与我相关
我的任务
社区描述
VB 基础类
社区管理员
  • VB基础类社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧