Notifications
Clear all

[Closed] dotNet UI

This stuff is exciting to mess with. I’m diving in head first just messing around with all kinds of stuff. Very cool stuff. You’ve been super helpful through all of this. Thanks for your patience Lo.

Now is it easy to modifier the head and dialog style?
I looked through the help file on here http://www.scriptspot.com/bobo/mxs9/dotNet/dotNetObject_System.Windows.Forms.Form.html

Wasn’t sure exactly what settings I would be looking to adjust to do so.

Next I’m going to be working on what would be a dotNet subrollout example and then I’ll post it for everyone to see.

 lo1

I don’t think there is a simple way of changing the colors and fonts of the window frame, that is, without handling the frame painting yourself.

No worries.
It’s not to that important really.

So when I create a button and attempt to make it a flat style button it still seems to take on a border color being white?
How do I remove the border of the button so its just flat.


theFont = dotnetobject "System.Drawing.Font" "Arial" 9

fn buttonFactory X Y W H fCol bCol txt =
(
	local theBut = dotNetObject "button"
	theBut.Font = theFont
	theBut.flatStyle=theBut.flatStyle.flat
	theBut.Bounds = dotNetObject "System.Drawing.Rectangle" X Y W H
	theBut.BackColor = (dotNetClass "System.Drawing.Color").fromARGB bCol[1] bCol[2] bCol[3]
	theBut.ForeColor = (dotNetClass "System.Drawing.Color").fromARGB fCol[1] fCol[2] fCol[3]
	theBut.TextAlign = theBut.TextAlign.MiddleCenter
	theBut.Text = txt
	theBut
)

--//Buttons
btnGrind = buttonFactory 308 135 74 24 [255,255,255] [61,148,178] "Grind"

TheForm = dotNetObject "Form"
TheForm.controls.addRange #(btnGrind)

TheForm.bounds = dotNetObject "system.drawing.rectangle" 500 500 565 225
TheForm.backColor = TheForm.backColor.fromARGB 153 153 153

--Set the parent of the form to be Max. 
--Get the max handle pointer.
maxHandlePointer=(Windows.GetMAXHWND())

--Convert the HWND handle of Max to a dotNet system pointer
sysPointer = DotNetObject "System.IntPtr" maxHandlePointer

--Create a dotNet wrapper containing the maxHWND
maxHwnd = DotNetObject "MaxCustomControls.Win32HandleWrapper" sysPointer

--Show the Max form using the wrapper. 
TheForm.Show (maxHwnd)

 lo1
theBut.flatAppearance.BorderSize = 0

So I wanted to work on complete a first script to get a feel for how things work and see a script from start to finish.
This script simply takes the values in the spinners and calculates the even spacing between the number of objects set.

I’ve got few questions for you guys.

What’s the best way to handle the values updating when the spinner value is changed? Right now its a mouseover which is way to intense considering the users mouse may hover but never change the value

The users can change to make the script dependant on the objects width or the spacing width by clicking on the label/button. The function that controls the states of those checkbuttons could probably be written a bit more efficiently. It seems redundant.

Lastly overall the code, could it be written a bit more efficiently, if so in what parts and how?

Thanks guys.

Once this is finished i’ll begin working on putting together a subrollout reference.


--//Font 1
theFont = dotnetobject "System.Drawing.Font" "Arial" 9
--//Font h2
H2FontStyle = dotNetClass "System.Drawing.FontStyle"
H2Font = dotnet.combineenums H2FontStyle.bold

--//Preview array
previewArr = #("O - O - O - O - O - O","- O - O - O - O - O - O -","- O   O   O   O   O   O -")
	
enableAccelerators=false --This is needed so that we can type in the values as well as use the spinner. 

fn fnUpdateValues = (
	print "Calculating"
	if cbObjectWidth.checked == true do (--//ObjectWidth based
		if dlSpaceType.SelectedIndex + 1 == 1 do (--//Betweens Only
			newVal = (spTotalWidth.value-(spSpaceWidth.value*(spNumObjects.value-1)))/spNumObjects.value
			spObjectWidth.value = newVal
		)
		if dlSpaceType.SelectedIndex + 1 == 2 do (--//Ends/Betweens
			newVal = (spTotalWidth.value-(spSpaceWidth.value*(spNumObjects.value+1)))/spNumObjects.value
			spObjectWidth.value = newVal
		)
	)
	if cbSpaceWidth.checked == true do (--//SpaceWidth based
		if dlSpaceType.SelectedIndex + 1 == 1 do (--//Betweens Only
			newVal = (spTotalWidth.value-(spNumObjects.value*spObjectWidth.value))/(spNumObjects.value-1)
			spSpaceWidth.value = newVal
		)
		if dlSpaceType.SelectedIndex + 1 == 2 do (--//Ends/Betweens
			newVal = (spTotalWidth.value-(spNumObjects.value*spObjectWidth.value))/(spNumObjects.value+1)
			spSpaceWidth.value = newVal
		)
	)
)

