Notifications
Clear all

[Closed] DotNet Syntax Problem

Hi guys,
I’m a french beginner in MaxScript.
I succeed scripting in maxscript (with maxscript help and many forum).
But with the dotnet syntax, I’m lost…
I don’t understand some things.

for exemples these codes found in CGTALK :
I tried many solutions for the “DotNetForm.Show()” but they doesn’t work.
Why ” on pb1 paint e do” don’t work in the second script ?
How can I draw (rectangle, ellipse, image) with the second method ?

Thank you

ps : this code source come from this thread mouse imput window and this thread
ps 2 : Sorry for my English, I know that it’s not perfect. Correct me, if it’s too bad and unreadable I accept C&C

Rollout méthod :


  rollout dnpb "GDI+ paint" width:280 height:350
    (	
  	  -- Variables
  	  local bmpDisplayed = dotNetObject "System.Drawing.Bitmap" "C:\Program Files\Autodesk\3ds Max 9\maps\peul\Compteur_test_02.png"
  	local bmpRectangle = dotNetObject "System.Drawing.Rectangle" 0 0 320 320
    
  	 local acolor = dotnetclass "system.drawing.color"
  	 local abrush = dotnetobject "System.Drawing.SolidBrush" acolor.yellow	
  	 local anotherbrush = dotnetobject "System.Drawing.TextureBrush" bmpDisplayed
  	 local pos1x = 65
  	 local pos1y = 65	  
  	
  	 dotnetcontrol pb1 "System.Windows.Forms.panel" pos:[5,5] width:130 height:130 
  	  
  	 on pb1 paint e do
  	 (
  	 g = e.graphics	
  	 GDIsmoothing = dotnetclass "System.Drawing.Drawing2D.SmoothingMode"
  	 g.SmoothingMode = GDIsmoothing.AntiAlias		
  	 g.FillRectangle abrush 3 3 124 124
  	 g.FillEllipse anotherbrush (pos1x-15) (pos1y-15) 30 30	
  	g.DrawImage bmpDisplayed bmpRectangle
  	 g.dispose()
  	 )
  	 
  	 on pb1 mouseMove sender arg do
  	 (
  		 if arg.button==arg.button.left then
  		 (			
  			 pos2x = arg.x
  			 pos2y = arg.y
  			 pb1.invalidate()
  		 )
  	 )
  
  	  on dnpb close do 
  	  (
  	  abrush.dispose()
  	  anotherbrush.dispose()
  	  )
  	  
    )
    createdialog dnpb
  

DotNet méthod (no rollout) :


  (
  	-- Variables
  	  local bmpDisplayed = dotNetObject "System.Drawing.Bitmap" "C:\Program Files\Autodesk\3ds Max 9\maps\peul\Compteur_test_02.png"
  	local bmpRectangle = dotNetObject "System.Drawing.Rectangle" 0 0 320 320
    
  	 local acolor = dotnetclass "system.drawing.color"
  	 local abrush = dotnetobject "System.Drawing.SolidBrush" acolor.yellow	
  	 local anotherbrush = dotnetobject "System.Drawing.TextureBrush" bmpDisplayed 
  	 local pos1x = 65
  	 local pos1y = 65
  
  	-- Create a form
  	local DotNetForm = DotNetObject "System.Windows.Forms.Form"
  	DotNetForm.Size = (DotNetObject "Drawing.Size" 200 380)
  	DotNetForm.TopMost = true
  
  	local pb1 = DotNetObject "System.Windows.Forms.panel"
  	pb1.Size = (DotNetObject "Drawing.Size" 130 130)
  	pb1.Location = (DotNetObject "Drawing.Point" 5 5)
  	pb1.BackColor = (dotNetClass "System.Drawing.Color").FromARGB 125 125 125
  	
  ------- >>>>>>>>>> This code don't Work....
  			 on pb1 paint e do
  			 (
  			 g = e.graphics	
  			 GDIsmoothing = dotnetclass "System.Drawing.Drawing2D.SmoothingMode"
  			 g.SmoothingMode = GDIsmoothing.AntiAlias		
  			 g.FillRectangle abrush 3 3 124 124
  			 g.FillEllipse anotherbrush (pos1x-15) (pos1y-15) 30 30	
  			g.DrawImage bmpDisplayed bmpRectangle
  			 g.dispose()
  			 )
  		
  			 on pb1 mouseMove sender arg do
  			 (
  					 
  				 if arg.button==arg.button.left then
  				 (			
  					 pos2x = arg.x
  					 pos2y = arg.y
  					 pb1.invalidate()
  				 )
  			 )
  		
  			  on dnpb close do 
  			  (
  			  abrush.dispose()
  			  anotherbrush.dispose()
  			  )
  			 
  ------- >>>>>>>>>> End This code don't Work....	 
  	 
  	DotNetForm.Controls.AddRange #(pb1)
  
  	-- Show the form
  	DotNetForm.Show()
  )
  
  
4 Replies

you have to manually add eventhandler since it’s a form …

