设置(第一)当前选择(或没有选择时的插入点所在段落)的属性
#Include <GuiRichEdit.au3>
_GUICtrlRichEdit_SetParaAttributes($hWnd, $sStatesAndAtts)
$hWnd | 控件句柄 |
$sStatesAndAtts | 返回由分号";"分隔的字符串组. 每组包括: 第一个字符 - 状态: + - 打开属性 - - 关闭属性 "fpg" - 强制这个/这些段落到新页面(初始关闭) "hyp" - 自动断字(最初的) "kpt" - 保持这个/这些段落在同一页面上(最初关闭) "kpn" - 保持这个/这些段落和下一段落同一页面上(最初关闭) "pwo" - 防止半行或孤行,即避免段落页面上出现一个单行(最初关闭) |
"r2l" - 显示文本使用从右到左的阅读顺序(刚开始关闭) "row" - 段落为表格行(初始关闭) "sbs" - 显示段落并排(刚开始关闭) "sln" - 隐藏文档中的行号或带行号的片段(初始关闭) |
成功: | 返回 True |
失败: | 返回 False设置@error |
@error: | 101 - $hWnd 参数值不是句柄 |
1021 - $sStatesAndAtts 状态字符无效. 它在 @extended | |
1022 - $sStatesAndAtts 属性缩写无效. 它在 @extended | |
1023 - $sStatesAndAtts 字符长度无效 |
在MSDN中搜索
#include <GuiRichEdit.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
Global $lblMsg, $hRichEdit
Main()
Func Main()
Local $hGui, $iMsg, $btnNext, $iStep = 0
$hGui = GUICreate("Example (" & StringTrimRight(@ScriptName, 4) & ")", 320, 350, -1, -1)
$hRichEdit = _GUICtrlRichEdit_Create($hGui, "This is a test.", 10, 10, 300, 220, _
BitOR($ES_MULTILINE, $WS_VSCROLL, $ES_AUTOVSCROLL))
$lblMsg = GUICtrlCreateLabel("", 10, 235, 300, 60)
$btnNext = GUICtrlCreateButton("Next", 270, 310, 40, 30)
GUISetState()
_GUICtrlRichEdit_AppendText($hRichEdit, "First paragraph")
Report("First paragraph: default attributes")
While True
$iMsg = GUIGetMsg()
Select
Case $iMsg = $GUI_EVENT_CLOSE
_GUICtrlRichEdit_Destroy($hRichEdit) ; 除非脚本崩溃才需要
;~ GUIDelete() ; 同样行
Exit
Case $iMsg = $btnNext
$iStep += 1
Switch $iStep
Case 1
_GUICtrlRichEdit_AppendText($hRichEdit, @CR & "Second paragraph")
_GUICtrlRichEdit_SetParaAttributes($hRichEdit, "-hyp")
Report("Second paragraph: hyphenation off")
Case 2
_GUICtrlRichEdit_SetSel($hRichEdit, 10, -1)
_GUICtrlRichEdit_SetParaAttributes($hRichEdit, "-hyp;+fpg;+kpn")
Report("Attributes of first paragraph in selection")
Case 3
; Stream all text to the Desktop so you can look at attributes in Word
_GUICtrlRichEdit_Deselect($hRichEdit)
_GUICtrlRichEdit_StreamToFile($hRichEdit, @DesktopDir & "\gcre.rtf")
GUICtrlSetState($btnNext, $GUI_DISABLE)
EndSwitch
EndSelect
WEnd
EndFunc ;==>Main
Func Report($sMsg)
$sMsg = $sMsg & @CR & @CR & "Get function returns " & @CR & _GUICtrlRichEdit_GetParaAttributes($hRichEdit)
GUICtrlSetData($lblMsg, $sMsg)
ControlFocus($hRichEdit, "", "")
EndFunc ;==>Report