VBA,shape的移动 shape.incrementLeft 和 shape.incrementTop

 

实现移动

 

Sub ftest11()
Dim p1 As Shape
Dim t1 As Double

Set p1 = Worksheets("sheet7").Shapes.AddShape(msoShapeOval, 100, 100, 200, 100)
    p1.Fill.ForeColor.RGB = RGB(0, 0, 250)

With p1.ThreeD
   .Visible = True
   .Depth = 100
   .ExtrusionColor.RGB = RGB(255, 0, 0)
End With

t1 = Timer
i = 0
Do Until i >= 60
   DoEvents
   If Timer - t1 > 0.2 Then
      i = i + 1
      p1.IncrementLeft 10 * Rnd()
      p1.IncrementTop 10 * Rnd()
      t1 = Timer
   End If
   
Loop

p1.Delete

End Sub

 

实现发子弹类似效果

 

Sub ftest12()
Dim p1, p2 As Shape
Dim t1 As Double

Set p1 = Worksheets("sheet7").Shapes.AddShape(msoShapeOval, 100, 100, 50, 20)
    p1.Fill.ForeColor.RGB = RGB(0, 0, 250)


t1 = Timer
i = 0
Do While True
   DoEvents

       
   If Timer - t1 > 1 Then
   
      Set p2 = p1.Duplicate
      i = i + 1
      p2.IncrementLeft 100 * i
      t1 = Timer
      
'        If i > 1 Then
'           p2.Delete   '如何实现子弹的消失呢
'        End If
      
   End If
Loop

End Sub

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值