fn nudMouseMove sender arg =
(
	fnUpdateValues()
)

fn PreviewFactory X Y W H fCol bCol txt =
(
	local theLab = dotNetObject "Label"
	theLab.Font = dotNetObject "System.Drawing.Font" "Arial" 12 H2Font
	theLab.Bounds = dotNetObject "System.Drawing.Rectangle" X Y W H
	theLab.BackColor = (dotNetClass "System.Drawing.Color").fromARGB bCol[1] bCol[2] bCol[3]
	theLab.ForeColor = (dotNetClass "System.Drawing.Color").fromARGB fCol[1] fCol[2] fCol[3]
	theLab.TextAlign = theLab.TextAlign.MiddleCenter
	theLab.Text = txt
	theLab
)

fn labelFactory X Y W H fCol bCol txt =
(
	local theLab = dotNetObject "Label"
	theLab.Font = theFont
	theLab.Bounds = dotNetObject "System.Drawing.Rectangle" X Y W H
	theLab.BackColor = (dotNetClass "System.Drawing.Color").fromARGB bCol[1] bCol[2] bCol[3]
	theLab.ForeColor = (dotNetClass "System.Drawing.Color").fromARGB fCol[1] fCol[2] fCol[3]
	theLab.TextAlign = theLab.TextAlign.MiddleRight
	theLab.Text = txt
	theLab
)

fn checkButtonFactory X Y W H fCol bCol txt enabled =
(
	local theBut = dotNetObject "CheckBox"
	theBut.Font = theFont
	theBut.flatAppearance.BorderSize = 0
	theBut.flatStyle=theBut.flatStyle.flat
	theBut.appearance = theBut.appearance.button
	theBut.Bounds = dotNetObject "System.Drawing.Rectangle" X Y W H
	theBut.BackColor = (dotNetClass "System.Drawing.Color").fromARGB bCol[1] bCol[2] bCol[3]
	theBut.ForeColor = (dotNetClass "System.Drawing.Color").fromARGB fCol[1] fCol[2] fCol[3]
	theBut.TextAlign = theBut.TextAlign.MiddleRight
	theBut.Text = txt
	theBut.Checked = enabled
	--theBut.Enabled = NOT enabled
	theBut.tag = enabled
	theBut
)

fn spinnerlFactory X Y W H minV maxV dec val enabled =
(
	local theSpn = dotNetObject "NumericUpDown"
	theSpn.Bounds = dotNetObject "System.Drawing.Rectangle" X Y W H
	theSpn.DecimalPlaces = dec
	theSpn.Increment = .1
	theSpn.minimum = minV
	theSpn.maximum = maxV
	theSpn.value = val
	theSpn.ReadOnly = false
	theSpn.Enabled = enabled
	dotNet.addEventHandler theSpn "mouseDown" nudMouseDown
	dotNet.addEventHandler theSpn "mouseMove" nudMouseMove
	theSpn
)

fn cmbBoxFactory X Y W H items =
(
	local theCmb = dotNetObject "ComboBox"
	theCmb.Bounds = dotNetObject "System.Drawing.Rectangle" X Y W H
	theCmb.DropDownStyle = theCmb.DropDownStyle.DropDownList
	theCmb.items.addRange items
	theCmb.SelectedIndex = 0
	theCmb
)

