ScriptSpot

Forum topic · General Scripting

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

By 3dwannab · 2021-09-19

Downloads
Description

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
  )
Comments (2)

.

miauu · 2021-09-20

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 · 2021-09-20

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.