[AHK v2] RichEdit Class

Post your working scripts, libraries and tools
oif2003
Posts: 101
Joined: 17 Oct 2018, 11:43
GitHub: oif2003

[AHK v2] RichEdit Class

14 Nov 2018, 00:16

 tl;dr: 
    myRichEditCtrlObj := new RichEdit(parentGuiObj, OptionalOptionsString, OptionalDefaultTextorRTF)
    After that use it like a regular Edit control object


Hi,

Here's the RichEdit class I have been using. It was originally made by just me (https://github.com/AHK-just-me/Class_RichEdit) and has been modified and enhanced by many others since then. I updated it for AutoHotkey v2 and added support for a few standard Edit control properties and methods. Specifically, it now supports: OnEvent(), Focus(), and Move(). Supported events are "Change", "Focus", and "LoseFocus". As for properties, it supports Hwnd, Enabled, Focused, Name, Pos, Type, Visible, Value, and Text (equivalent to Value). Options supported at time of control creation are: +/-wrap, readonly, uppercase, lowercase, standard size/position settings (x, y, w, h), styles & exstyles (the 0x and E0x options), and a user-defined default text. The goal is to make the syntax similar to that of a regular Edit control.

Code: Select all

#singleinstance force
#include Class_RichEdit.ahk

;	It can handle RTF format
re1DefautText := 	  "{\rtf1\ansi\ansicpg1252\deff0\nouicompat{\fonttbl{\f0\fnil\fcharset0 Consolas;}}"
				. "{\colortbl `;\red255\green255\blue0;\red0\green0\blue255;}"
				. "{\*\generator Riched20 10.0.17134}\viewkind4\uc1 "
				. "\pard\cf1\highlight2\ul\b\i\lang1033 This is a RichEdit Box\par"
				. "}"
					
gui := guicreate()
gui.setfont("s10", "Consolas")
eb := gui.add("edit", "r10 w400", "This is an Edit Box")

; 	This is how you create them
; 	be sure the first argument is the gui object.  Syntax is similar to what you would use for Edit box
; 	implemented options:  +/-wrap, readonly, uppercase, lowercase,styles & exstyles
; 	(see Class_RichEdit's constructor __New())
re1 := new richedit(gui, "r10 w400", re1DefautText)
re2 := new richedit(gui, "r5 w400 readonly", "This is a read-only RichEdit Box`n")

;	These are the only supported events for .onEvent()
;	for other RichEdit specific events, see Class_RichEdit.ahk's SetEventMask()
re1.OnEvent("change", ()=>output("RichEdit content has changed.")) 
re1.OnEvent("focus", ()=>output("RichEdit has gained focus.")) 
re1.OnEvent("losefocus", ()=>output("RichEdit has lost focus.")) 

gui.show()

;	Supported properties:
;		Gui - parent gui object (the one you passed when creating this RichEdit control
;		Hwnd - the control's hwnd
;		Also supports: Enabled, Focused, Name, Pos, Type, Visible, Value, and Text (equivalent to Value)
;
;		For RTF specific features, see Class_RichEdit.ahk for usage of
;			SetFont, GetRTF, SetSel, .... etc

output("Its size and position: w" re1.pos.w " h" re1.pos.h " x" re1.pos.x " y" re1.pos.y)


output(msg) {
	global gui, re2
	re2.value .= msg "`n" ;you can also use re2.text here
	PostMessage(0x115, 7, ,re2.hwnd , "ahk_id " gui.hwnd) ;scroll to end of control
}
To see how it is used, see RichEdit_demo.ahk. You will also need to download Class_RichEdit.ahk.
https://github.com/oif2003/RichEditBox/ ... o.ahk?ts=4
https://github.com/oif2003/RichEditBox/ ... t.ahk?ts=4
credit: Just Me, majkinetor, corrupt, jballi, DigiDon, and burque505

Image

Edit: Fixed typos, formatting

Return to “Scripts and Functions”

Who is online

Users browsing this forum: robodesign and 39 guests