--//UI Items
lbSpacerPreview= PreviewFactory 24 24 195 36 [255,255,255] [61,148,178] previewArr[1]
lbTotalWidth = labelFactory 8 80 100 24 [0,0,0] [200,200,200] "Total Width:"
spTotalWidth = spinnerlFactory 118 83 100 21 (-999999999) (999999999) 2 960.0 true
lbNumObjects= labelFactory 8 114 100 24 [0,0,0] [200,200,200] "# Objects:"
spNumObjects = spinnerlFactory 118 117 100 21 (-999999999) (999999999) 0 4 true
cbObjectWidth = checkButtonFactory 12 148 100 24 [0,0,0] [200,200,200] "Object Width:" true
spObjectWidth = spinnerlFactory 118 151 100 21 (-999999999) (999999999) 2 60.0 false
cbSpaceWidth = checkButtonFactory 12 182 100 24 [0,0,0] [200,200,200] "Space Width:" false
spSpaceWidth  = spinnerlFactory 118 185 100 21 (-999999999) (999999999) 2 16.0 true
lbSpaceType = labelFactory 8 216 100 24 [0,0,0] [200,200,200] "Space Type:"
dlSpaceType = cmbBoxFactory 118 218 100 21 #("Betweens Only","Ends/Betweens","Ends Only")


--//Actions	
fn fnSelectedTyped s e =
(
	type = dlSpaceType.SelectedIndex
	lbSpacerPreview.text = previewArr[type+1]
	fnUpdateValues()
)

fn fnSpaceBased s e =
(
	if s.checked == true then (
		cbObjectWidth.checked = false
		spObjectWidth.enabled = true
		spSpaceWidth.enabled = false
	)else(
		cbObjectWidth.checked = true
		spObjectWidth.enabled = false
		spSpaceWidth.enabled = true
	)
	fnUpdateValues()
)

fn fnObjectBased s e =
(
	if s.checked == true then (
		cbSpaceWidth.checked = false
		spSpaceWidth.enabled = true
		spObjectWidth.enabled = false
	)else(
		cbSpaceWidth.checked = true
		spSpaceWidth.enabled = false
		spObjectWidth.enabled = true
	)
	fnUpdateValues()
)

--//Event Handlers
dotnet.addEventHandler cbObjectWidth "CheckStateChanged" fnObjectBased
dotnet.addEventHandler cbSpaceWidth "CheckStateChanged" fnSpaceBased
dotnet.addEventHandler dlSpaceType "SelectedIndexChanged" fnSelectedTyped	



TheForm = dotNetObject "Form"
TheForm.controls.addRange #(lbSpacerPreview,lbTotalWidth,spTotalWidth,lbNumObjects,spNumObjects,cbObjectWidth,spObjectWidth,cbSpaceWidth,spSpaceWidth,lbSpaceType,dlSpaceType)

TheForm.bounds = dotNetObject "system.drawing.rectangle" 500 500 260 300
TheForm.backColor = TheForm.backColor.fromARGB 200 200 200
TheForm.text = "Spacer v1.0"

--Set the parent of the form to be Max. 
--Get the max handle pointer.
maxHandlePointer=(Windows.GetMAXHWND())

--Convert the HWND handle of Max to a dotNet system pointer
sysPointer = DotNetObject "System.IntPtr" maxHandlePointer

--Create a dotNet wrapper containing the maxHWND
maxHwnd = DotNetObject "MaxCustomControls.Win32HandleWrapper" sysPointer

--Show the Max form using the wrapper. 
TheForm.Show (maxHwnd)


1 Reply
 lo1
(@lo1)
Joined: 1 year ago

Posts: 0

Use the numericUpDown control’s ValueChanged event

There are some exceptions when running the code, the nudMouseDown function is undefined.
I’ll try to have a more detailed look at the code tomorrow.

Alright.
Ill look into that and change that so when you go over the code tomorrow it will have those newer operators included in it.
Thanks Lo!

Very interesting topic! Keep up the good work.

Changed the code to have the value changed event.


--//Font 1
theFont = dotnetobject "System.Drawing.Font" "Arial" 9
--//Font h2
H2FontStyle = dotNetClass "System.Drawing.FontStyle"
H2Font = dotnet.combineenums H2FontStyle.bold

--//Preview array
previewArr = #("O - O - O - O - O - O","- O - O - O - O - O - O -","- O   O   O   O   O   O -")
	
enableAccelerators=false --This is needed so that we can type in the values as well as use the spinner. 

