IBD

Set variable portions of text Input to bold

9 posts in this topic

#1 ·  Posted

Hi All,

I've a GUI that contains a large text input, what I'm hoping I might be able to achieve is to allow users to select certain parts of the text entered & make it bold to highlight specific parts, I've set a GUICtrlSetOnEvent against a button to be selected however this obviously just changes the entire lot of text bold.

Is this possible? or am I barking up the wrong tree with this? Or should I be heading in a different direction to achieve this?

Func BoldOnOff()
 If $TextState=1 Then
 GUICtrlSetFont ($LrgInput, 8, 400, 0, "Tahoma")
 $TextState=0
ElseIf $TextState=0 Then
 GUICtrlSetFont ($LrgInput, 8, 800, 0, "Tahoma")
$TextState=1
EndIf
EndFunc

 

Any pointers would be greatly appreciated!

Thanks

IBD

Share this post


Link to post
Share on other sites



#2 ·  Posted

IBD,

Welcome to the AutoIt forums.

I am afraid that standard input or edit controls can only have styles applied to the whole content - if you need to have separate styles applied to different sections then you will have to use a RichEdit control, which is a far more complicated beast.

Perhaps you could split the required user input between separate controls so that you can apply the required style only to that element of the whole string - you would have to prevent the user from entering inappropriate data in each of the controls, but that should not be too hard to manage. Can you please provide some more detail on the required input and how you would like it styled.

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______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

 

Share this post


Link to post
Share on other sites

#3 ·  Posted

Hi Melba,

Thank you for the reply.

I thought i might have to venture down the route the richedit.... I'd also thought about breaking the text up into chunks but that wouldn't really work with the nature of the text......

....which is basically very large blocks of text based on legalities changing within a set country, the below is purely an example & there would normally be more text 'copied & pasted' then certain sections marked out in bold;

-----Example

Nanotechnology

A special tagging system

Nanotechnology - entities with a controlled geometrical size of at least one functional component below 100 nanometres in one or more dimensions susceptible of making physical, chemical or biological effects - is considered by many to be one of the key technologies of this century, with an expected market volume of EUR 1 trillion in 2015.

Nanotechnology can occur in almost any area of science and engineering: it is just as relevant to biotechnologists and physicists as it is to electrical and mechanical engineers or materials scientists. The interdisciplinary nature of the field means that anyone interested in literature on nanotechnology, especially existing patent documents, struggles to retrieve it from the databases available.

To get to grips with this new technology, the EPO introduced the "Y01N" tags to label nanotechnology.

Y01N became B82Y


Recently all patent offices worldwide started to classify nanotechnology uniformly under the International Patent Classification (IPC) system. To make this possible, a new symbol, B82Y was introduced into the IPC on 1 January 2011, building on the Y01N system that the EPO had been using to tag nanotechnology-related patent applications.

The new B82Y symbol makes it easier to retrieve relevant patent documents in this important technical area as it is now part of both the IPC and the CPC (Cooperative Patent Classification) schemes. The EPO has moved all nanotechnology documents from the Y01N area in its databases to B82Y. The Y01N codes have been discontinued.

The concordance between Y01N and B82Y is as follows:

B82Y5 =Y01N2 Nanobiotechnology or nano-medicine
B82Y10 =Y01N4 Nanotechnology for information processing, storage and transmission
B82Y15 =Y01N8 Nanotechnology for interacting, sensing and actuating
B82Y20 =Y01N10 Nanotechnology for optics
B82Y25 =Y01N12 Nanomagnetism
B82Y30 =Y01N6 Nanotechnology for materials and surface science
B82Y35 (new) Methods or apparatus for measurement or analysis of nanostructures
B82Y40 (new) Manufacture or treatment of nanostructures

----Example

As first time around any pointers in approach would be appreciated & I'll toddle off.

Cheers

IBD

 

 

 

Share this post


Link to post
Share on other sites

#4 ·  Posted

IBD,

For text chunks that size I fear you will have to use a RichEdit, I was hoping for just a single line!

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______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

 

Share this post


Link to post
Share on other sites

#5 ·  Posted

Thanks again for the reply Melba.

Afraid not! No worries I'll head off down the richedit route.... One other question before I do, will Windows hotkeys work within richedit? Ctrl+B etc etc?

 

Cheers

IBD

Share this post


Link to post
Share on other sites

#6 ·  Posted

IBD,

I have just tested for you and although standard Windows cut/copy/paste hotkeys will work those for text styling codes (bold, italic, etc) do not - you will have to do the necessary coding yourself.

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______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

 

Share this post


Link to post
Share on other sites

#7 ·  Posted

Ah not to worry, thanks for your help & advice Melba!

 

Cheers

IBD

Share this post


Link to post
Share on other sites

#8 ·  Posted

Or you could embed MS Word into your GUI.


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

#9 ·  Posted

Something like that:

 

#include <GuiConstantsEx.au3>
#include <WindowsConstants.au3>
#include <EditConstants.au3>
#include <GuiMenu.au3>
#include <Constants.au3>
#include <WinAPI.au3>

#include <GUIRichEdit.au3>

Global Enum $idBold = 1000, $idNormal

$hGUI = GUICreate("Test", 300, 200)

$Edit1 = _GUICtrlRichEdit_Create($hGUI, "", 10, 10, 280, 150, BitOR($WS_HSCROLL, $WS_VSCROLL, $ES_MULTILINE))

$hMenu = _GUICtrlMenu_CreatePopup()

_GUICtrlMenu_AddMenuItem($hMenu, "Bold", $idBold)
_GUICtrlMenu_AddMenuItem($hMenu, "Normal", $idNormal)

GUISetState()

$wProcHandle = DllCallbackRegister("_WindowProc", "ptr", "hwnd;uint;wparam;lparam")

$wProcOld = _WinAPI_SetWindowLong($Edit1, $GWL_WNDPROC, DllCallbackGetPtr($wProcHandle))

While 1
    $Msg = GUIGetMsg()
    Switch $Msg
        Case $GUI_EVENT_CLOSE
            ExitLoop
    EndSwitch
WEnd


GUIDelete($hGUI)
DllCallbackFree($wProcHandle)


Func _WindowProc($hWnd, $Msg, $wParam, $lParam)
    Switch $hWnd
        Case $Edit1
            Switch $Msg
                Case $WM_RBUTTONUP
                    If _GUICtrlRichEdit_IsTextSelected($hWnd) Then
                    _GUICtrlMenu_TrackPopupMenu($hMenu, $hWnd)
                    EndIf
                    Return 0
                Case $WM_COMMAND
                    Switch $wParam
                        Case $idBold
                            _GUICtrlRichEdit_SetCharAttributes($hWnd, "+bo")
                        Case $idNormal
                            _GUICtrlRichEdit_SetCharAttributes($hWnd, "-bo")
                    EndSwitch
            EndSwitch
    EndSwitch

    Local $aRet = DllCall("user32.dll", "int", "CallWindowProc", "ptr", $wProcOld, _
            "hwnd", $hWnd, "uint", $Msg, "wparam", $wParam, "lparam", $lParam)

    Return $aRet[0]
EndFunc   ;==>_WindowProc

 


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.

Share this post


Link to post
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