It's a known problem with the visibility broken in dotNet in Maxsript. Here's a thread to show how you can add a button to a UserControl
to get it working.
My problem here is I want to add more than one button to the UserControl
and move the buttons into position once I know which to unhide which is not in this version but that's my intention for my need for this functionality.
The second button is not displaying even though its position is correct as formatted to the listener.
I hope I don't have to add seperate UserControl
's for each button!
How can I add more than one button to the control and have them update their positions and their visibility?
clearListener()
try destroyDialog RollsRoyce catch()
rollout RollsRoyce "" width:400 height:60
(
local btnH = 33
local btnW = RollsRoyce.width/2
dotnetcontrol panelVisibleFix "UserControl" width:RollsRoyce.width height:btnH pos:[0,15]
dotNetControl btn1 "button" text:"Button 1..." visible:false width:btnW height:btnH
dotNetControl btn2 "button" text:"Button 2..." visible:false width:btnW height:btnH
on RollsRoyce open do
(
btn1.FlatStyle = btn1.FlatStyle.System
btn2.FlatStyle = btn2.FlatStyle.System
panelVisibleFix.controls.addrange #(btn1, btn2)
-- Add the button to the panel and unhide it.
-- In my main script I want to check for conditions to have these visible or
-- not but with this simple example I want to unhide then.
btn1.visible = true
RollsRoyce.btn1.pos = panelVisibleFix.pos
-- This button is not getting shown.
btn2.visible = true
RollsRoyce.btn2.pos = RollsRoyce.panelVisibleFix.pos+[RollsRoyce.btnW,0]
format "btn1 position is: %\n" RollsRoyce.btn1.pos
format "btn2 position is: %\n" RollsRoyce.btn2.pos
)
)
createdialog RollsRoyce
You are using rollout controls as if they were regular .NET controls, and you're setting their position in context of the rollout as if you were setting it inside the .NET control. Either do one thing or the other. With .NET controls inside a rollout control, it could look for example like this:
try destroyDialog RollsRoyce catch()
rollout RollsRoyce "" width:400 height:60
(
local btnH = 33
dotNetControl panelVisibleFix "FlowLayoutPanel" width:RollsRoyce.width height:btnH pos:[0,15]
fn makeNETBtn width height text visible:on =
(
local btn = dotNetObject "Button"
btn.Text = text
btn.Width = width
btn.Margin = dotNetObject "Padding" 0 0 0 0
btn.Height = height
btn.FlatStyle = btn.FlatStyle.System
btn.Visible = visible
return btn
)
on RollsRoyce open do
(
local btnW = RollsRoyce.width / 2
local btn1 = makeNETBtn btnW btnH "Button 1..." visible:off
local btn2 = makeNETBtn btnW btnH "Button 2..." visible:off
panelVisibleFix.Controls.AddRange #(btn1, btn2)
btn1.visible = on
btn2.visible = on
)
)
createDialog RollsRoyce