(
– Variables
–local bmpDisplayed = dotNetObject “System.Drawing.Bitmap” “C:\Program Files\Autodesk\3ds Max 9\maps\peul\Compteur_test_02.png”
local bmpRectangle = dotNetObject “System.Drawing.Rectangle” 0 0 320 320

    local acolor = dotnetclass "system.drawing.color"
    local abrush = dotnetobject "System.Drawing.SolidBrush" acolor.yellow    
    --local anotherbrush = dotnetobject "System.Drawing.TextureBrush" bmpDisplayed 
    local pos1x = 65
    local pos1y = 65
    -- Create a form
    local DotNetForm = DotNetObject "System.Windows.Forms.Form"
    DotNetForm.Size = (DotNetObject "Drawing.Size" 200 380)
    DotNetForm.TopMost = true
    local pb1 = DotNetObject "System.Windows.Forms.panel"
    pb1.Size = (DotNetObject "Drawing.Size" 130 130)
    pb1.Location = (DotNetObject "Drawing.Point" 5 5)
    pb1.BackColor = (dotNetClass "System.Drawing.Color").FromARGB 125 125 125

——- >>>>>>>>>> This code don’t Work…
fn pb1_paint s e =
(
e.graphics.SmoothingMode = e.graphics.SmoothingMode.AntiAlias
e.graphics.FillRectangle abrush 3 3 124 124
–e.graphics.FillEllipse anotherbrush (pos1x-15) (pos1y-15) 30 30
–g.DrawImage bmpDisplayed bmpRectangle
)

    fn pb1_mouseMove s e =
    (
        if e.button==e.button.left then
        (            
            pos2x = e.x
            pos2y = e.y
            pb1.invalidate()
        )
    )
      
    fn DotNetForm_closed s e = 
        (
            --abrush.dispose()
            --anotherbrush.dispose()
        )

——- >>>>>>>>>> End This code don’t Work…

  DotNetForm.Controls.AddRange #(pb1)

dotnet.addeventhandler pb1 "paint" pb1_paint   
dotnet.addeventhandler pb1 "mouseMove" pb1_mouseMove 
dotnet.addeventhandler DotNetForm "closed" DotNetForm_closed       
      
  -- Show the form
  DotNetForm.Show()

)

martin

Ok, great.
I had try something like this, but without the good syntax.
Your code works very well, thank you for your help.

I work on my script and I post it !!

Hi,
I try to create a slider “XSI style” but when I add a txtBox in one Label it doesn’t work.
If my touches are shortcuts of 3DSmax then nothing is typed in the textBox !!
I m sure, it’s a problem of syntax, but i don’t find it…

rollout SliderRollout "DotNet Slider Test" width:184 height:184
 	   (
 	
 		dotNetControl Slider_01 "System.Windows.Forms.Label" pos:[8,8] width:35 height:20
 		dotNetControl txtBoxB "System.Windows.Forms.textBox" pos:[8,35] width:30 height:20
 		
 		   on SliderRollout open do
 		   (		
 		Slider_01.ForeColor	= (dotNetClass "System.Drawing.Color").FromARGB 0 100 100 100
 		   Slider_01.BackColor	= (dotNetClass "System.Drawing.Color").FromARGB 0 255 255 255
 		   Slider_01.BorderStyle	= (dotNetClass "System.Windows.Forms.BorderStyle").none--FixedSingle
 		   Slider_01.Padding		= dotNetObject "System.Windows.Forms.Padding" 0 0 0 0
 		   Slider_01.TextAlign	= (dotNetClass "System.Drawing.ContentAlignment").MiddleCenter --TopCenter
 			
 		txtBoxA = dotNetObject "System.Windows.Forms.TextBox" 
 		txtBoxA.BorderStyle	= (dotNetClass "System.Windows.Forms.BorderStyle").none --FixedSingle --none --
 		txtBoxA.Size		= dotNetObject "System.Drawing.Size" 30 20
 		txtBoxA.TextAlign	= (dotNetClass "System.Windows.Forms.HorizontalAlignment" ).center
 		--txtBoxA.Enabled		= true
 		txtBoxA.Top			= 3
 		txtBoxA.Left		= 2
 		txtBoxA.BringToFront()
 		showmethods txtBoxA
 		
 		Slider_01.Controls.Add txtBoxA
 		   )
 		
 	
 )
 createDialog SliderRollout

Don’t really know what you are trying to do but you can disable max accelerators at anytime by using : enableAccelerators = false

best regard,
Martin


rollout SliderRollout "DotNet Slider Test" width:184 height:184
   (
	dotNetControl Slider_01 "System.Windows.Forms.Label" pos:[8,8] width:35 height:20
	dotNetControl txtBoxB "System.Windows.Forms.textBox" pos:[8,35] width:30 height:20

	on SliderRollout open do
	   (		
		Slider_01.ForeColor	= (dotNetClass "System.Drawing.Color").FromARGB 0 100 100 100
		Slider_01.BackColor	= (dotNetClass "System.Drawing.Color").FromARGB 0 255 255 255
		Slider_01.BorderStyle	= (dotNetClass "System.Windows.Forms.BorderStyle").none--FixedSingle
		Slider_01.Padding		= dotNetObject "System.Windows.Forms.Padding" 0 0 0 0
		Slider_01.TextAlign	= (dotNetClass "System.Drawing.ContentAlignment").MiddleCenter --TopCenter

		txtBoxA = dotNetObject "System.Windows.Forms.TextBox" 
		txtBoxA.BorderStyle	= (dotNetClass "System.Windows.Forms.BorderStyle").none --FixedSingle --none --
		txtBoxA.Size		= dotNetObject "System.Drawing.Size" 30 20
		txtBoxA.TextAlign	= (dotNetClass "System.Windows.Forms.HorizontalAlignment" ).center
		txtBoxA.Font = dotnetobject "System.Drawing.Font" "Arial" 14.0
		--txtBoxA.Enabled		= true
-- 		txtBoxA.Top			= 3
-- 		txtBoxA.Left		= 2
-- 		txtBoxA.BringToFront()
		txtBoxA.dock = txtBoxA.dock.fill
		--showmethods txtBoxA
		dotnet.addeventhandler txtBoxA "click" (fn doit s e = enableAccelerators = false) 
	   txtBoxA.tag = dotnetMXSValue txtBoxA
		Slider_01.Controls.Add txtBoxA
	   )
 --
 )
createDialog SliderRollout