Что нового

Как правильно выделить текст в Input

pvnn

Осваивающий
Сообщения
305
Репутация
32
Всем привет
Делаю выделение/снятие выделения текста в Input при помощи ControlClick.
Может есть более изящное решение?

Код:
#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>

$Form1 = GUICreate("Form1", 180, 131, -1, -1)
$Input1 = GUICtrlCreateInput("Input1", 8, 24, 150, 21)
GUICtrlSetBkColor(-1,0x29ff18)

$Button1 = GUICtrlCreateButton("Выделить", 10, 80, 75, 25)
$Button2 = GUICtrlCreateButton("Снять", 88, 80, 75, 25)

GUISetState(@SW_SHOW)


While 1
	$nMsg = GUIGetMsg()
	Switch $nMsg
		Case $GUI_EVENT_CLOSE
			Exit
		Case $Button1
			ControlClick($Form1,'',$Input1,"left", 2)

		Case $Button2
			ControlClick($Form1,'',$Input1)
	EndSwitch
WEnd
 

sngr

AutoIT Гуру
Сообщения
1,010
Репутация
408
Код:
#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>

$Form1 = GUICreate("Form1", 180, 131, -1, -1)
$Input1 = GUICtrlCreateInput("Input1", 8, 24, 150, 21)
GUICtrlSetBkColor(-1,0x29ff18)

$Button1 = GUICtrlCreateButton("Выделить", 10, 80, 75, 25)
$Button2 = GUICtrlCreateButton("Снять", 88, 80, 75, 25)

GUISetState(@SW_SHOW)


While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $Button1
;~             ControlClick($Form1,'',$Input1,"left", 2)
GUICtrlSetState($Input1,$GUI_FOCUS)

        Case $Button2
;~             ControlClick($Form1,'',$Input1)
GUICtrlSetState($Input1,$GUI_NOFOCUS)
    EndSwitch
WEnd
 
Автор
P

pvnn

Осваивающий
Сообщения
305
Репутация
32
sngr, мне нужно чтобы выделение текста снялось, а фокус остался в Input, чтобы я мог продолжить набирать текст.
Ссори что не написал об этом выше...
 

Tempo

AutoIT Гуру
Сообщения
616
Репутация
205
pvnn
Код:
#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>

$hForm1 = GUICreate("Form1", 180, 131, -1, -1)
$iInput1 = GUICtrlCreateInput("Input1", 8, 24, 150, 21)
GUICtrlSetBkColor(-1, 0x29ff18)

$iButton1 = GUICtrlCreateButton("Выделить", 10, 80, 75, 25)
$iButton2 = GUICtrlCreateButton("Снять", 88, 80, 75, 25)

GUISetState()

While 1
	Switch GUIGetMsg()
		Case $iButton1
			GUICtrlSetState($iInput1, $GUI_FOCUS)
			GUICtrlSendMsg($iInput1, $EM_SETSEL, 0, -1)
		Case $iButton2
			GUICtrlSetState($iInput1, $GUI_FOCUS)
			GUICtrlSendMsg($iInput1, $EM_SETSEL, -1, 0)
		Case $GUI_EVENT_CLOSE
			Exit
	EndSwitch
WEnd
 
Верх