Hi,
You can use "Text Object Model" technology
---------------------------------------------
More information:
MSDN Library under:
User Interface Design and Development
/ Windows Controls
/ Individual Control Information
/ Rich Edit Controls
/ Messages
and (or)
/ Text Object Model
/ Interfaces
/ ITextRange
---------------------------------------------
Used Interfaces:
ITextDocument,
ITextRange.
both defined in RICHED20.dll
(C:\WINDOWS\System32\RICHED20.dll)
From VS Studio IDE :
Project / Add Reference / (tab) COM
add
"tom"
---------------------------------------------
I have this tested with success in Delphi only
From my program /Delphi, sorry, but it is relativ simple/:
///////////////////////////////////////////////////////////////////////////
//--- function for retrieving connection with TOM
function TForm1.GetTextDocumentAndRange(const RichEdit1HWND:THandle;
var RichEditOle:IUnknown; var pDoc:ITextDocument;
var r:ITextRange):Boolean;
begin
// RichEdit1HWND this is hwnd (window handle) of my RichEdit1 component
if (SendMessage( RichEdit1HWND, EM_GETOLEINTERFACE, 0,
Longint(@RichEditOle) ) <> 0) then
if (RichEditOle<>nil) and
(RichEditOle.QueryInterface(IID_ITextDocument, pDoc) = 0) then
begin
r:=pDoc.Range(0,0);
result:=r<>nil;
end;
end;
// IID_ITextDocument -> GUID constant from tom_tlb.pas - generated from
delphi by importing tom
// IID_ITextDocument has value: {8CC497C0-A1DF-11CE-8098-00AA0047BE5D}
////////////////////////////////////////////////////////////////////////////
//
From preceding function you have r as ITextRange
ITextRange serve as "hidden" selection
Now You can use functions as:
r.FindText()
r.Move()
r.MoveEnd()
...
r.MoveStart()
...
r.collapse
r.copy
r.paste
...
...
r.Start = .. // Begin of selection - but this is only virtually selected
r.End = .. // End of selection
// and more - for retrieving TextRange
// and HIGHLIGHTING selection / word :
// changing font color
r.Font.ForeColor =
// changing style
r.Font.Bold = true / false
and so on (see MSDN Lib please)
Warning : at end you have to free r and pDoc
-----
Miro
"Catherine Jones" <no*@moreply.com> píąe v diskusním příspěvku
news:u0**************@TK2MSFTNGP10.phx.gbl...
Hi all,
We are into the development of an application in C#. In one of the module
we are using RichEdit control as text editor. This text editor is resposible
for highlighting certain keywords. After parsing the text we are using the
following methods for setting the color of the text.
RichText.Select(int startIndex, int length) &
RichText.SelectionColor = Color.Red
This is working fine. But while loading a file of 10000 lines, this color
setting is taking almost 15mints, which is not at all desiarable. Is there
any better way to do this. The file format is ASCII and we don't want to
use rtf format.
We are using .Net 1.1.
We have found that for selecting text, SendCommand API with command ID
EM_SETSEL is much faster.
But still we are missing a proper solution for changing the font color of
selected text. Currently we are
using the method "SelectionColor" which is very slow. Could you give an
alternative solution for this issue.
Thanx in advance.