fn fnUpdateValues = (
	if cbObjectWidth.checked == true do (--//ObjectWidth based
		if dlSpaceType.SelectedIndex + 1 == 1 do (--//Betweens Only
			newVal = (spTotalWidth.value-(spSpaceWidth.value*(spNumObjects.value-1.0)))/spNumObjects.value
			spObjectWidth.value = newVal as float
		)
		if dlSpaceType.SelectedIndex + 1 == 2 do (--//Ends/Betweens
			newVal = (spTotalWidth.value-(spSpaceWidth.value*(spNumObjects.value+1.0)))/spNumObjects.value
			spObjectWidth.value = newVal as float
		)
	)
	if cbSpaceWidth.checked == true do (--//SpaceWidth based
		if dlSpaceType.SelectedIndex + 1 == 1 do (--//Betweens Only
			newVal = (spTotalWidth.value-(spNumObjects.value*spObjectWidth.value))/(spNumObjects.value-1.0)
			spSpaceWidth.value = newVal as float
		)
		if dlSpaceType.SelectedIndex + 1 == 2 do (--//Ends/Betweens
			newVal = (spTotalWidth.value-(spNumObjects.value*spObjectWidth.value))/(spNumObjects.value+1.0)
			spSpaceWidth.value = newVal as float
		)
	)
)

fn fnSpinnerChanged s e =
(
	fnUpdateValues()
)

fn PreviewFactory X Y W H fCol bCol txt =
(
	local theLab = dotNetObject "Label"
	theLab.Font = dotNetObject "System.Drawing.Font" "Arial" 12 H2Font
	theLab.Bounds = dotNetObject "System.Drawing.Rectangle" X Y W H
	theLab.BackColor = (dotNetClass "System.Drawing.Color").fromARGB bCol[1] bCol[2] bCol[3]
	theLab.ForeColor = (dotNetClass "System.Drawing.Color").fromARGB fCol[1] fCol[2] fCol[3]
	theLab.TextAlign = theLab.TextAlign.MiddleCenter
	theLab.Text = txt
	theLab
)

fn labelFactory X Y W H fCol bCol txt =
(
	local theLab = dotNetObject "Label"
	theLab.Font = theFont
	theLab.Bounds = dotNetObject "System.Drawing.Rectangle" X Y W H
	theLab.BackColor = (dotNetClass "System.Drawing.Color").fromARGB bCol[1] bCol[2] bCol[3]
	theLab.ForeColor = (dotNetClass "System.Drawing.Color").fromARGB fCol[1] fCol[2] fCol[3]
	theLab.TextAlign = theLab.TextAlign.MiddleRight
	theLab.Text = txt
	theLab
)

fn checkButtonFactory X Y W H fCol bCol txt enabled =
(
	local theBut = dotNetObject "CheckBox"
	theBut.Font = theFont
	theBut.flatAppearance.BorderSize = 0
	theBut.flatStyle=theBut.flatStyle.flat
	theBut.appearance = theBut.appearance.button
	theBut.Bounds = dotNetObject "System.Drawing.Rectangle" X Y W H
	theBut.BackColor = (dotNetClass "System.Drawing.Color").fromARGB bCol[1] bCol[2] bCol[3]
	theBut.ForeColor = (dotNetClass "System.Drawing.Color").fromARGB fCol[1] fCol[2] fCol[3]
	theBut.TextAlign = theBut.TextAlign.MiddleRight
	theBut.Text = txt
	theBut.Checked = enabled
	--theBut.Enabled = NOT enabled
	theBut.tag = enabled
	theBut
)

fn spinnerlFactory X Y W H minV maxV dec val enabled =
(
	local theSpn = dotNetObject "NumericUpDown"
	theSpn.Bounds = dotNetObject "System.Drawing.Rectangle" X Y W H
	theSpn.DecimalPlaces = dec
	theSpn.Increment = .1
	theSpn.minimum = minV
	theSpn.maximum = maxV
	theSpn.value = val
	theSpn.ReadOnly = false
	theSpn.Enabled = enabled
	dotNet.addEventHandler theSpn "ValueChanged" fnSpinnerChanged
	theSpn
)

fn cmbBoxFactory X Y W H items =
(
	local theCmb = dotNetObject "ComboBox"
	theCmb.Bounds = dotNetObject "System.Drawing.Rectangle" X Y W H
	theCmb.DropDownStyle = theCmb.DropDownStyle.DropDownList
	theCmb.items.addRange items
	theCmb.SelectedIndex = 0
	theCmb
)

