messagebox width?

Become a member of the CGSociety

Connect, Share, and Learn with our Large Growing CG Art Community. It's Free!

THREAD CLOSED
 
Thread Tools Search this Thread Display Modes
Old 07 July 2011   #1
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
__________________
Visit my Portfolio :)
 
Old 07 July 2011   #2
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.
__________________
Maxscript Made Easy...
http://davewortley.wordpress.com/

Last edited by DaveWortley : 07 July 2011 at 02:12 PM.
 
Old 07 July 2011   #3
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.
__________________
www.joshuanewman.net
 
Old 07 July 2011   #4
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..
__________________
Visit my Portfolio :)
 
Old 07 July 2011   #5
You could also display the complete filename and only truncate the path using:

filenameFromPathand getFilenamePath

to seperate the filename and path before shortening the path.

J.
__________________
www.joshuanewman.net
 
Old 07 July 2011   #6
Originally Posted by j-man: 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\AdditionalCompilerOptio  ns.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
 
Old 07 July 2011   #7
and there it is <:

J.
__________________
www.joshuanewman.net
 
Old 07 July 2011   #8
it's easy do use .net to messages:

(
	local str = @"C:\Program Files (x86)\Autodesk\3ds Max 2010 SDK\maxsdk\ProjectSettings\AdditionalCompilerOptio  ns.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.
 
Old 07 July 2011   #9
Originally Posted by j-man: 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.
 
Old 07 July 2011   #10
I wanted to play with the big boys and went totally overboard and failed:


Looks like I got the wrong handle
__________________
Homepage clicky clickey!
 
Old 07 July 2011   #11
he-he... it seems like you want to change message box size. you got the right handle...
 
Old 07 July 2011   #12
haha, wow thanks guys; i came up with a temp fix but i might try out your suggestions when i get more time
__________________
Visit my Portfolio :)
 
Old 07 July 2011   #13
Thread automatically closed

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.
__________________
CGTalk Policy/Legalities
Note that as CGTalk Members, you agree to the terms and conditions of using this website.
 
Thread Closed share thread



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
CGSociety
Society of Digital Artists
www.cgsociety.org

Powered by vBulletin
Copyright ©2000 - 2006,
Jelsoft Enterprises Ltd.
Minimize Ads
Forum Jump
Miscellaneous

All times are GMT. The time now is 01:25 PM.


Powered by vBulletin
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.