How to fit a rollout to a dotnet labels contents and show tabs correctly

My end goal here is to make a custom messagebox as I want to gain control over its position.

I want to get two things figured out here.

1. How do I fit the dialog to the size of the contents like the attached maxscript messagebox.png for this dialog?
2. Is it possible to have the \t characters line up like the messagebox also?

Here's the label inside a basic rollout.

clearlistener()
 
(
  try destroyDialog rolloutName catch()
 
  rollout rolloutName "rolloutName" (
 
   dotNetControl lbl_msg "Label"  --width:(rolloutName.width-20) height:100
 
   fn dotNetControlsInt =
   (
 
    show lbl_msg
 
    --      TheFont = dotnetobject "System.Drawing.Font" "Arial" 10
    --     lbl_msg.font = TheFont
 
    lbl_msg.BackColor = (dotNetClass "System.Drawing.Color").fromARGB (((colorMan.getColor #background) * 255)[1] as integer) (((colorMan.getColor #background) * 255)[2] as integer) (((colorMan.getColor #background) * 255)[3] as integer)
    lbl_msg.ForeColor = (dotNetClass "System.Drawing.Color").fromARGB (((colorMan.getColor #text) * 255)[1] as integer) (((colorMan.getColor #text) * 255)[2] as integer) (((colorMan.getColor #text) * 255)[3] as integer)
    lbl_msg.UseCompatibleTextRendering = true
    lbl_msg.AutoSize = true
 
    lbl_msg.TabIndex = 4
    lbl_msg.TabStop = true
 
    lbl_msg.Size = dotnetObject "System.Drawing.Size" 500 600
 
    labelText = "This\t\tis\n_a_\t\ttest.\nThis\t\tis\n_a_\t\ttest.\nThis\t\tis\n_a_\t\ttest.\nThis\t\tis\n_a_\t\ttest.\nThis\t\tis\n_a_\t\ttest.\nThis\t\tis\n_a_\t\ttest.\nThis\t\tis\n_a_\t\ttest.\nThis\t\tis\n_a_\t\ttest.\nThis\t\tis\n_a_\t\ttest.\nThis\t\tis\n_a_\t\ttest.\nThis\t\tis\n_a_\t\ttest.\nThis\t\tis\n_a_\t\ttest.\nThis\t\tis\n_a_\t\ttest.\nThis\t\tis\n_a_\t\ttest.\nThis\t\tis\n_a_\t\ttest.\nThis\t\tis\n_a_\t\ttest.\nThis\t\tis\n_a_\t\ttest.\nThis\t\tis\n_a_\t\ttest.\nThis\t\tis\n_a_\t\ttest.\nThis\t\tis\n_a_\t\ttest.\nThis\t\tis\n_a_\t\ttest.\nThis\t\tis\n_a_\t\ttest.\nThis\t\tis\n_a_\t\ttest.\nThis\t\tis\n_a_\t\ttest.\nThis\t\tis\n_a_\t\ttest.\n"
 
    -- My effort to get the tabs to line up. Yes, its really useless.
    lbl_msg.Text = substituteString labelText "\t" "\x0009" -- A Unicode attempt.
    lbl_msg.Text = substituteString labelText "\t" "    " -- The more useless attempt.
 
    )
 
   on rolloutName open do dotNetControlsInt()
 
   )
 
  createDialog rolloutName 500 250
  )
AttachmentSize
maxscript_messagebox.png10.88 KB

Comments

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
miauu's picture

.

Try this:

(
	fn MessageBoxEx message caption:"Message" buttons:#OK icon:#Information =
	(
	    local MsgBox = dotnetclass "System.Windows.Forms.MessageBox"
	    local MessageBoxButtons = dotnetclass "System.Windows.Forms.MessageBoxButtons"
	    local MessageBoxIcon = dotnetclass "System.Windows.Forms.MessageBoxIcon"
	    local DialogResult = dotnetclass "System.Windows.Forms.DialogResult"
 
	    local _buttons = case buttons of
	    (
		#AbortRetryIgnore: MessageBoxButtons.AbortRetryIgnore
		#OK: MessageBoxButtons.OK
		#OKCancel: MessageBoxButtons.OKCancel
		#RetryCancel: MessageBoxButtons.RetryCancel
		#YesNo: MessageBoxButtons.YesNo
		#YesNoCancel: MessageBoxButtons.YesNoCancel
	    )
 
	    local _icon = case icon of
	    (
		#Asterisk: MessageBoxIcon.Asterisk
		#Error: MessageBoxIcon.Error
		#Exclamation: MessageBoxIcon.Exclamation
		#Hand: MessageBoxIcon.Hand
		#Information: MessageBoxIcon.Information
		#None: MessageBoxIcon.None
		#Question: MessageBoxIcon.Question
		#Stop: MessageBoxIcon.Stop
		#Warning: MessageBoxIcon.Warning
	    )
 
	    local result = case MsgBox.Show message caption _buttons _icon of
	    (
		(DialogResult.Abort): #Abort
		(DialogResult.Cancel): #Cancel
		(DialogResult.Ignore): #Ignore
		(DialogResult.No): #No
		(DialogResult.None): #None
		(DialogResult.OK): #OK
		(DialogResult.Retry): #Retry
		(DialogResult.Yes): #Yes
	    )
 
	    return result
	)
 
	labelText = "This\t\tis\n_a_\t\ttest.\nThis\t\tis\n_a_\t\ttest.\nThis\t\tis\n_a_\t\ttest.\nThis\t\tis\n_a_\t\ttest.\nThis\t\tis\n_a_\t\ttest.\nThis\t\tis\n_a_\t\ttest.\nThis\t\tis\n_a_\t\ttest.\nThis\t\tis\n_a_\t\ttest.\nThis\t\tis\n_a_\t\ttest.\nThis\t\tis\n_a_\t\ttest.\nThis\t\tis\n_a_\t\ttest.\nThis\t\tis\n_a_\t\ttest.\nThis\t\tis\n_a_\t\ttest.\nThis\t\tis\n_a_\t\ttest.\nThis\t\tis\n_a_\t\ttest.\nThis\t\tis\n_a_\t\ttest.\nThis\t\tis\n_a_\t\ttest.\nThis\t\tis\n_a_\t\ttest.\nThis\t\tis\n_a_\t\ttest.\nThis\t\tis\n_a_\t\ttest.\nThis\t\tis\n_a_\t\ttest.\nThis\t\tis\n_a_\t\ttest.\nThis\t\tis\n_a_\t\ttest.\nThis\t\tis\n_a_\t\ttest.\nThis\t\tis\n_a_\t\ttest.\n"
 
	MessageBoxEx labelText buttons:#OK icon:#Information
)
3dwannab's picture

.

Thanks, I was trying to create my own message box but wanted to have control over the position of it.

My main obstacle is to get tabbing to work for the label and the auto sizing of it which in turn will help me resize the main dialog.

Meant tab in this screenshot text below.

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.