--//UI Items
lbSpacerPreview= PreviewFactory 24 24 195 36 [255,255,255] [61,148,178] previewArr[1]
lbTotalWidth = labelFactory 8 80 100 24 [0,0,0] [200,200,200] "Total Width:"
spTotalWidth = spinnerlFactory 118 83 100 21 (-999999999) (999999999) 2 960.0 true
lbNumObjects= labelFactory 8 114 100 24 [0,0,0] [200,200,200] "# Objects:"
spNumObjects = spinnerlFactory 118 117 100 21 (-999999999) (999999999) 0 4 true
cbObjectWidth = checkButtonFactory 12 148 100 24 [0,0,0] [200,200,200] "Object Width:" true
spObjectWidth = spinnerlFactory 118 151 100 21 (-999999999) (999999999) 2 60.0 false
cbSpaceWidth = checkButtonFactory 12 182 100 24 [0,0,0] [200,200,200] "Space Width:" false
spSpaceWidth  = spinnerlFactory 118 185 100 21 (-999999999) (999999999) 2 16.0 true
lbSpaceType = labelFactory 8 216 100 24 [0,0,0] [200,200,200] "Space Type:"
dlSpaceType = cmbBoxFactory 118 218 100 21 #("Betweens Only","Ends/Betweens","Ends Only")


--//Actions	
fn fnSelectedTyped s e =
(
	type = dlSpaceType.SelectedIndex
	lbSpacerPreview.text = previewArr[type+1]
	fnUpdateValues()
)

fn fnSpaceBased s e =
(
	if s.checked == true then (
		cbObjectWidth.checked = false
		spObjectWidth.enabled = true
		spSpaceWidth.enabled = false
	)else(
		cbObjectWidth.checked = true
		spObjectWidth.enabled = false
		spSpaceWidth.enabled = true
	)
	fnUpdateValues()
)

fn fnObjectBased s e =
(
	if s.checked == true then (
		cbSpaceWidth.checked = false
		spSpaceWidth.enabled = true
		spObjectWidth.enabled = false
	)else(
		cbSpaceWidth.checked = true
		spSpaceWidth.enabled = false
		spObjectWidth.enabled = true
	)
	fnUpdateValues()
)

--//Event Handlers
dotnet.addEventHandler cbObjectWidth "CheckStateChanged" fnObjectBased
dotnet.addEventHandler cbSpaceWidth "CheckStateChanged" fnSpaceBased
dotnet.addEventHandler dlSpaceType "SelectedIndexChanged" fnSelectedTyped	



TheForm = dotNetObject "Form"
TheForm.controls.addRange #(lbSpacerPreview,lbTotalWidth,spTotalWidth,lbNumObjects,spNumObjects,cbObjectWidth,spObjectWidth,cbSpaceWidth,spSpaceWidth,lbSpaceType,dlSpaceType)

TheForm.bounds = dotNetObject "system.drawing.rectangle" 500 500 260 300
TheForm.backColor = TheForm.backColor.fromARGB 200 200 200
TheForm.text = "Spacer v1.0"

--Set the parent of the form to be Max. 
--Get the max handle pointer.
maxHandlePointer=(Windows.GetMAXHWND())

--Convert the HWND handle of Max to a dotNet system pointer
sysPointer = DotNetObject "System.IntPtr" maxHandlePointer

--Create a dotNet wrapper containing the maxHWND
maxHwnd = DotNetObject "MaxCustomControls.Win32HandleWrapper" sysPointer

--Show the Max form using the wrapper. 
TheForm.Show (maxHwnd)


 lo1

three small things:

  1. The increment of the number of objects spinner is 0.1, while the number of displayed decimal digits is 0, so you have to click it 10 times before it increments one number, making the user believe it is broken.

  2. Just some syntactic sugar, I would write this:

if s.checked == true then (
		cbObjectWidth.checked = false
		spObjectWidth.enabled = true
		spSpaceWidth.enabled = false
	)else(
		cbObjectWidth.checked = true
		spObjectWidth.enabled = false
		spSpaceWidth.enabled = true
	)

as this:

spObjectWidth.enabled = s.checked
cbObjectWidth.enabled = spSpaceWidth.enabled = not s.checked

but I guess it’s a matter of preference.

  1. You might want to avoid having your form appear in the taskbar:
TheForm.showInTaskbar = off

Here is the final code all put together. My first completed dotNet tool. Although it might not seem like a lot to many, its super exciting and a big learning experience for me. Next I’m moving onto the doing subRollouts in dotNet. That will be the next post here.

Special thanks to Rotem for the help.

