JOlsson Posted November 14, 2008 Share Posted November 14, 2008 Hi,Here is my goal: I want to create a GUI window using AutoIt to display a multi-line text message to the user. The window should have the following characteristics:The window should not be resizable by the user.The window should base its width and height on the multi-line text message to display. That is, the window size should be calculated dynamically by the script based on the longest line in the multi-line text message to display and on how many lines there are in the message.Essentially, what I want is a MsgBox window that I am able to control the status of and update the text and sizing of dynamically while it is being displayed.My most immediate questions are:How do I calculate horizontal window size based on number of characters per line in a string?How do I calculate vertical window size based on number of lines in a string?I realize that this is based on the font size used but it would be helpful with some pointers to get me started. Link to comment Share on other sites More sharing options...
Andreik Posted November 14, 2008 Share Posted November 14, 2008 Rasim wrote a function _AutoSize() for an InputBox. Search this function and modify it for your needs. When the words fail... music speaks. Link to comment Share on other sites More sharing options...
LarryDalooza Posted November 14, 2008 Share Posted November 14, 2008 consider... Opt("GUIResizeMode",802) $testtext1 = "test me" & @LF & "test the hell out of me" & @LF & "mutha tester" $testtext2 = "I am a test, I am only a test, and I 'm sitting here on capitol hill" $gui = GUICreate("",300,300) GUICtrlCreateLabel($testtext1,10,10) $wh = ControlGetPos($gui,"","Static1") WinMove($gui,"",20,20,$wh[2]+20,$wh[3]+44) GUISetState() Sleep(5000) GUIDelete($gui) $gui = GUICreate("",300,300) GUICtrlCreateLabel($testtext2,10,10) $wh = ControlGetPos($gui,"","Static1") WinMove($gui,"",20,20,$wh[2]+20,$wh[3]+44) GUISetState() Sleep(5000) GUIDelete($gui) You may want to determine the Caption Height programatically to add it to the WinMove() height parameter. Lar. AutoIt has helped make me wealthy Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted November 17, 2008 Moderators Share Posted November 17, 2008 (edited) @Lar, Your idea is very nearly perfect - and I thought it was the answer to my prayers. But it only works as long as you stick with the default font size! I was experimenting and wondering why it did not work as I expected. Then I discovered that it does not work if you use a GUICtrlSetFont on the label and change the point value or face (unless the combination closely matches the default font). It seems that calling GUICtrlCreateLabel without size parameters assumes that the font is the default - so any attempt to use a different font or point value will not produce the correct sized label. Try the following:#include <GUIConstantsEx.au3> GUICreate("My Test", 110, 150) GUICtrlCreateLabel("This is a test!", 10, 10) GUICtrlSetBkColor(-1, 0xFFFF00) GUICtrlCreateLabel("This is a test!", 10, 40) GUICtrlSetBkColor(-1, 0xFFFF00) GUICtrlSetFont(-1, 12) GUICtrlCreateLabel("This is a test!", 10, 70) GUICtrlSetBkColor(-1, 0xFFFF00) GUICtrlSetFont(-1, Default, Default, 1, "Comic Sans MS") GUICtrlCreateLabel("This is a test!", 10, 100) GUICtrlSetBkColor(-1, 0xFFFF00) GUICtrlSetFont(-1, Default, Default, 1, "Courier New") GUISetState() While 1 $msg = GUIGetMsg() If $msg = $GUI_EVENT_CLOSE Then Exit WEnd On my machine I get identical label sizes - and only the first and third allow all the text of the message to display. So, if you want to use this technique, be aware that it has its limitations. M23 Edit: More experimentation shows that the label does indeed use the size of the GUI font - and using GUISetFont on the GUI produces the label correctly for the chosen font face and size. So the limitation is not as bad as I feared - AutoIt comes up trumps again! Edited November 18, 2008 by Melba23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now