Notifications
Clear all

[Closed] Dotnet Timer

 MZ1

in max timer we can access timer.ticks,but in dotnet timer i cant!anyone can show an example of using dotnet timer and his methods?, how i can use
[left]Tick sender e = ( 鈥? )
[/left]
event handler?.

4 Replies

http://msdn.microsoft.com/en-us/library/system.windows.forms.timer.aspx


/*********** START *********/
fn onTick s e =
(
	format "time: %
	sender: %
"  localTime s
	-- Stop on first TICK
	s.Stop()
)
ftm = dotnetobject "System.Windows.Forms.Timer"
ftm.Interval = 2000 -- every two seconds

-- Add Event Handler And Start
dotnet.addEventHandler ftm "Tick" onTick
ftm.Start()

/*********** STOP **********/
-- Stop Timer
ftm.Stop()
-- Remove Event Handler
dotnet.removeAllEventHandlers ftm
-- Dispose Timer
ftm.Dispose()

or
http://msdn.microsoft.com/en-us/library/system.timers.timer.aspx


ttm = dotnetobject "System.Timers.Timer"
ttm.Interval = 2000 -- every two seconds

-- Add Event Handler And Start
dotnet.addEventHandler ttm "Elapsed" onTick
ttm.Start()
-- Stop Timer
ttm.Stop()

 MZ1

Tank you for your answer,but i don鈥檛 know how i can access tick number and use it in my script!.how i can convert this code to dotnet code?.
——start code
rollout test 鈥淭est Timer鈥?br>
(
timer clock 鈥渢estClock鈥?interval:1000 –tick once a second
label testLabel 鈥?鈥?br>
on clock tick do
(
testLabel.text = (clock.ticks as string)
)
)
createDialog test
—–end code
鈥搈y goal is clock.ticks

The argument passed to the 鈥榚lapsed鈥?event handler includes the 鈥楽ignalTime鈥? You can use that to determine precisely how much time has gone by.

鈥ut it sounds like you might just need to increment a counter?

rollout test "Test Timer"
(
	label signalTime ""
	label elapsedTime ""

	local startTime
	local myTimer = dotnetobject "System.Timers.Timer" 1000 autoreset:true
 	
	fn onElapsed sender args =
	(
		signalTime.text = args.SignalTime.ToString()
		elapsedTime.text = (args.SignalTime.Subtract(startTime)).ToString()
	)

	on test open do
	(
		dotnet.AddEventHandler myTimer #elapsed onElapsed
		startTime = (dotnetclass "datetime").now
		myTimer.Start()
	)

)
try (destroyDialog test) catch()
createDialog test
 MZ1

Tank you for your answer.actually yea,counter is a good and simple way.and maybe best way!
I鈥檓 going to make UI for loading archive animations on character.first i made a listbox,but it was not enough good.next idea was using windows-media in UI for showing animations preview,but it has many bugs such as video size don鈥檛 work with script!and many other bugs.next idea was making a button for showing image sequences.but max dialog has a bug in update that cause jump in frames and bad showing images.finally i decide to use dotnet form instead of max UI,it was perfect!my code is not complete but take a look at.

——-CodeStart———————–
BitmapArray =(getfiles 鈥淐:\Test\Pre*.bmp鈥? 鈥?Path of image sequenses to show in botton
(
hForm = dotNetObject 鈥淪ystem.Windows.Forms.Form鈥?br>
hForm.size = dotNetObject 鈥淪ystem.Drawing.Size鈥?300 300
hForm.topmost = true

theTimer = dotNetObject "System.Windows.Forms.Timer"
theTimer.interval = 25
    
btn = dotNetObject "System.Windows.Forms.Button"
btn.size = dotNetObject "System.Drawing.Size" 200 200
btn.image = dotNetObject "System.Drawing.bitmap" BitmapArray[1]

global counter=1
fn ChangeBitmap =
    (
        btn.text = (Counter as string)
        Counter+=1
        if counter< BitmapArray.count then btn.image = dotNetObject "System.Drawing.bitmap" BitmapArray[counter] else counter = 1
        )
        
        dotnet.addEventHandler theTimer "tick" ChangeBitmap

    hForm.controls.add btn
    
        fn btnMouseEnter = 
    (
    if counter< BitmapArray.count then btn.image = dotNetObject "System.Drawing.bitmap" BitmapArray[1] else counter = 1
    theTimer.Enabled=true
    )

    dotNet.addEventHandler btn "MouseEnter" btnMouseEnter
    
        fn btnMouseLeave =
    (
    theTimer.Enabled=false
    counter = 1
    )

    dotNet.addEventHandler btn "MouseLeave" btnMouseLeave
    
    hForm.show()

)

————–end of code——————————–

my question is : there is beter way to showing preview in boutton? I read in maxscript help that activex is not good way but instead you can use dotnet.how? how i can use dotnet to make a player in UI?