本帖最后由 冥界3大法王 于 2018-8-19 10:48 编辑
无费话,先来看下实现后的效果吧。
看完之后,是否心动了?
来来来,抄起我们心爱的Delphi :
procedure TForm1.Memo1DblClick(Sender: TObject);
begin
ShowMessage(Memo1.SelText); //这个弹出选中的文字内容
//后面再接查找 变色的代码就OK了,由于Memo 没有富文本属性,所以,我们换成 RichEdit控件
end;
[Delphi] 纯文本查看 复制代码 unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ComCtrls, ExtCtrls;
type
TForm1 = class(TForm)
RichEdit1: TRichEdit;
Memo1: TMemo;
Timer1: TTimer;
procedure Memo1DblClick(Sender: TObject);
procedure RichEdit1DblClick(Sender: TObject);
procedure Timer1Timer(Sender: TObject);
procedure RichEdit1MouseUp(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
i: integer;
implementation
{$R *.dfm}
procedure TForm1.Memo1DblClick(Sender: TObject);
begin
ShowMessage(Memo1.SelText);
end;
procedure TForm1.RichEdit1DblClick(Sender: TObject); //没有这样的的事件代码,所以这段落没有反应
var
M: Integer;
begin
with RichEdit1 do
begin
M := pos(RichEdit1.SelText, RichEdit1.Text);
if M > 0 then
begin
SelStart := M - 1;
SelLength := Length(RichEdit1.Text);
SetFocus;
Richedit1.SelAttributes.Color := clFuchsia;
SendMessage(self.Richedit1.Handle, EM_SCROLLCARET, 0, 0);
end;
end;
end;
procedure TForm1.Timer1Timer(Sender: TObject);
begin
i := 0;
timer1.Enabled := false;
end;
procedure TForm1.RichEdit1MouseUp(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
var
M: Integer;
begin
if i = 0 then
begin
inc(i);
timer1.Enabled := true
end
else
begin
i := 0;
begin
with RichEdit1 do
begin
M := pos(RichEdit1.SelText , RichEdit1.Text);
if M > 0 then
begin
SelStart := M - 1;
SelLength := Length(RichEdit1.Text);
SetFocus;
Richedit1.SelAttributes.Color := clFuchsia;
SendMessage(self.Richedit1.Handle, EM_SCROLLCARET, 0, 0);
end;
end;
end;
timer1.Enabled := false;
end;
end;
end.
|