Jump to content

Underline some words in a label


funkey
 Share

Recommended Posts

Here is my new little function to create a label where some words are underlined.

I hope someone will need this.

GUICreate('Some words in the labels are underlined', 700, 320)

_GuiCtrlCreateLabel_UnderlineWords("Some words are underlined, some are not.", 10, 10, "3;6", 20)
_GuiCtrlCreateLabel_UnderlineWords("Some words are underlined, some are not.", 10, 50, "3;6", 10)
_GuiCtrlCreateLabel_UnderlineWords("Some words are underlined, some are not.", 10, 80, "3;6", 18)

_GuiCtrlCreateLabel_UnderlineWords("Some words are underlined, some are not.", 10, 120, "3;6", 20, "Courier")
_GuiCtrlCreateLabel_UnderlineWords("Some words are underlined, some are not.", 10, 150, "1;3;6", 10, "Courier")
_GuiCtrlCreateLabel_UnderlineWords("Some words are underlined, some are not.", 10, 180, "3;6", 18, "Arial")

$aLabel = _GuiCtrlCreateLabel_UnderlineWords("Some text: Link", 10, 220, "2", 60, "Arial")

GUICtrlSetColor($aLabel[2], 0x0000ff)
GUICtrlSetCursor($aLabel[2], 0)

GUISetState()

Local $msg
Do
    Sleep(10)
 $msg = GUIGetMsg()
 If $msg = $aLabel[2] Then MsgBox(64, "_GuiCtrlCreateLabel_UnderlineWords", "Greetings from Austria!")
Until $msg = -3

Func _GuiCtrlCreateLabel_UnderlineWords($sText, $iPosX, $iPosY, $sIndex, $iFontSize = 8.5, $sFont = 'Microsoft Sans Serif')
 ;funkey 2010, 11th of June
    GUISetFont($iFontSize, 400, 0, $sFont)
    Local $aIndex = StringSplit($sIndex, ";", 2)
    Local $aText = StringSplit(StringStripWS($sText, 7), " ", 2)
    Local $hLabel[UBound($aText)]
    $hLabel[0] = GUICtrlCreateLabel($aText[0], $iPosX, $iPosY)
    Local $hGui = DllCall("user32.dll", "hwnd", "GetParent", "hwnd", GUICtrlGetHandle(-1))
    $hGui = $hGui[0]
    Local $aPos
    For $i = 1 To UBound($aText) -1
        $aPos = ControlGetPos($hGui, "", GUICtrlGetHandle(-1))
        $hLabel[$i] = GUICtrlCreateLabel($aText[$i], $iPosX + $aPos[0] + $aPos[2] - 15 + Ceiling($iFontSize / 3), $iPosY)
    Next
    For $i = 0 To UBound($aIndex) -1
        GUICtrlSetFont($hLabel[$aIndex[$i]], Default, Default, 4)
    Next
    Return $hLabel
EndFunc

Programming today is a race between software engineers striving to
build bigger and better idiot-proof programs, and the Universe
trying to produce bigger and better idiots.
So far, the Universe is winning.

Link to comment
Share on other sites

Nice.

Check out my _GUICtrlCreateTFLabel UDF.

Here is (almoust) the same example using this UDF:

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

#include "GUICtrlCreateTFLabel.au3"

GUICreate('Some words in the labels are underlined', 700, 320)

