The mystery of Richedit in Delphi

zhaozj2021-02-11  214

First, how to learn the current line number with the RicheDit (or Memo) control to make a text editor, you can get the total number of minutes by accessing the linescount property, but if you want to know the line number of the cursor, it is troublesome, because Delphi is not Provide this property. To implement this editor necessary, you must call EM_ linefromchar. Try the procedure below.

First arrange a RicheDit or MEMO in the window, and a button. Write the following code in the Button's OnClick event.

VAR

Currentline: integer;

Begin

Currentline: = editor perform (em_ linefromchar, sffff, 0);

Application ssagebox (Pchar ('Current line number is' INTSTOSTR (Currentline), 'Message', MB_ IconInformation;

END;

It should be noted that the line number of the first line is zero.

Second, how to undo operation (Undo)

For Memo, implementing UNDO does not need to be programmed, as long as the PopupMenu property is empty, you can use the mouse button to activate a common operation menu, including undo, cut, copy, paste, delete and select six items. .

But unfortunately, this trick is not good for the powerful RicheDit control, and we have to design a popupMemu yourself. When you complete the "shear" and other functions such as cuttoclipboard, the "cut" is successfully completed, and then it will be unavailable that the undo or Cancel is not found to perform "revoke".

At this point you need to do this:

Richedit1 perform (em_undo, 0,0);

You should also check if you are allowed to undo, thereby opening or closing the "Undo" item in the pop-up menu:

Undo1enabled: = richeditperform (em_canundo, 0, 0) <> 0;

The above program is debugged in Delphi3

转载请注明原文地址:https://www.9cbs.com/read-4222.html

New Post(0)