Check it out.


--//Font 1
theFont = dotnetobject "System.Drawing.Font" "Arial" 9
--//Font h2
H2FontStyle = dotNetClass "System.Drawing.FontStyle"
H2Font = dotnet.combineenums H2FontStyle.bold

--//Preview array
previewArr = #("O - O - O - O - O - O","- O - O - O - O - O - O -","- O   O   O   O   O   O -")
	
enableAccelerators=false --This is needed so that we can type in the values as well as use the spinner. 

fn fnUpdateValues = (
	if cbObjectWidth.checked == true do (--//ObjectWidth based
		if dlSpaceType.SelectedIndex + 1 == 1 do (--//Betweens Only
			newVal = (spTotalWidth.value-(spSpaceWidth.value*(spNumObjects.value-1.0)))/spNumObjects.value
			spObjectWidth.value = newVal
		)
		if dlSpaceType.SelectedIndex + 1 == 2 do (--//Ends/Betweens
			newVal = (spTotalWidth.value-(spSpaceWidth.value*(spNumObjects.value+1.0)))/spNumObjects.value
			spObjectWidth.value = newVal
		)
		if dlSpaceType.SelectedIndex + 1 == 3 do (--//Ends Only
			newVal = (spTotalWidth.value-(spSpaceWidth.value*2))/spNumObjects.value
			spObjectWidth.value = newVal
		)
	)
	if cbSpaceWidth.checked == true do (--//SpaceWidth based
		if dlSpaceType.SelectedIndex + 1 == 1 do (--//Betweens Only
			newVal = (spTotalWidth.value-(spNumObjects.value*spObjectWidth.value))/(spNumObjects.value-1.0)
			spSpaceWidth.value = newVal
		)
		if dlSpaceType.SelectedIndex + 1 == 2 do (--//Ends/Betweens
			newVal = (spTotalWidth.value-(spNumObjects.value*spObjectWidth.value))/(spNumObjects.value+1.0)
			spSpaceWidth.value = newVal
		)
		if dlSpaceType.SelectedIndex + 1 == 3 do (--//Ends Only
			newVal = (spTotalWidth.value-(spObjectWidth.value*spNumObjects.value))/2
			spSpaceWidth.value = newVal
		)
	)
)

fn fnSpinnerChanged s e =
(
	fnUpdateValues()
)

fn PreviewFactory X Y W H fCol bCol txt =
(
	local theLab = dotNetObject "Label"
	theLab.Font = dotNetObject "System.Drawing.Font" "Arial" 12 H2Font
	theLab.Bounds = dotNetObject "System.Drawing.Rectangle" X Y W H
	theLab.BackColor = (dotNetClass "System.Drawing.Color").fromARGB bCol[1] bCol[2] bCol[3]
	theLab.ForeColor = (dotNetClass "System.Drawing.Color").fromARGB fCol[1] fCol[2] fCol[3]
	theLab.TextAlign = theLab.TextAlign.MiddleCenter
	theLab.Text = txt
	theLab
)

fn labelFactory X Y W H fCol bCol txt =
(
	local theLab = dotNetObject "Label"
	theLab.Font = theFont
	theLab.Bounds = dotNetObject "System.Drawing.Rectangle" X Y W H
	theLab.BackColor = (dotNetClass "System.Drawing.Color").fromARGB bCol[1] bCol[2] bCol[3]
	theLab.ForeColor = (dotNetClass "System.Drawing.Color").fromARGB fCol[1] fCol[2] fCol[3]
	theLab.TextAlign = theLab.TextAlign.MiddleRight
	theLab.Text = txt
	theLab
)

fn checkButtonFactory X Y W H fCol bCol txt enabled =
(
	local theBut = dotNetObject "CheckBox"
	theBut.Font = theFont
	theBut.flatAppearance.BorderSize = 0
	theBut.flatStyle=theBut.flatStyle.flat
	theBut.appearance = theBut.appearance.button
	theBut.Bounds = dotNetObject "System.Drawing.Rectangle" X Y W H
	theBut.BackColor = (dotNetClass "System.Drawing.Color").fromARGB bCol[1] bCol[2] bCol[3]
	theBut.ForeColor = (dotNetClass "System.Drawing.Color").fromARGB fCol[1] fCol[2] fCol[3]
	theBut.TextAlign = theBut.TextAlign.MiddleRight
	theBut.Text = txt
	theBut.Checked = enabled
	theBut.tag = enabled
	theBut
)

