我正在尝试制作一些图像来做我看过许多Microsoft应用程序使用的漂亮的幻灯片。运动开始缓慢的那一步加速到那里的一半,然后在它的新位置进行一个很好的缓慢停止。我已经计算出所有计算结果,获取并设置图片框位置,使用console.writeline
确认图像位置正确,甚至是以简化格式运行的测试运行。
但是在完整的版本中,它并没有重新粉刷图像。事实上,在脚本运行时看起来根本没有发生任何事情。我尝试过Me.Refresh()
,Invalidate()
,Timer.Enabled = True/False
和Me.Update()
。其中没有一个有效。最后一步是最令人沮丧的:我在最后调用我的SetPanelLocation()
方法,以确保面板最终位于最终位置,无论移动是否有效。在这个调用中没有任何事情发生,即使在这个例程失败之后,我可以从另一个用户事件中调用相同的方法,它会再次开始工作,就像没有错。
我正在创建自己的名为clsFeedImageBox
的PictureBox类,它继承了包含此功能的PictureBox
(以及其他功能)。每张图像只有300x225像素,因此它们不是需要花费大量时间重绘的大量图像。此类的每个实例都在一个公共Forms.SplitterPanel
中。我习惯性地使用了很多评论,所以我把它们留在了这里,也许它们会增添一些亮点。
Public Class clsFeedImgBox
Inherits PictureBox
Private iRank As Integer 'rank in whatever feed this file gets put in
Private iRankTarget As Integer 'rank to move to when rank feed event starts
Private iTopStart As Integer 'starting top location before feed event
Private iTopTarget As Integer 'final Top location after feed event
Private WithEvents tMyTimer As New System.Timers.Timer
Private WithEvents oParent As FeedBase 'splitter panel, all location info comes from the parent
Public Sub New(ByRef sender As FeedBase, ByVal rank as Integer)
'set objects
oParent = sender
'set .Image property to pre-made thumbnail
Image.FromFile(ThumbPath) 'ThumbPath is a property which is set by this point (some code has been removed)
'setup initial position
setPanelLocation(rank)
'set autosize
Me.SizeMode = PictureBoxSizeMode.StretchImage
'set Image Scroll timer interval to 20 fps (1000 / 20 = 50)
tMyTimer.Interval = 50
End Sub
Public Sub scroll(ByVal newRank As Integer)
'setPanelLocation(newRank) <== this works, timed movements don't
iRankTarget = newRank
iTopStart = Me.Top
iTopTarget = oParent.ImgTop(newRank) 'gets an integer for the new Top location
tMyTimer.Start()
End Sub
Private Sub myScrollStep() Handles tMyTimer.Elapsed
'tMyTimer.Enabled = False 'this idea with the enabled = True at the end didn't work
iTickCount += 1
Dim iScrollPerc As Integer 'scroll % between Start and End * 100
iScrollPerc = oParent.ScrollStep(iTickCount, Rank) 'this part works
Console.WriteLine(strThumbName & " scrollPerc: " & iScrollPerc.ToString)
If iScrollPerc >= 100 Then
'scroll event complete
Console.WriteLine(strThumbName & " SetFinalLocation")
Me.setPanelLocation(iRankTarget) '<== This line doesn't work here, but works when called by other means
'stop Feed updates
tMyTimer.Stop()
'reset iTickCount for next movement
iTickCount = 0
Else
'scrolling still going
Dim newTop As Integer
newTop = Math.Round(iTopTarget - (((100 - iScrollPerc) * (iTopTarget - iTopStart)) / 100)) 'this part works
'Console.WriteLine(strThumbName & " TopTarget: " & newTop)
Me.Top = newTop 'Nothing happens here
End If
'Me.Left = oParent.ImgLeft
'Me.Width = oParent.ImgWidth
'Me.Height = oParent.ImgHeight 'that didn't work
'Me.Refresh() 'this didn't work
'Invalidate() 'this didn't do much good either
'Me.Update() 'Aaaaand no cigar, time for StackOverflow
'tMyTimer.Enabled = True
End Sub
Public Sub setPanelLocation(ByVal rank As Integer)
iRank = rank
Me.MyRePaint()
End Sub
Public Sub MyRePaint()
'repaint image box with everything in it's current rank
Me.Left = oParent.ImgLeft
Me.Top = oParent.ImgTop(iRank)
Me.Width = oParent.ImgWidth
Me.Height = oParent.ImgHeight
End Sub
End Class
是什么给出的? VB.NET必须有一些内部工作方式可以帮助我解决这个问题。我正在使用VS 2012和Win8