$sLabel1_Data = '<font size="20">Some words are</font> <font size="20" attrib="underlined">underlined,</font> <font size="20">some are</font> <font size="20" attrib="underlined">not.</font>'
$sLabel2_Data = '<font size="10">Some words are</font> <font size="10" attrib="underlined">underlined,</font> <font size="10">some are</font> <font size="10" attrib="underlined">not.</font>'
$sLabel3_Data = '<font size="18">Some words are</font> <font size="18" attrib="underlined">underlined,</font> <font size="18">some are</font> <font size="18" attrib="underlined">not.</font>'
$sLabel4_Data = '<font size="20" name="Courier">Some words are</font> <font size="20" name="Courier" attrib="underlined">underlined,</font> <font size="20" name="Courier">some are</font> <font size="20" name="Courier" attrib="underlined">not.</font>'
$sLabel5_Data = '<font size="10" name="Courier">Some</font> <font size="10" name="Courier" attrib="underlined">words</font> <font size="10" name="Courier">are</font> <font size="10" name="Courier" attrib="underlined">underlined,</font> <font size="10" name="Courier">some are</font> <font size="10" name="Courier" attrib="underlined">not.</font>'
$sLabel6_Data = '<font size="18" name="Arial">Some words are</font> <font size="18" name="Arial" attrib="underlined">underlined,</font> <font size="18" name="Arial">some are</font> <font size="18" name="Arial" attrib="underlined">not.</font>'
$sLabel7_Data = '<font size="60" name="Arial">Some text:</font> <font size="60" name="Arial" color="blue" attrib="underlined">Link</font>'

_GUICtrlCreateTFLabel($sLabel1_Data, 10, 10)
_GUICtrlCreateTFLabel($sLabel2_Data, 10, 50)
_GUICtrlCreateTFLabel($sLabel3_Data, 10, 80)

_GUICtrlCreateTFLabel($sLabel4_Data, 10, 120)
_GUICtrlCreateTFLabel($sLabel5_Data, 10, 150)
_GUICtrlCreateTFLabel($sLabel6_Data, 10, 180)

$nLabel = _GUICtrlCreateTFLabel($sLabel7_Data, 10, 220)
GUICtrlSetCursor($nLabel[3], 0)

GUISetState()

While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
        Case $nLabel[3]
            MsgBox(64, "_GuiCtrlCreateLabel_UnderlineWords", "Greetings from Austria!")
    EndSwitch
WEnd

 

Spoiler

Using OS: Win 7 Professional, Using AutoIt Ver(s): 3.3.6.1 / 3.3.8.1

AutoIt_Rus_Community.png AutoIt Russian Community

My Work...

Spoiler

AutoIt_Icon_small.pngProjects: ATT - Application Translate Tool {new}| BlockIt - Block files & folders {new}| SIP - Selected Image Preview {new}| SISCABMAN - SciTE Abbreviations Manager {new}| AutoIt Path Switcher | AutoIt Menu for Opera! | YouTube Download Center! | Desktop Icons Restorator | Math Tasks | KeyBoard & Mouse Cleaner | CaptureIt - Capture Images Utility | CheckFileSize Program

AutoIt_Icon_small.pngUDFs: OnAutoItErrorRegister - Handle AutoIt critical errors {new}| AutoIt Syntax Highlight {new}| Opera Library! | Winamp Library | GetFolderToMenu | Custom_InputBox()! | _FileRun UDF | _CheckInput() UDF | _GUIInputSetOnlyNumbers() UDF | _FileGetValidName() UDF | _GUICtrlCreateRadioCBox UDF | _GuiCreateGrid() | _PathSplitByRegExp() | _GUICtrlListView_MoveItems - UDF | GUICtrlSetOnHover_UDF! | _ControlTab UDF! | _MouseSetOnEvent() UDF! | _ProcessListEx - UDF | GUICtrl_SetResizing - UDF! | Mod. for _IniString UDFs | _StringStripChars UDF | _ColorIsDarkShade UDF | _ColorConvertValue UDF | _GUICtrlTab_CoverBackground | CUI_App_UDF | _IncludeScripts UDF | _AutoIt3ExecuteCode | _DragList UDF | Mod. for _ListView_Progress | _ListView_SysLink | _GenerateRandomNumbers | _BlockInputEx | _IsPressedEx | OnAutoItExit Handler | _GUICtrlCreateTFLabel UDF | WinControlSetEvent UDF | Mod. for _DirGetSizeEx UDF
 
AutoIt_Icon_small.pngExamples: 
ScreenSaver Demo - Matrix included | Gui Drag Without pause the script | _WinAttach()! | Turn Off/On Monitor | ComboBox Handler Example | Mod. for "Thinking Box" | Cool "About" Box | TasksBar Imitation Demo

Like the Projects/UDFs/Examples? Please rate the topic (up-right corner of the post header: Rating AutoIt_Rating.gif)

