create dotnetcontrol buttons inside function

I want to create buttons depending on certain things!
So here is what I need:

fn myfunction=
(
...
 
for i=1 to IDcount do
(
     dotnetcontrol ID_btn[i] "System.Windows.Forms.Button" width:20 height:60 pos:[27,i*153]
     ID_btn[i].backcolor  = (dotnetcolor 70 70 70)
     ID_btn[i].flatstyle = dotnetobject "System.Windows.Forms.FlatStyle" Flat
     ID_btn[i].text="1"
     ID_btn[i].foreColor = (dotnetcolor 200 200 200)
)
)

How to make it work?

Comments

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
barigazy's picture

Then use simle "Panel"

Then use simle "Panel" control for the buttons (simpliest container)

dotnetcontrol pn "Panel" pos:[5,5] width:390 height:378

barigazy

artrender.info's picture

I just didn't understand

where did you define the width and the height for the panel1 and panel2?

I will add controls just for the visible textures in datagrid, that's why it will be not slow!!!

barigazy's picture

I not define them in this

I not define them in this example. But you can anywhere inside function, and if you need to be changed in some point then you need to add also arguments in fn definition like i did for width and height (w: and h:)

barigazy

artrender.info's picture

now it's much interesting!

I'm implementing now to my code!!!!!
Thx barigazy, I think this will do what I want!

barigazy's picture

:)

Believe me your trouble just started. :) Don't experiment too much with additional controls because your tool will become slower and slower.

barigazy

artrender.info's picture

Oh, yeeeeeeeeeeeeeees!!!

now I have what to work with!
Is it possible to clear pn.controlls? so that they would be empty and to recreate in case my list updates!

barigazy's picture

.net clear method

-- to remove all buttons
sp1.panel2.controls.Clear()
-- and for panel probably
pn.controls.Clear()

barigazy

artrender.info's picture

what is dock

in which cases it should be used?
how to add split containers iteratively?
how to fill every container with a button?

srry for all these questions, but if understand this then I know how to go on!

Thank you Barigazy, I would not be able to make it by myself!

barigazy's picture

Dock propert allow you to

Dock propert allow you to entirely fills the container with specified controls. Similar to align in max script. This option not work well in may last example I don't know why.

Explain better "Iteratively"?

Using for-loop collect buttons

 
try(destroyDialog testR)catch()
rollout testR "Test" width:400 height:400
(
	dotnetcontrol pn "MaxCustomControls.MaxUserControl" pos:[5,5] width:390 height:378
	fn defColor r g b = ((dotNetClass "System.Drawing.Color").FromArgb r g b)
	local COL1 = (defColor 80 80 80), COL2 = (defColor 150 150 150), COL3 = (defColor 65 125 88), COL4 = (defColor 125 150 80)
	local sp1 = dotnetobject "SplitContainer"
	local sp2 = dotnetobject "SplitContainer"
	fn defineSplitCont sp mainPnl clr1 clr2 w: h: dock: spliter:2 orient:#vert ctrlsIn1st:#() ctrlsIn2st:#()=
	(
		sp.panel1.backColor = clr1
		sp.panel2.backColor = clr2
		sp.splitterWidth = spliter
		case orient of
		(
			(#vert): sp.Orientation = sp.Orientation.Vertical
			(#horiz): sp.Orientation = sp.Orientation.Horizontal
		)
		if dock then (sp.panel1.DockPadding.All = sp.panel2.DockPadding.All = 0 ; sp.dock = sp.dock.fill) else
		(
			if w != unsupplied and h != unsupplied do (sp.width = w ; sp.height = h)
			sp.Location = dotNetObject "System.Drawing.Point" (mainPnl.pos.x) (mainPnl.pos.y)
		)
		if ctrlsIn1st.count != 0 do sp.Panel1.controls.AddRange ctrlsIn1st
		if ctrlsIn2st.count != 0 do sp.Panel2.controls.AddRange ctrlsIn2st	
		sp
	)
	fn defBtn pnl txt: w:50 h:50 cnt:0 =
	(
		btn = dotnetobject "Button"
		btn.text = txt
		btn.width = 50 ; btn.height = 20
		btn.Location = dotNetObject "System.Drawing.Point" 5 (-15 + (cnt*btn.height))
		btn
	)
	on testR open do 
	(
		pn.backcolor = pn.backcolor.black
		pn.BorderStyle = pn.BorderStyle.FixedSingle
		pn.width = 390 ; pn.height = 390 
		defineSplitCont sp2 pn COL3 COL4 dock:off spliter:2 orient:#horiz
		defineSplitCont sp1 pn COL1 COL2 w:378 h:378 dock:on spliter:2 ctrlsIn1st:#(sp2) ctrlsIn2st:(for i = 1 to 10 collect (defBtn sp1.panel2 txt:("Btn_"+i as string) w:50 h:10 cnt:i))
		pn.controls.add sp1
	)
)
createDialog testR

barigazy

artrender.info's picture

THX Barigazy

I will try it when I come back! Thank you thank you thank you!!!

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.