I’m trying to get a .NET label to autofit its contents and then in turn change the size of the dialog. Much like how messagebox behaves only with this I have more control over the width of the message box and more importantly for me the position of the message box. Center screen doesn’t really work that great because the UI of my script will more often than not get used on a secondary monitor.
\t doesn’t work either. At least I can’t see a way to get them to.
Here’s the code:
clearlistener() ( try destroyDialog rolloutName catch() ::rolloutName fn dnDrawingColorFromColorMan name = (clr = (colorMan.getColor name) * 255.0 ; (dotNetClass "System.Drawing.Color").fromARGB clr.x clr.y clr.z) fn dnDrawingSize x y = dotnetObject "System.Drawing.Size" x y rollout rolloutName "A Label Attempt to Change the Rollout Size" ( dotNetControl lbl_msg "Label" fn dotNetControlsInt = ( -- show lbl_msg labelMaxWidth = rolloutName.width-20 labelMinWidth = 200 p2ScreenSize = [(dotnetclass"System.Windows.Forms.Screen").primaryscreen.bounds.width,(dotnetclass"System.Windows.Forms.Screen").primaryscreen.bounds.height] theFont = dotnetobject "System.Drawing.Font" "Arial" 10 -- Label colours and others lbl_msg.font = theFont lbl_msg.BackColor = dnDrawingColorFromColorMan #background lbl_msg.ForeColor = dnDrawingColorFromColorMan #text lbl_msg.UseCompatibleTextRendering = true -- Here's where I've tried to get the label to autofit lbl_msg.AutoSize = true lbl_msg.MinimumSize = dnDrawingSize labelMinWidth 200 lbl_msg.MaximumSize = dnDrawingSize labelMaxWidth (p2ScreenSize.y-80) -- Minus 80 for the taskbar as it could be double height. 40 px is what's on mine for a single height taskbar lbl_msg.Height = lbl_msg.PreferredHeight lbl_msg.AutoSize = true labelText = "I'm\ttrying to access a property of the mainSubRollout for the order the sub rollouts are in." labelText += "\n" labelText += "\n\tAfter running the code below and dragging Sub 2 rollout to the top like the image and checking mainRolTest.mainSubRollout.rollouts it always returns #(Rollout:subRollout1, Rollout:subRollout2) even though the displayed order of the rollouts are not the same." labelText += "\n" labelText += "\n\tenter image description here" labelText += "\n" labelText += "\n\tHow can I access this order in which they are currently displayed?" labelText += "\n" labelText += "\n\tA result for the image should be: #(Rollout:subRollout2, Rollout:subRollout1)" labelText += "\n" labelText += "\n\tI have a Panel that I'm creating programmatically; additionally I'm adding several components to it." labelText += "\n" labelText += "\n\tOne of these components is a Label which will contain user-generated content." labelText += "\n" labelText += "\n\tI don't know how tall the label should be, but it does have a fixed width." labelText += "\n" labelText += "\n\tHow can I set the height so that it displays all the text, without changing the width?" -- Not a great attempt at getting tabs '\t' to work lbl_msg.TabIndex = 4 lbl_msg.TabStop = true -- lbl_msg.Text = substituteString labelText "\t" "\x0009" -- A Unicode attempt. -- lbl_msg.Text = substituteString labelText "\t" " " -- A Unicode attempt. lbl_msg.Text = labelText ) on rolloutName open do dotNetControlsInt() ) createDialog rolloutName 600 250 )