* === My topics === *

==================================================
My_Userbar.gif
==================================================

 

 

 

AutoIt is simple, subtle, elegant. © AutoIt Team

Link to comment
Share on other sites

You could replace

GUICtrlSetFont($hLabel[$aIndex[$i]], Default, Default, 4)

to

GUICtrlSetFont($hLabel[$aIndex[$i] - 1], Default, Default, 4)

Could solve problems. I think its easier this way. Nice UDF though :mellow:

Minesweeper

A minesweeper game created in autoit, source available.

_Mouse_UDF

An UDF for registering functions to mouse events, made in pure autoit.

2D Hitbox Editor

A 2D hitbox editor for quick creation of 2D sphere and rectangle hitboxes.

Link to comment
Share on other sites

Thanks for your comments. MrCreatoR: Your function is much more universal than mine, but it takes much more time to create a label with your string syntax. My function is simple and the syntax is simple too. And I could change the funtion to make the labels italic or striked. For colored labels there I use an old function of mine.

#include <GDIPlus.au3>

GUICreate('Colored labels by funkey', 500, 200)

_GuiCtrlCreateColoredLabel('Hello[0x0000FF] Autoitscript.com![0x00FF00] Do you like this?[0xFF0000]', 20, 20, 'Arial', 20)
_GuiCtrlCreateColoredLabel('Th[0xFF00FF]i[0x0000FF]s[0x00FFFF] is[0x00FF00] a[0xFFFF00] fir[0xFF6900]st[0x000000] color[0xFF0000] test[0x0000FF]', 20, 80, 'Times New Roman', 15)

GUISetState()

_GuiCtrlCreateColoredLabel('A[0x0000FF]n[0xFF0000]i[0x0000FF]m[0xFF0000]a[0x0000FF]t[0xFF0000]i[0x0000FF]o[0xFF0000]n[0x0000FF] :)[0x00FFFF]', 40, 130, 'Microsoft Sans Serif', 45, 6, 300)

Do
 Sleep(10)
Until GUIGetMsg() = -3

Func _GuiCtrlCreateColoredLabel($sText, $iPosX, $iPosY, $sFont = 'Microsoft Sans Serif', $iFontSize = 8.5, $iFontAttributes = 0, $iSleep = 0)
 ;Author: funkey
 Local $aTextPart = StringRegExp($sText, '.+?]', 3)
 Local $aText, $hLabel[UBound($aTextPart)], $aSize[2] = [0, 0], $iWidthOld
 For $i = 0 To UBound($aTextPart) - 1
  $aText = StringSplit(StringTrimRight($aTextPart[$i], 1), '[', 2)
  $iWidthOld += $aSize[0] - $iFontSize / 2
  $aSize = _GetTextSize($aText[0], $sFont, $iFontSize, $iFontAttributes)
  $hLabel[$i] = GUICtrlCreateLabel($aText[0], $iPosX + $iWidthOld, $iPosY, $aSize[0], $aSize[1])
  GUICtrlSetColor(-1, $aText[1])
  GUICtrlSetBkColor(-1, -2) ; $GUI_BKCOLOR_TRANSPARENT
  GUICtrlSetFont(-1, $iFontSize, 400, $iFontAttributes, $sFont)
  Sleep($iSleep)
 Next
 Return $hLabel
EndFunc   ;==>_GuiCtrlCreateColoredLabel

Func _GetTextSize($nText, $sFont = 'Microsoft Sans Serif', $iFontSize = 8.5, $iFontAttributes = 0)
 ;Author: Bugfix
 ;Modified: funkey
 Local $aSize[2] = [0,0]
 If $nText = '' Then Return SetError(1, 0, $aSize)
 _GDIPlus_Startup()
 Local $hFormat = _GDIPlus_StringFormatCreate(0)
 Local $hFamily = _GDIPlus_FontFamilyCreate($sFont)
 Local $hFont = _GDIPlus_FontCreate($hFamily, $iFontSize, $iFontAttributes, 3)
 Local $tLayout = _GDIPlus_RectFCreate(15, 171, 0, 0)
 Local $hGraphic = _GDIPlus_GraphicsCreateFromHWND(0)
 Local $aInfo = _GDIPlus_GraphicsMeasureString($hGraphic, $nText, $hFont, $tLayout, $hFormat)
 Local $iWidth = Ceiling(DllStructGetData($aInfo[0], "Width"))
 Local $iHeight = Ceiling(DllStructGetData($aInfo[0], "Height"))
 _GDIPlus_StringFormatDispose($hFormat)
 _GDIPlus_FontDispose($hFont)
 _GDIPlus_FontFamilyDispose($hFamily)
 _GDIPlus_GraphicsDispose($hGraphic)
 _GDIPlus_Shutdown()
 $aSize[0] = $iWidth
 $aSize[1] = $iHeight
 Return $aSize
