Что нового

Изменение внешнего вида созданного элемента Edit

A

Alofa

Гость
Доброго времени суток.
И так задача состоит в следующем: необходимо в уже созданном элементе Edit включать/выключать так называемую опцию "перенос по словам". Все пользовались блокнотом, так что объяснения я думаю излишне.
Насколько знаю это можно регулировать стилями элемента, но вот как их изменять, а точнее заменять в уже отображаемом Edit?

На данный момент делаю так:
Код:
#include <GuiEdit.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>

Global $hGUI, $iBatt, $iEdit, $fStyle = True

$hGUI = GUICreate('', 220, 120)
_EditCreate() ; Создаем $iEdit
$iBatt = GUICtrlCreateButton('Перенос по словам', 20, 10, 180, 25)
GUISetState()

While 1
	Switch GUIGetMsg()
		Case $GUI_EVENT_CLOSE
			Exit
		Case $iBatt
			$fStyle = Not $fStyle
			_EditCreate($fStyle)
	EndSwitch
WEnd

; Создаем или пересоздаем $iEdit с разными стилями
Func _EditCreate($fStyle = True)
	Local $sEditText, $aSel
	If $iEdit Then ; Если $iEdit уже создан
		$sEditText = GUICtrlRead($iEdit)
		$aSel = _GUICtrlEdit_GetSel($iEdit)
		GUICtrlDelete($iEdit)
	Else
		$sEditText = 'Какой-то возможно многострочный текст.'
	EndIf
	$iEdit = GUICtrlCreateEdit($sEditText, 10, 50, 200, 60, (($fStyle) ? BitOR($WS_VSCROLL, $ES_AUTOVSCROLL, $ES_MULTILINE) : $GUI_SS_DEFAULT_EDIT))
	GUICtrlSetState($iEdit, $GUI_FOCUS)
	If IsArray($aSel) Then _GUICtrlEdit_SetSel($iEdit, $aSel[0], $aSel[1])
EndFunc   ;==>_EditCreate
... т.е. пересоздаю сам Edit - думаю это не совсем правильное решение.
 

InnI

AutoIT Гуру
Сообщения
4,912
Репутация
1,429
http://stackoverflow.com/questions/285587/ws-vscroll-createwindow-style-works-setwindowlong-doesnt
 
Автор
A

Alofa

Гость
Спасибо InnI, вы только подтвердили мои подозрения.
Some control styles cannot be changed after window creation. The ES_AUTOHSCROLL style (which essentially controls word wrapping) is one of them; this is stated (somewhat indirectly) by the MSDN section on Edit Control Styles. You can set the bits using SetWindowLong(), but the control will either ignore them or behave erratically.

The only way to do this cleanly is to recreate the edit control using the required styles. This is actually what Notepad does when you toggle the "Word Wrap" setting.
 
Верх