Notifications
Clear all

[Closed] messagebox width?

Hi, sorry to create a whole thread for this, but i wasnt sure where else this should go.
basically is there a way to control the width of a messagebox? I’m currently throwing up some pretty long file paths and they’re being lost off the edge.
Any help would be great.
Thanks!
Tom

11 Replies

You can use escape characters in the strings to make a multi-line error message. So use
to do a carraige return.

Messagebox "This is a very very very very very very
very
very
very
long message!"

You can easily write a function to put some ’
’ in a very long string working out if the string is too long by using thestring.count will give you the number of characters.

Hi,

How about truncating the text? You can test it’s width in pixels and then delete some letter in the middle until it fits


 str="This is a very long string that has been written so I can test my string truncation method."
 width=200
 while (GetTextExtent str)[1]>width do str=((substring str 1  ((str.count/2)-3))+"..."+(substring str ((str.count/2)+3) str.count))
 

(made as small as possible for Denis’s benefit, now his turn)

J.

1 Reply
(@denist)
Joined: 11 months ago

Posts: 0

the truncating a long text is absolutely right idea. i usually do it to place filenames(paths) in UI.
working with filenames it makes sense to truncate beginning of the path. so my simple version of the string truncation looks:


str = @"C:\Program Files (x86)\Autodesk\3ds Max 2010 SDK\maxsdk\ProjectSettings\AdditionalCompilerOptions.Readme.txt"
fn truncateString  str width:200 = if (gettextextent str).x > width then
(
	width -= (gettextextent "...").x
	local new  
	for k=1 to str.count while (gettextextent (new = substring str k -1)).x > width do ()
	"..." + new
) else str
truncateString  str

thanks guys, i was doing the forced line break, but i was displaying some long file paths through variables that were causing problems. I might see if i can do something with j-mans suggestion, thanks for that
would be much easier if messageboxes just had a ‘width:’ attribute, but i guess they really dont…

You could also display the complete filename and only truncate the path using:

filenameFromPath and getFilenamePath

to seperate the filename and path before shortening the path.

J.

and there it is <:

J.

1 Reply
(@denist)
Joined: 11 months ago

Posts: 0

actually as you see my function doesn’t work correct. it might return a text longer than the limit.
it’s why i called it simple version.

it’s easy do use .net to messages:


(
	local str = @"C:\Program Files (x86)\Autodesk\3ds Max 2010 SDK\maxsdk\ProjectSettings\AdditionalCompilerOptions.Readme.txt"

	local mb = dotnetclass "MessageBox"
	local button = (dotnetclass "MessageBoxButtons").YesNo
	local icon = (dotnetclass "MessageBoxIcon").Warning
	
	local result = mb.show (str + "

" + "Do you want to save the file?") "Quit" button icon
	format "action: %
" (result.ToString())
) 

the .net messagebox cares about a message length itself.

I wanted to play with the big boys and went totally overboard and failed:


Looks like I got the wrong handle

he-he… it seems like you want to change message box size. you got the right handle…

haha, wow thanks guys; i came up with a temp fix but i might try out your suggestions when i get more time