EndFunc   ;==>_GetTextSize

Programming today is a race between software engineers striving to
build bigger and better idiot-proof programs, and the Universe
trying to produce bigger and better idiots.
So far, the Universe is winning.

Link to comment
Share on other sites

  • Moderators

Thanks for your comments. MrCreatoR: Your function is much more universal than mine, but it takes much more time to create a label with your string syntax. My function is simple and the syntax is simple too. And I could change the funtion to make the labels italic or striked. For colored labels there I use an old function of mine.

Err... What happens when I want to use a square bracket in my label?

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to comment
Share on other sites

Err... What happens when I want to use a square bracket in my label?

Nothing is perfect, sorry. It's just an easy function, that does what I wanted, so I never needed brackets in my labels. If you need to, then use MrCreatoR's UDF or do it label for label by hand :mellow:

Programming today is a race between software engineers striving to
build bigger and better idiot-proof programs, and the Universe
trying to produce bigger and better idiots.
So far, the Universe is winning.

Link to comment
Share on other sites

  • Moderators

Nothing is perfect, sorry. It's just an easy function, that does what I wanted, so I never needed brackets in my labels. If you need to, then use MrCreatoR's UDF or do it label for label by hand :mellow:

I wasn't criticizing you. I was pointing out an obvious error in your logic that you failed to see. Was hoping that me seeing it and asking, would give you the umph to fix it rather than make excuses or suggest that I use something else.

To be quite honest, I wouldn't use either of your methods.

Well, I might use MrCreatOr's syntax method, but I would have created a GUI that I could have edited the text visually, and from there have it spit out the string code.

Or at the very least wrote a function that I could have passed "String", "Color", "Size", "Etc" to and had it return the string I needed.

Anyway, just food for thought, if you take it as constructive criticism, maybe you can push the envelope a bit more.

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to comment
Share on other sites

Well, I might use MrCreatOr's syntax method, but I would have created a GUI that I could have edited the text visually, and from there have it spit out the string code

Very good idea, as always :mellow: . Already started to work on the visual editor for this UDF...

 

Spoiler

Using OS: Win 7 Professional, Using AutoIt Ver(s): 3.3.6.1 / 3.3.8.1

AutoIt_Rus_Community.png AutoIt Russian Community

My Work...

Spoiler

AutoIt_Icon_small.pngProjects: ATT - Application Translate Tool {new}| BlockIt - Block files & folders {new}| SIP - Selected Image Preview {new}| SISCABMAN - SciTE Abbreviations Manager {new}| AutoIt Path Switcher | AutoIt Menu for Opera! | YouTube Download Center! | Desktop Icons Restorator | Math Tasks | KeyBoard & Mouse Cleaner | CaptureIt - Capture Images Utility | CheckFileSize Program

