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

In this case I will use

In this case I will use dotnet Panel control and put all inside. You will lose auto alignement but who care. Just define locations of labels or buttons where you need to be inside panel control

barigazy

artrender.info's picture

I can use even verticalString like you said

but I still could not find a solution to align buttons like in the second picture from above

barigazy's picture

Are you try with FLP

Are you try with FLP horizontal direction direction. I this not works then you need change concept

barigazy

artrender.info's picture

Let's say

I can use image for label with vertical text - multitexture, but I can't alight buttons

barigazy's picture

Why do you want to use map to

Why do you want to use map to represent simple text.Are you try to add text to button as I show you yesterday?

barigazy

artrender.info's picture

here is what I achieve

	fn defCB  dnCtrl btntype btnwidth btnheight txt: =
	(
		dnCtrl.backcolor = (dotnetcolor 84 84 84)
		dnCtrl.forecolor = (dotnetcolor 200 200 200)
		dnCtrl.TextAlign = dnCtrl.TextAlign.MiddleCenter
		dnCtrl.BorderStyle = dnCtrl.BorderStyle.None
		dnCtrl.margin = (dotNetObject "system.windows.forms.padding" 1)
		dnCtrl.width = btnwidth
		dnCtrl.height = btnheight
		dnCtrl.text = txt
		dnCtrl.Cursor = (dotNetClass "Cursors").Hand
         )
 
 
 
mt = dotnetobject "Label"
defCB mt 20 (IDTextureCount*30-2) txt: ((classOf s.material) as string) 
BitmapLister.FLP.Controls.Add(mt)
 
for m in mIDList do
(
     lbl = dotnetobject "Label"
     defCB lbl 20 (newbitmaps.count*30-2) txt: (m as string)
     BitmapLister.FLP.Controls.Add(lbl)
     BitmapLister.FLP.FlowDirection.TopDown
)

AttachmentSize
btn-alignment.jpg 148.02 KB
artrender.info's picture

But these buttons are the last thing to do with GUI

May be you have some ideas how to do this:
buttons should update accordingly to textures from datagrid which change.

Here is what I have now

	fn dotnetcolor r g b = 
	(
		(dotNetClass "System.Drawing.Color").fromARGB r g b
	)
 
	fn defCB  dnCtrl btnheight txt: check: =
	(
		dnCtrl.Appearance = dnCtrl.Appearance.Button
		dnCtrl.flatappearance.bordersize = 0
		dnCtrl.margin = (dotNetObject "system.windows.forms.padding" 1)
		dnCtrl.width = 20 
		dnCtrl.height = btnheight
		dnCtrl.backcolor = (dotnetcolor 84 84 84) 
		dnCtrl.forecolor = (dotnetcolor 200 200 200)
		dnCtrl.Cursor = (dotNetClass "Cursors").Hand
		dnCtrl.FlatStyle = dnCtrl.FlatStyle.Flat
		dnCtrl.TextAlign = dnCtrl.TextAlign.MiddleCenter
		dnCtrl.text = txt ; dnCtrl.checked = check
	)
--...
dotNetControl MtlFLP "FlowLayoutPanel" width:22 height:(table.height-24) pos:[5,153]--column for materials buttons
dotNetControl FLP "FlowLayoutPanel" width:30 height:(table.height-24) pos:[18,153]--column for mat IDs
--...
 if classof s.material == multimaterial then
(...
	cb = dotNetobject "checkbox"
	defCB cb (newbitmaps.count*30-2) txt: (m as string) check:false -- 30 - the height of a datagrid row, newbitmaps.count -- count of textures inside ID
	FLP.Controls.Add(cb)
)
else
						mt = dotNetobject "checkbox"
						defCB mt (multimatTCount*30-2) txt: ((classOf s.material) as string) check:false
						BitmapLister.MtlFLP.Controls.Add(mt)

and here is what I want:

AttachmentSize
direction.jpg 122.32 KB
wanted.jpg 129.03 KB
barigazy's picture

Are you try to use button

Are you try to use button name like this :

"M\nU\nL\nT\nI\nM\nA\nT\nE\nR\nR\nI\nA\nL"
--or
fn verticalString str = 
(
	local outStr = ""
	for s in 1 to str.count do outStr += str[s]+"\n"
	outStr
)
verticalString "MULTIMATERIAL"

barigazy

artrender.info's picture

great idea

but if I use 2 clumns FlowLayoutPanel for the buttons then how to use labels?
or should I refuse from using FlowLayoutPanel?

And how to create labels from function, to add them depending on some parameters?

barigazy's picture

Label is not different then

Label is not different then button. Define only properties for backcolor,forecolor,textalign,...

lbl = dotnetobject "Label"
lbl.backcolor = lbl.backcolor.dimgray
lbl.forecolor = lbl.corecolor.lightgray
lbl.TextAlign = lbl.TextAlign.MiddleCenter
lbl.BorderStyle = lbl.BorderStyle.None
lbl.width = ...
lbl.height = ...
--etc
--use for-loop to create (combine Labels and Buttons inside FLP)
-- every odd will be Label and even will be Button
--for-loop example
for i = 1 to 10 do
(
	if mod i 2 != 0 then print ("Label_"+ i as string) else print ("Button_"+ i as string)
)
--Now just replace insted of print your functions for Label and Button definition

barigazy

Comment viewing options

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