Maxscript .net Spinner

Maxscript .net Spinner

Anonymous
Not applicable
1,734 Views
4 Replies
Message 1 of 5

Maxscript .net Spinner

Anonymous
Not applicable
How do i get the spinner to scrub through values like the max spinner when the cursor is dragged up or down.
How do i place a decimal value in it as well?

Thanks


rollout NumericUpDownTestRollout "" height:50 width:80
(
dotNetControl upDown "System.Windows.Forms.NumericUpDown" align:#center height:50 width:50

on NumericUpDownTestRollout open do
(
upDown.Value = 50
upDown.Maximum = 100
upDown.Minimum = 0
)
)
createdialog NumericUpDownTestRollout
0 Likes
1,735 Views
4 Replies
Replies (4)
Message 2 of 5

paulneale
Advisor
Advisor
form=dotNetObject "form"

nud=dotNetObject "System.Windows.Forms.NumericUpDown"
nud.DecimalPlaces=2
nud.Increment=.1
nud.maximum=10
nud.minimum=-10
nud.ReadOnly=false
showProperties nud

form.controls.add nud
form.show()
Paul Neale

http://paulneale.com


Paul Neale




EESignature

0 Likes
Message 3 of 5

paulneale
Advisor
Advisor
Forgot to mention

enableAccelerators=false


so that you can type in the value as well.
Paul Neale

http://paulneale.com


Paul Neale




EESignature

0 Likes
Message 4 of 5

paulneale
Advisor
Advisor
And I completely forgot to answer the other question. You are going to have to use multiple event handlers and track the movement of the mouse your self.

http://www.penproductions.ca/tutorials/dotNet/numericUpDown/numericUpDown.htm


--Create a dotNet form control.
form=dotNetObject "form"

--Create a dotNet NumericUpDown control.
nud=dotNetObject "System.Windows.Forms.NumericUpDown"
nud.DecimalPlaces=2
nud.Increment=.1
nud.maximum=1000
nud.minimum=-10
nud.value=10
nud.ReadOnly=false

--This is needed so that we can type in the values as well as use the spinner.
enableAccelerators=false

--Set variables to hold the mouse position and current value of the spinner.
lastMousePos=0
curVal=0

--Mouse down function to set the variables above to the starting values.
fn nudMouseDown sender arg=
(
case arg.button of
(
--Check for the left mouse button
(arg.button.left):
(
lastMousePos=(arg.location).y
curVal=sender.value
)
--Check for the right mouse button
(arg.button.right):
(
sender.value=0
)
)
)

--On mouseMove event
fn nudMouseMove sender arg=
(
case arg.button of
(
--Check for the left mouse button.
(arg.button.left):
(
--Get the offset from the last position of the mouse
mouseOffSetY=(lastMousePos-arg.location.y)*.1
--Add that position to the curVal variable
curVal=curVal+=mouseOffSetY

--Check if the curVal is within limits of the spinner.
if curVal>=sender.minimum and curVal<=sender.maximum do
(
--Set the value of the spinner
sender.value=curVal
)
--Check if the value has gone above or below the min max values and set them.
--This is needed if the value changes more rapidly then the spinner can react.
if curVal<sender.minimum do sender.value=sender.minimum
if curVal>sender.maximum do sender.value=sender.maximum

--Set the lastMousePos value to the current value of the mouse.
lastMousePos=arg.location.y
)
)
)

--Create the event handlers
dotNet.addEventHandler nud "mouseDown" nudMouseDown
dotNet.addEventHandler nud "mouseMove" nudMouseMove
--Set the life time control of the spinner to be handled by dot net and not Max script.
--This stops garbage collections from deleting the event handlers.
dotNet.setLifeTimeControl nud #dotNet

--Add the NumericUpDown to the form and show the form.
form.controls.add nud
form.show()
Paul Neale

http://paulneale.com


Paul Neale




EESignature

0 Likes
Message 5 of 5

Anonymous
Not applicable
Thanks Paule,
I was searching the net for solutions and a lot of the sites and forums I found were just other people asking how to do it. There were no solutions. It's to bad the .net spinner by default does not do the same things as the max spinner. It is a bummer that the .net spinner requires a handful of code to equal that of max.

Thanks again.

John
0 Likes