dnControl=(dotNetObject "control")
--DotNet functions
fn dnColor c:[0,0,0] a:255 = ((dotNetClass "system.drawing.color").FromArgb a c.x c.y c.z)
fn dnSize s:[10,10]=(dotNetObject "system.drawing.size" s.x s.y)
fn dnPoint p:[0,0]=(dotNetObject "system.drawing.point" p.x p.y)
fn dnPointF p:[0,0]=(dotNetObject "system.drawing.pointF" p.x p.y)
fn dnRec p:[0,0] s:[10,10]=(dotNetObject "system.drawing.rectangle" p.x p.y s.x s.y)
--Bitmaps
bitMapPath ="G:\\MaxScripts\\DotNet JoyStick\\assets\\"
square100Bmp=(dotNetClass "system.drawing.bitMap").fromFile (bitMapPath+"square100.bmp")
squareTargetPng=(dotNetClass "system.drawing.bitMap").fromFile (bitMapPath+"squareTarget.png")
fn clampVal sender val =
(
minMaxX=[0,sender.width]
minMaxY=[0,sender.height]
valX=val.x
valY=val.y
--Clamp the ranges
if valX<minMaxX[1] do valX=minMaxX[1]
if valX>minMaxX[2] do valX=minMaxX[2]
if valY<minMaxY[1] do valY=minMaxY[1]
if valY>minMaxY[2] do valY=minMaxY[2]
[valX,valY]
)
fn controlLabelPaint sender arg=
(
g=arg.graphics
v = sender.PointToClient sender.MousePosition
v=clampVal sender v
g.DrawImage squareTargetPng (dnPoint p:[v.x-12,v.y-12])
)
form=dotNetObject "maxCustomControls.maxForm"
--Create the label
dnLabel=dotNetObject "label"
dnLabel.bounds=dotNetObject "system.drawing.rectangle" 10 10 100 100
dnLabel.backGroundImage=square100Bmp
--Add the label to the form.
form.controls.add dnLabel
-------------------------------------------------------
--Variable used in mouseMove handler.
global mouseIsDown=false
--Add event handlers for the form.
fn formMouseDown sender arg=
(
--Check to see which mouse button is being pressed.
mouseIsDown=true
sender.refresh()
)
fn formMouseUp sender arg=
(
mouseIsDown=false
)
fn formMouseMove sender arg=
(
if mouseIsDown do sender.refresh()
)
--Add the event handlers.
dotNet.addEventHandler dnLabel "mouseDown" formMouseDown
dotNet.addEventHandler dnLabel "mouseUp" formMouseUp
dotNet.addEventHandler dnLabel "mouseMove" formMouseMove
dotNet.addEventHandler dnLabel "paint" controlLabelPaint
--Set the life time of the control to #dotNet so that it is not garbage collected with the rest of Max script.
dotNet.setLifeTimeControl dnLabel #dotNet
--Show the form
form.show()