[Closed] Align button to right side in a dialog
Hello!
I’m creating a new dialog and I was wondering if it was at all possible to align a button, imgtag or whatever to the right side of the window.
So that even after resizing, the button “sticks” to the right side of the window instead of disappearing?
I suspect there is no way of doing this with maxscript, since I have not been able to find anything. I might be wrong, though.
Would it be possible to do something like this with dotnet?
Thanks,
Norman
in maxscript you have to do it the hard way, create a ‘on dialog resized’ event handler, and in it set the position of the button relative to the new width of the dialog.
In dotnet it’s much easier, as you simply set flags for which sides you want the control to be anchored to, using the anchor property.
I’m afraid you cannot change buttons position after the dialogs creation, at least not with maxscript. :banghead:
If anyone can quickly show me an example with dotnet, I would really appreciate it.
maxscript example:
try(destroyDialog resizeExample)catch()
rollout resizeExample "A rollout" width:400 height:300
(
button rightSideBtn "Button2" width:50 height:30 pos:[300,250]
on resizeExample resized newSize do
(
rightSideBtn.pos=[newSize[1]-100,newSize[2]-50]
)
)
createDialog resizeExample style:#(#style_titlebar, #style_border, #style_sysmenu,#style_resizing,#style_maximizebox)
I’ll post a dotnet example soon
I think the reason “align: #right” wouldn’t work in this case is because he’s saying when the window is resized, not when it’s created, else you could just use the usual.
align: #left
align: #center
align: #right
dotnet example wrapped in a maxscript rollout using a panel control (I personally prefer this to a dotnet form, but that’s just personal taste):
try(destroyDialog resizeExampleDotnet)catch()
rollout resizeExampleDotnet "A rollout" width:400 height:300
(
local anchorStyle = dotNetClass "System.Windows.Forms.AnchorStyles"
local btn = dotNetObject "System.Windows.Forms.Button"
dotNetControl panel "System.Windows.Forms.Panel" width:400 height:300 pos:[0,0]
on resizeExampleDotnet open do
(
btn.bounds = dotNetObject "System.Drawing.Rectangle" 300 200 50 30
btn.text = "dotnet button"
btn.anchor = dotNet.combineEnums anchorStyle.Right anchorStyle.Bottom
panel.controls.add btn
)
on resizeExampleDotnet resized newSize do
(
panel.width=newSize[1]
panel.height=newSize[2]
)
)
createDialog resizeExampleDotnet style:#(#style_titlebar, #style_border, #style_sysmenu,#style_resizing,#style_maximizebox)
D’oh! Thanks lo! I was actually doing it wrong with maxscript…
I was doing this:
on test_move resized theSize do
(
btn_test.pos[1] = theSize[1] - 40
)
Thanks again! I also prefer a dotnet object. At this point it’s easier for me to replace buttons than to write a new dotnet form!
Yeah you can’t change just one component of a point2 .pos property. Another advantage with dotnetobjects is that you can change their width and height after creation, while with maxscript controls there is no way to do that.
Not directly but for some of them there’s a way. Not that it would make more sense to use this rather than dotnet buttons, though:
try destroyDialog test catch()
rollout test ""
(
button btn " Wide "
slider sld range:[0,20,2]
on sld changed val do
(
local spaces = ""
for i = 1 to val do append spaces " "
btn.text = (spaces + "Wide" + spaces)
)
)
createDialog test