performance - VB.NET Animated image class that uses a timer to advance frames - is this a good approach? -
vb.net, .net 4
hello,
i writing industrial control front-end has "fancy" graphics indicate states of machinery. example, indicate heaters on showing red wavy arrows emanating out picture of heater. accomplished creating class inherits picturebox , using timer advance images:
public class animatedpicturebox inherits picturebox private withevents timer new timers.timer public property interval double return timer.interval end set(byval value double) timer.interval = value end set end property public imagelist new list(of image) private nextimageindex integer = 0 public sub new(byval interval integer) mybase.new() timer = new timers.timer me.interval = interval me.sizemode = pictureboxsizemode.stretchimage me.visible = true end sub public sub new() me.new(100) end sub public sub beginanimation(byval [loop] boolean) timer.start() end sub public sub beginanimation() beginanimation([loop]:=true) end sub public sub stopanimation() timer.stop() end sub private sub timer_elapsed(byval sender object, byval e system.timers.elapsedeventargs) handles timer.elapsed invokecontrol(me, _ sub(x) x.image = x.imagelist(nextimageindex) x.nextimageindex += 1 if x.nextimageindex > x.imagelist.count - 1 x.nextimageindex = 0 end sub) end sub end class
where invokecontrol subroutine in module handles cross-thread marshalling of controls:
private sub invokecontrol(of t control)(byval control t, byval action action(of t)) if control.invokerequired try control.invoke(new action(of t, action(of t))(addressof invokecontrol), new object() {control, action}) catch ex exception '..handle error.. end try else action(control) end if end sub
my question "is alright way go or there obvious better way?" i'm not @ programming , worried having several of these objects embedded timers taxing cpu. suggestions appreciated!
thanks in advance, brian
p.s. went animated gifs other animation stuff, here, wanted able handle image formats can handle larger palette gif (if makes sense). in other words, when tried save of animations gifs, image quality took unacceptable hit.
i think approach. timers give lot of flexibility, , mike said, won't take cpu time speak of.
Comments
Post a Comment