Notifications
Clear all

[Closed] Dropdown list, reinitialize items width

I’ve noticed that when a dropdownList is first run it gets the width of the longest item assigned to it and then sets that as its lists width. However this width property does not update when the items are changed. For example:

rollout testRoll "testing" width:180 height:100 (
dropdownlist dd_list "dropdownlist:" height:15 items:#("blah blah blah blah blah blah blah blah blah blah")
on testRoll open do (dd_list.items = #("testing"))
)
createdialog testRoll

This generates a very wide list, even though the actual text in it hardly takes up any room at all. And of course if initialized with a short string you run the risk of new items getting cut off. Is there a way to fix this?

15 Replies

Denis is there any way to resize a maxscript button using window.sendMessage?

3 Replies
(@denist)
Joined: 11 months ago

Posts: 0

button is a window. you can use windows.setWindowPos to change position and size

(@davewortley)
Joined: 11 months ago

Posts: 0

Very useful! thanks!

windows.setWindowPos dialog.resize_bt.hwnd[1] 20 30 50 20 true
so it’s Hwnd x y w h bool?
Boolean seems to have some effect on whether it remove the old one?

Is there any way to make the form redraw itself correctly as when you mouse-over it fixes itself but before that the text can sometimes be a bit screwed up…

(@denist)
Joined: 11 months ago

Posts: 0

i personally prefer to use MSDN version of setWindowPos made with pre-compiled (on-the-fly for example) assembly. the benefit of it is ability of change only pos or size as well as both together. you can find several examples of its using on this forum.

Thanks Denis. Sorry didn’t even notice the other topic (I typically just go right to google).

Anyhow, Having some problems getting the text width. I thought Max used Times New Roman or Courier as its default font, but it always ends up too wide. Here’s what I’m doing:

ddPixelWidth = ((dotNetClass “TextRenderer”).MeasureText myStringVariable (dotNetObject “System.Drawing.Font” “Courier” 10)).width
windows.sendmessage ddMenu.hwnd[1] 352 ddPixelWidth 0

as i remember the default mxs controls font is “Tahoma,8”

Perfect. Thanks!

redraw is a bit tricky. when you change size of a button the button probably does do something to adjust text margins. it’s hard to say how well it does. maybe MSDN RedrawWindow works better.

4 Replies
(@polytools3d)
Joined: 11 months ago

Posts: 0

Setting the control position seems to fix the redrawing issue. Not sure if it will work with all controls and in all cases though. Other properties may also do the trick.

try destroydialog ::RO_TEST catch()
 rollout RO_TEST "" width:136 height:120
 (
 	button btn1 "Click Me" pos:[8,8] width:120 height:32
 	checkbox chk1 "Fix Redraw" pos:[8,48] width:80 height:16
 	button btn2 "EXAMPLE" pos:[8,80] width:120 height:32
 	
 	on btn1 pressed do
 	(
 		windows.setwindowpos btn2.hwnd[1] 8 80 (random 8 120) 32 true
 		if chk1.checked do btn2.pos = btn2.pos
 	)
 )
 createdialog RO_TEST
(@denist)
Joined: 11 months ago

Posts: 0

this is what windows.setwindowpos has to do with redraw turned ON. but David told about an issue.

(@polytools3d)
Joined: 11 months ago

Posts: 0

Yes, the ‘repaint’ argument seems to be buggy and so my sugestion was to use the .pos property of the control instead and see if it solves the redrawing. It appears it does.

<control>.pos = <control>.pos

Perhaps windows.setWindowPos() is not meant to be used with controls but with rollouts? Who knows?

(@denist)
Joined: 11 months ago

Posts: 0

ahh… i see. but the idea was to move/size a control by its hwnd (in case when you have no idea about its source)

also the moving has to be OK. the sizing might be problematic

Other properties also seem to “fix” the repainting of the UI, and the <enabled> property appears to perform faster. If you have to update a lot of controls, perhaps you can just iterate over all of them like:

for ctrl in <rollout>.controls do ctrl.enabled = ctrl.enabled

Nice to know thanks!