View Full Version : messagebox width?
ilithian 07-19-2011, 01:19 PM 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
|
|
DaveWortley
07-19-2011, 02:09 PM
You can use escape characters in the strings to make a multi-line error message. So use \n to do a carraige return.
Messagebox "This is a very very very very very very\nvery\nvery\nvery\nlong message!"
You can easily write a function to put some '\n' in a very long string working out if the string is too long by using thestring.count will give you the number of characters.
j-man
07-19-2011, 02:26 PM
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.
ilithian
07-19-2011, 04:25 PM
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..
j-man
07-19-2011, 04:33 PM
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.
denisT
07-19-2011, 04:48 PM
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.
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
j-man
07-19-2011, 04:55 PM
and there it is <:
J.
denisT
07-19-2011, 05:11 PM
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 + "\n\n" + "Do you want to save the file?") "Quit" button icon
format "action: %\n" (result.ToString())
)
the .net messagebox cares about a message length itself.
denisT
07-19-2011, 05:14 PM
and there it is <:
J.
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. ;)
haavard
07-19-2011, 09:36 PM
I wanted to play with the big boys and went totally overboard and failed:
http://folk.ntnu.no/havardsc/misc/messageBoxFail.png (http://folk.ntnu.no/havardsc/misc/messageBoxFail.png)
Looks like I got the wrong handle
:p
denisT
07-19-2011, 10:15 PM
he-he... it seems like you want to change message box size. you got the right handle... :)
ilithian
07-20-2011, 09:49 AM
haha, wow thanks guys; i came up with a temp fix but i might try out your suggestions when i get more time
CGTalk Moderation
07-20-2011, 09:49 AM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.
vBulletin v3.0.5, Copyright ©2000-2013, Jelsoft Enterprises Ltd.