AutoIt_Icon_small.pngUDFs: OnAutoItErrorRegister - Handle AutoIt critical errors {new}| AutoIt Syntax Highlight {new}| Opera Library! | Winamp Library | GetFolderToMenu | Custom_InputBox()! | _FileRun UDF | _CheckInput() UDF | _GUIInputSetOnlyNumbers() UDF | _FileGetValidName() UDF | _GUICtrlCreateRadioCBox UDF | _GuiCreateGrid() | _PathSplitByRegExp() | _GUICtrlListView_MoveItems - UDF | GUICtrlSetOnHover_UDF! | _ControlTab UDF! | _MouseSetOnEvent() UDF! | _ProcessListEx - UDF | GUICtrl_SetResizing - UDF! | Mod. for _IniString UDFs | _StringStripChars UDF | _ColorIsDarkShade UDF | _ColorConvertValue UDF | _GUICtrlTab_CoverBackground | CUI_App_UDF | _IncludeScripts UDF | _AutoIt3ExecuteCode | _DragList UDF | Mod. for _ListView_Progress | _ListView_SysLink | _GenerateRandomNumbers | _BlockInputEx | _IsPressedEx | OnAutoItExit Handler | _GUICtrlCreateTFLabel UDF | WinControlSetEvent UDF | Mod. for _DirGetSizeEx UDF
 
AutoIt_Icon_small.pngExamples: 
ScreenSaver Demo - Matrix included | Gui Drag Without pause the script | _WinAttach()! | Turn Off/On Monitor | ComboBox Handler Example | Mod. for "Thinking Box" | Cool "About" Box | TasksBar Imitation Demo

Like the Projects/UDFs/Examples? Please rate the topic (up-right corner of the post header: Rating AutoIt_Rating.gif)

* === My topics === *

==================================================
My_Userbar.gif
==================================================

 

 

 

AutoIt is simple, subtle, elegant. © AutoIt Team

Link to comment
Share on other sites

SmOke_N

Already started to work on the visual editor for this UDF...

And it's done! what do you think? (we probably should continue and discuss about it there :mellow:). Edited by MrCreatoR

 

Spoiler

Using OS: Win 7 Professional, Using AutoIt Ver(s): 3.3.6.1 / 3.3.8.1

AutoIt_Rus_Community.png AutoIt Russian Community

My Work...

Spoiler

AutoIt_Icon_small.pngProjects: ATT - Application Translate Tool {new}| BlockIt - Block files & folders {new}| SIP - Selected Image Preview {new}| SISCABMAN - SciTE Abbreviations Manager {new}| AutoIt Path Switcher | AutoIt Menu for Opera! | YouTube Download Center! | Desktop Icons Restorator | Math Tasks | KeyBoard & Mouse Cleaner | CaptureIt - Capture Images Utility | CheckFileSize Program

AutoIt_Icon_small.pngUDFs: OnAutoItErrorRegister - Handle AutoIt critical errors {new}| AutoIt Syntax Highlight {new}| Opera Library! | Winamp Library | GetFolderToMenu | Custom_InputBox()! | _FileRun UDF | _CheckInput() UDF | _GUIInputSetOnlyNumbers() UDF | _FileGetValidName() UDF | _GUICtrlCreateRadioCBox UDF | _GuiCreateGrid() | _PathSplitByRegExp() | _GUICtrlListView_MoveItems - UDF | GUICtrlSetOnHover_UDF! | _ControlTab UDF! | _MouseSetOnEvent() UDF! | _ProcessListEx - UDF | GUICtrl_SetResizing - UDF! | Mod. for _IniString UDFs | _StringStripChars UDF | _ColorIsDarkShade UDF | _ColorConvertValue UDF | _GUICtrlTab_CoverBackground | CUI_App_UDF | _IncludeScripts UDF | _AutoIt3ExecuteCode | _DragList UDF | Mod. for _ListView_Progress | _ListView_SysLink | _GenerateRandomNumbers | _BlockInputEx | _IsPressedEx | OnAutoItExit Handler | _GUICtrlCreateTFLabel UDF | WinControlSetEvent UDF | Mod. for _DirGetSizeEx UDF
 
AutoIt_Icon_small.pngExamples: 
ScreenSaver Demo - Matrix included | Gui Drag Without pause the script | _WinAttach()! | Turn Off/On Monitor | ComboBox Handler Example | Mod. for "Thinking Box" | Cool "About" Box | TasksBar Imitation Demo

Like the Projects/UDFs/Examples? Please rate the topic (up-right corner of the post header: Rating AutoIt_Rating.gif)

* === My topics === *

==================================================
My_Userbar.gif
==================================================

 

 

 

AutoIt is simple, subtle, elegant. © AutoIt Team

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...