[Closed] DotNet store data in Form?
Hi
Im trying to pas some types of data in to DotNet form
Maybe some of them can’t be stored…I dont know…
DATA:
- obj = dotnetObject “button”
- img = dotNetObject “ImageList”
- str = dotnetObject “System.String” “The String”
- val = dotnetObject “System.Int32” 8
- float = ???
- arr = #(1,2,3,A,B,C)
- str = struct data (name, age, height)
How can I store them?
here is an example :
- obj: , 2) img
form = dotnetObject “form”
form.name = “my form”
btn = dotnetObject “button”
btn.name = “my button”
img_list = dotNetObject “ImageList”
store data:
container = dotnetObject “System.ComponentModel.Container”
container.add form form.name
container.add btn btn.name
container.add img_list “my images”
get them back:
container.Components.count
container.Components.item[0].name
container.Components.item[1].name
container.Components.item[1].handle
container.components.item “my button”
form.container.components.item “my button”
btn.container.components.item “my button”
my research ends here…:curious:
to pass the other types of data I ned some help here
here is maybe way to go…
bs= (dotNetObject “BindingSource”)
bs.Add strArray
container.add bs “my array”
form.DataBindings
form.DataBindings.Add (???) (???) (???)
the easiest way to store any max data in dotnet object to assign some value to it’s tag:
<object>.tag = dotNetMXSValue data
data might any max data including arrays, MAXObjects, and structures.
Hi Denis! , I did not know about dotNetMXSValue ,wery good!
(
struct FORM_DATA (name="merlin", age=240, weight=58.24, childerns = #("a","b","c"))
local f = dotnetobject "form"
f.tag = dotNetMXSValue (FORM_DATA())
gc()
local b1 = dotnetobject "button"
b1.text = "Get Name"
local b2 = dotnetobject "button"
b2.text = "Get Age"
local b3 = dotnetobject "button"
b3.text = "Get Weight"
local b4 = dotnetobject "button"
b4.text = "Get Childerns"
fn _getName = (format "Name:%
" f.tag.name)
fn _getAge = (format "Age:%
" f.tag.age)
fn _getWeight = (format "Name:%
" f.tag.weight)
fn _getChilderns = (format "Name:%
" f.tag.childerns)
dotNet.addeventhandler b1 "click" _getName
dotNet.addeventhandler b2 "click" _getAge
dotNet.addeventhandler b3 "click" _getWeight
dotNet.addeventhandler b4 "click" _getChilderns
local lp = dotNetObject "TableLayoutPanel"
lp.autosize = true
lp.controls.addRange( #(b1,b2,b3,b4) )
f.controls.add( lp )
f.show()
)
But there is a little catch heh…
How can I acces in this struct now ?
– Error occurred in _getName()
– Frame:
>> MAXScript dotNet event handler Exception: – Unknown property: “name” in dotNetMXSValue:[(FORM_DATA name:“merlin” age:240 weight:58.24 childerns:#(“a”, “b”, “c”))] <<
dotNetMXSValue works fine, however I have a smal problem here…
maybe Big one…
when GC() is caled then, form buttons goes to dead.
GLOBAL NEW_FORM
(
struct FORM_DATA (name, age, weight, childerns)
local f = dotnetobject "form"
f.tag = dotNetMXSValue (FORM_DATA "merlin" 240 58.24 #("a","b","c"))
local b1 = dotnetobject "button"
b1.text = "Get Name"
local b2 = dotnetobject "button"
b2.text = "Get Age"
local b3 = dotnetobject "button"
b3.text = "Get Weight"
local b4 = dotnetobject "button"
b4.text = "Get Childerns"
fn _getName s a = (format "Name:%
" s.parent.parent.tag.value.name)
fn _getAge s a = (format "Age:%
" s.parent.parent.tag.value.age)
fn _getWeight s a = (format "Name:%
" s.parent.parent.tag.value.weight)
fn _getChilderns s a = (format "Name:%
" s.parent.parent.tag.value.childerns)
dotNet.addeventhandler b1 "MouseUp" _getName
dotNet.addeventhandler b2 "MouseUp" _getAge
dotNet.addeventhandler b3 "MouseUp" _getWeight
dotNet.addeventhandler b4 "MouseUp" _getChilderns
local lp = dotNetObject "TableLayoutPanel"
lp.autosize = true
lp.controls.addRange( #(b1,b2,b3,b4) )
f.controls.add( lp )
NEW_FORM = f
f = undefined
NEW_FORM.show()
)
I think you are find the solution in the past , but it was max rollout not DotNet form.
add
dotnet.setLifetimeControl b1 #dotnet
dotnet.setLifetimeControl b2 #dotnet
dotnet.setLifetimeControl b3 #dotnet
dotnet.setLifetimeControl b4 #dotnet
what a pity setLifetimeControl is missing in max9
#Struct:dotNet(
removeAllEventHandlers:<fn>,
getType:<fn>,
removeEventHandler:<fn>,
combineEnums:<fn>,
showConstructors:<fn>,
removeEventHandlers:<fn>,
compareEnums:<fn>,
loadAssembly:<fn>,
addEventHandler:<fn>)
max9? setLifetimeControl was added to MAX 2010… let me think what can we do with max9…
or include buttons in the structure:
struct FORM_DATA (name, age, weight, childerns, buttons)
…
f.tag = dotNetMXSValue (FORM_DATA “merlin” 240 58.24 #(“a”,“b”,“c”) #(b1,b2,b3,b4))