Jump to content

GUI: Wrap label text without spaces?


caseelse
 Share

Recommended Posts

Hello everybody!

I'm trying to create a label which displays strings of up to 64 characters (alphanumeric and special chars). However, the label is 32 chars wide and 2 chars high. So I would like strings with more than 32 chars to wrap to two lines without having to insert spaces anywhere in the string. This is what it looks like at the moment

#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
...
GUICtrlCreateLabel("1234567890123456789012345678901234567890123456789012345678901234", 20, 145, 195, 30, $SS_CENTER+$SS_SUNKEN)

(The numeric string is only an example for debugging purposes.)

Can anybody point me in the right direction, please?

Thanks

CE

Link to comment
Share on other sites

  • Moderators

caseelse,

Welcome the the AutoIt forum. ;)

Just test the length of the string before displaying it: :)

#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>

$hGUI = GUICreate("Test", 500, 500)

$sData = "1234567890123456789012345678901234567890123456789012345678901234"

If StringLen($sData) > 32 Then $sData = StringMid($sData, 1, 32) & @CRLF & StringMid($sData, 33)

GUICtrlCreateLabel($sData, 20, 145, 195, 30, BitOR($SS_CENTER, $SS_SUNKEN))

GUISetState()

While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
    EndSwitch
WEnd

Note the use of BitOR to set multiple styles. You can find out why you should do it this way in the Setting Styles tutorial in the Wiki. ;)

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png 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 columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

Hi M23,

Thanks for your warm welcome and your great help.

I had been hoping that there was some style or something so that I could avoid modifying the string. However, I think I'm just going to externalize your split string function so that I can keep the original string intact and continue using it in the program.

Note the use of BitOR to set multiple styles. You can find out why you should do it this way in the Setting Styles tutorial in the Wiki. :)

That is a great tip. I have to admit that I'm just a hobby programmer and so far have only been creating very simple apps in VB6 ;) . This little program is part of my effort to migrate them to AutoIt so that I won't need the stupid VB runtimes anymore.

Anyway, you certainly helped me a lot.

Thanks again

cheers

CE

Link to comment
Share on other sites

  • Moderators

caseelse,

I'm just a hobby programmer

So am I - fun, isn't it! ;)

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png 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 columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

I have to admit that I'm just a hobby programmer and so far have only been creating very simple apps in VB6

I created some professional applications using VB4 and VB6. Don't think VB is for hobbyists only (like many others do)!

[...] to migrate them to AutoIt so that I won't need the stupid VB runtimes anymore.

This is one reason for me too to use AutoIt (or Borland C++ Builder) ;) .

A-Jay

Rule #1: Always do a backup         Rule #2: Always do a backup (backup of rule #1)

Link to comment
Share on other sites

Don't think VB is for hobbyists only (like many others do)!

Yepp, I know what great things other people can do with VB6 - just not me ;)

I tried learning C/C++ at one point and managed to get the basic concepts. However, the language soon became too abstract for me.

Basically, I'm only using programming to automate repeating tasks and speed up things on PC and Mac. So whatever I'm coding, it's always solution-oriented and the breaks in between are usually so long that at the beginning I always have to look up even simple things again because I don't quite remember the exact syntax. So, "hobby programmer" might not be the correct term, more like "necessity programmer" ;)

Anyway, it just feels great when it works in the end and the thing does exactly what I wanted it to. (With the results I can't usually impress anybody except my wife who doesn't care too much about computers :) )

Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...