Jump to content

Determining selection location in edit control


Recommended Posts

Please tell me how to determine the selection in an edit control. For example, if my GUI has an edit control with several lines of text typed in it, and the user were to select one of the words, then click a button to bold the selection (to throw HTML tags before and after the selection) how would I programmatically determine what is selected? Do I need to determine both the line involved and the position of the selection on the line, or what, and how? Thank you.

Link to comment
Share on other sites

#include <GuiConstants.au3>

$GUI = GuiCreate("Example")
$editStyle = BitOr($ES_MULTILINE, $ES_NOHIDESEL)
$edit = GUICtrlCreateEdit("This is sample text already provided in the edit box.", 10, 10, 200, 00, $editStyle)
$button = GUICtrlCreateButton("Bold selection", 10, 150)

GUISetState()
While 1
    $msg = GuiGetMsg()
    If $msg = $GUI_EVENT_CLOSE Then ExitLoop
    If $msg = $button Then _SetSel()
WEnd
    
Func _SetSel()
    Local $text = ControlCommand($GUI, "", $edit, "GetSelected")
    ControlCommand($GUI, "", $edit, "EditPaste", '<b>' & $text & '</b>')
EndFunc

Use Mozilla | Take a look at My Disorganized AutoIt stuff | Very very old: AutoBuilder 11 Jan 2005 prototype I need to update my sig!
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...