fn spinnerlFactory X Y W H minV maxV dec val enabled =
(
	local theSpn = dotNetObject "NumericUpDown"
	theSpn.Bounds = dotNetObject "System.Drawing.Rectangle" X Y W H
	theSpn.DecimalPlaces = dec
	theSpn.Increment = 1.0
	theSpn.minimum = minV
	theSpn.maximum = maxV
	theSpn.value = val
	theSpn.ReadOnly = false
	theSpn.Enabled = enabled
	dotNet.addEventHandler theSpn "ValueChanged" fnSpinnerChanged
	theSpn
)

fn cmbBoxFactory X Y W H items =
(
	local theCmb = dotNetObject "ComboBox"
	theCmb.Bounds = dotNetObject "System.Drawing.Rectangle" X Y W H
	theCmb.DropDownStyle = theCmb.DropDownStyle.DropDownList
	theCmb.items.addRange items
	theCmb.SelectedIndex = 0
	theCmb
)

--//UI Items
lbSpacerPreview= PreviewFactory 24 24 195 36 [255,255,255] [61,148,178] previewArr[1]
lbTotalWidth = labelFactory 8 80 100 24 [0,0,0] [200,200,200] "Total Width:"
spTotalWidth = spinnerlFactory 118 83 100 21 (-999999999) (999999999) 2 960.0 true
lbNumObjects= labelFactory 8 114 100 24 [0,0,0] [200,200,200] "# Objects:"
spNumObjects = spinnerlFactory 118 117 100 21 (-999999999) (999999999) 0 4 true
cbObjectWidth = checkButtonFactory 12 148 100 24 [0,0,0] [200,200,200] "Object Width:" true
spObjectWidth = spinnerlFactory 118 151 100 21 (-999999999) (999999999) 2 60.0 false
cbSpaceWidth = checkButtonFactory 12 182 100 24 [0,0,0] [200,200,200] "Space Width:" false
spSpaceWidth  = spinnerlFactory 118 185 100 21 (-999999999) (999999999) 2 16.0 true
lbSpaceType = labelFactory 8 216 100 24 [0,0,0] [200,200,200] "Space Type:"
dlSpaceType = cmbBoxFactory 118 218 100 21 #("Betweens Only","Ends/Betweens","Ends Only")


--//Actions	
fn fnSelectedTyped s e =
(
	type = dlSpaceType.SelectedIndex
	lbSpacerPreview.text = previewArr[type+1]
	fnUpdateValues()
)

fn fnSpaceBased s e =
(
	spObjectWidth.enabled = s.checked
	cbObjectWidth.checked = spSpaceWidth.enabled = not s.checked
	fnUpdateValues()
)

fn fnObjectBased s e =
(
	spSpaceWidth.enabled = s.checked
	cbSpaceWidth.checked = spObjectWidth.enabled = not s.checked
 	fnUpdateValues()
)

--//Event Handlers
dotnet.addEventHandler cbObjectWidth "CheckStateChanged" fnObjectBased
dotnet.addEventHandler cbSpaceWidth "CheckStateChanged" fnSpaceBased
dotnet.addEventHandler dlSpaceType "SelectedIndexChanged" fnSelectedTyped	



TheForm = dotNetObject "Form"
TheForm.controls.addRange #(lbSpacerPreview,lbTotalWidth,spTotalWidth,lbNumObjects,spNumObjects,cbObjectWidth,spObjectWidth,cbSpaceWidth,spSpaceWidth,lbSpaceType,dlSpaceType)

TheForm.bounds = dotNetObject "system.drawing.rectangle" 500 500 260 300
TheForm.backColor = TheForm.backColor.fromARGB 200 200 200
TheForm.text = "Spacer v1.0"

--Set the parent of the form to be Max. 
--Get the max handle pointer.
maxHandlePointer=(Windows.GetMAXHWND())

--Convert the HWND handle of Max to a dotNet system pointer
sysPointer = DotNetObject "System.IntPtr" maxHandlePointer

--Create a dotNet wrapper containing the maxHWND
maxHwnd = DotNetObject "MaxCustomControls.Win32HandleWrapper" sysPointer

--Show the Max form using the wrapper.
TheForm.showInTaskbar = off	
TheForm.Show (maxHwnd)


Page 5 / 18