[Closed] dotnet ui controls – chaos
Well,
I am greatly confused here. I tried to build my first complete dotNet UI and so far it has been quite a hassle. I need a form that has a background image and then all kinds of controls within it, including a combobox and a textbox.
I started with a max rollout and a bunch of dotnetcontrols. Something like this
rollout rollo "test" (
dotNetControl dnc_AllCtrls "System.Windows.Forms.Panel" pos:[0,0] width:270 height:238
dotNetControl dnc_test "System.Windows.Forms.TextBox" pos:[0,0] width:109 height:17
on rollo_saveScene open do (
dnc_bg = dotNetClass "System.Drawing.Image"
dnc_bg = (dotNetClass "System.Drawing.Image").fromFile("...\\bg_test.bmp")
dnc_AllCtrls.BackgroundImage = dnc_bg
dnc_AllCtrls.controls.add dnc_test
dnc_test.Location = dotNetObject "System.Drawing.Point" 83 35
dnc_test.Size = dotNetObject "System.Drawing.Size" 109 37
)
)
createDialog rollo width:270 height:210 style:#(#style_toolwindow, #style_sysmenu)
But with the code above I had problems placing my controls in the right location on the panel. Added controls wouldn't either be movable at all or their sizes didn't adjust correctly. I tried all kinds of combinations with giving the size/location values through the constructor or with a dotnetobject or both.
Then I tried to following approch:
dnc_form = dotNetObject "MaxCustomControls.MaxForm"
dnc_form.Size = dotNetObject "System.Drawing.Size" 270 238
dnc_bg = dotNetClass "System.Drawing.Image"
dnc_bg = (dotNetClass "System.Drawing.Image").fromFile("...\\bg_test.bmp")
dnc_AllCtrls.BackgroundImage = dnc_bg
dnc_ComboBox = dotNetObject "System.Windows.Forms.ComboBox"
dnc_ComboBox.Location = dotNetObject "System.Drawing.Point" 20 35
dnc_ComboBox.Size = dotNetObject "System.Drawing.Size" 51 17
ComboBoxStyle = dotNetClass "System.Windows.Forms.ComboBoxStyle"
dnc_ComboBox.DropDownStyle = ComboBoxStyle.DropDownList
dnc_TextBox = dotNetObject "System.Windows.Forms.TextBox"
dnc_TextBox.Location = dotNetObject "System.Drawing.Point" 83 35
dnc_TextBox.Size = dotNetObject "System.Drawing.Size" 109 17
dnc_form.controls.add dnc_ComboBox
dnc_form.controls.add dnc_TextBox
dnc_form.show()
Which enabled me to place the controls nicely, the textbox worked, but the combobox would cause an error on max's garbage collection.
Next I tried something like the following:
rollout rollo_test "Test - DropDown" (
dotNetControl dnc_AllCtrls "System.Windows.Forms.Panel" pos:[0,0] width:270 height:238
on rollo_test open do (
dnc_bg = dotNetClass "System.Drawing.Image"
dnc_bg = (dotNetClass "System.Drawing.Image").fromFile("...\\bg_test.bmp")
dnc_AllCtrls.BackgroundImage = dnc_bg
dnc_ComboBox = dotNetObject "System.Windows.Forms.ComboBox"
dnc_ComboBox.Location = dotNetObject "System.Drawing.Point" 20 35
dnc_ComboBox.Size = dotNetObject "System.Drawing.Size" 51 17
ComboBoxStyle = dotNetClass "System.Windows.Forms.ComboBoxStyle"
dnc_ComboBox.DropDownStyle = ComboBoxStyle.DropDownList
dnc_TextBox = dotNetObject "System.Windows.Forms.TextBox"
dnc_TextBox.Location = dotNetObject "System.Drawing.Point" 83 35
dnc_TextBox.Size = dotNetObject "System.Drawing.Size" 109 17
dnc_AllCtrls.controls.add dnc_ComboBox
dnc_AllCtrls.controls.add dnc_TextBox
)
)
createDialog rollo_test width:270 height:210 style:#(#style_toolwindow, #style_sysmenu)
And now.... the textbox doesn't work anymore...grrrrr. Then I tried to convert only the textbox back to an dotnetcontrol, which then I couldn't place or size anymore, which means I am right back to where I've started.
I read up on all the different problems with the combobox and textbox but couldn't find anything about using both controltypes together or about my problems with placing dotnetcontrols on a panel.
Could anyone point me to the best approach for a dotnet form with a background image, controls placed they way I want them, including a combo and a textbox?
Thanks!
ok, sorry if my posting is one more time not comprehensible.
Lets break it down… how would you place this textbox on the panel? Have a look at my code and see how the text box is cut off at the sides. I tried all different kinds of combinations to place/size the textbox, but it is just not working…
rollout rollo_test "test" (
dotNetControl dnc_AllCtrls "System.Windows.Forms.Panel" pos:[0,0] width:270 height:210
dotNetControl dnc_scSet "System.Windows.Forms.TextBox" pos:[0,0] width:109 height:35
on rollo_test open do (
dnc_scSet.Location = dotNetObject "System.Drawing.Point" 83 10 --should be 83 35
--dnc_scSet.Size = dotNetObject "System.Drawing.Size" 83 55--should be 109 37
dnc_scSet.borderstyle = (dotNetClass "System.Windows.Forms.BorderStyle").FixedSingle
dnc_AllCtrls.controls.add dnc_scSet
)
)
createDialog rollo_test width:270 height:210 style:#(#style_toolwindow, #style_sysmenu)
Adding the textbox to the panel results in the problems with placing the textbox.
Hi lena,
I think it's because you are setting the location of the text box first, then adding it to the panel control. After you add it, the panel is effectively the parent control of the text box, which then offsets the control.
rollout rollo_test "test" (
dotNetControl dnc_AllCtrls "System.Windows.Forms.Panel" pos:[0,0] width:270 height:210
dotNetControl dnc_scSet "System.Windows.Forms.TextBox" pos:[0,0] width:109 height:35
on rollo_test open do (
--dnc_scSet.Location = dotNetObject "System.Drawing.Point" 5 5 --should be 83 35
--dnc_scSet.Size = dotNetObject "System.Drawing.Size" 83 55--should be 109 37
dnc_scSet.borderstyle = (dotNetClass "System.Windows.Forms.BorderStyle").FixedSingle
dnc_AllCtrls.controls.add dnc_scSet
dnc_scSet.Location = dotNetObject "System.Drawing.Point" 0 0
)
)
createDialog rollo_test width:270 height:210 style:#(#style_toolwindow, #style_sysmenu)
However, there is a bit of weirdness going on. if you are looking to offset the entire text box within the panel, you may have to use something like a table layout panel. it could be that when you set the location before you get the strange behaviour you are seeing , where the text area moves and leaves the border.
edit : you are right, max is doing some weird clipping stuff – you should be able to offset the location within a panel in the method you were doing. Any offset you try to apply seems to separate the fixed3d style from the single border style. very annoying. This behaviour could be because of how max packages a dotnetcontol when using it on a rollout. You will probably have to use a maxform instead to get predictable result swith the panel layout controls. boo.
Hey Pete, thanks for your answer.
Unfortunately your solution of using the maxform leads me right to the next problem: using a combobox. I have to have a combobox as well and if I use that within a maxform, I eventually get a garbage collection error from max:
dnc_form = dotNetObject "MaxCustomControls.MaxForm"
dnc_form.Size = dotNetObject "System.Drawing.Size" 270 238
dnc_TextBox = dotNetObject "System.Windows.Forms.TextBox"
dnc_TextBox.Location = dotNetObject "System.Drawing.Point" 83 35
dnc_TextBox.Size = dotNetObject "System.Drawing.Size" 109 17
dnc_ComboBox = dotNetObject "System.Windows.Forms.ComboBox"
dnc_ComboBox.Location = dotNetObject "System.Drawing.Point" 20 35
dnc_ComboBox.Size = dotNetObject "System.Drawing.Size" 51 17
ComboBoxStyle = dotNetClass "System.Windows.Forms.ComboBoxStyle"
dnc_ComboBox.DropDownStyle = ComboBoxStyle.DropDownList
dnc_form.controls.add dnc_ComboBox
dnc_form.controls.add dnc_TextBox
dnc_form.show()
gc()
Any thoughts on that?
Ok, I found a work-around for placing the textbox:
rollout rollo_test "test" (
dotNetControl dnc_AllCtrls "System.Windows.Forms.Panel" pos:[0,0] width:270 height:210
dotNetControl dnc_scSetCtrl "System.Windows.Forms.Panel"
dotNetControl dnc_scSet "System.Windows.Forms.TextBox" pos:[0,0] width:109 height:17
on rollo_test open do (
dnc_AllCtrls.controls.add dnc_scSetCtrl
dnc_scSetCtrl.Location = dotNetObject "System.Drawing.Point" 83 35
dnc_scSetCtrl.Size = dotNetObject "System.Drawing.Size" 192 55
dnc_scSetCtrl.controls.add dnc_scSet
dnc_scSet.borderstyle = (dotNetClass "System.Windows.Forms.BorderStyle").FixedSingle
dnc_ComboBox = dotNetObject "System.Windows.Forms.ComboBox"
dnc_ComboBox.Location = dotNetObject "System.Drawing.Point" 20 35
dnc_ComboBox.Size = dotNetObject "System.Drawing.Size" 51 17
ComboBoxStyle = dotNetClass "System.Windows.Forms.ComboBoxStyle"
dnc_ComboBox.DropDownStyle = ComboBoxStyle.DropDownList
dnc_AllCtrls.controls.add dnc_ComboBox
)
)
createDialog rollo_test width:270 height:210 style:#(#style_toolwindow, #style_sysmenu)
gc()
And now, hopefully, everything will be pretty and behaves nicely...