双击 高亮所有关键字
本帖最后由 冥界3大法王 于 2018-8-19 10:48 编辑无费话,先来看下实现后的效果吧。
看完之后,是否心动了?
来来来,抄起我们心爱的Delphi :
procedure TForm1.Memo1DblClick(Sender: TObject);
begin
ShowMessage(Memo1.SelText); //这个弹出选中的文字内容
//后面再接查找 变色的代码就OK了,由于Memo 没有富文本属性,所以,我们换成 RichEdit控件
end;
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.
动心了,但是论坛能用吗。{:301_984:} 可以的,但是没看懂 大神能做成.CRX插件用在浏览器中吗 @moranyuyan
http://www.cnplugins.com/zhuanti/11-highlight-chrome-plugins.html
已经有很多了 大神辛苦了~@!!~!~ 没看明白 chrome插件不错 有没有百度搜索或者谷歌搜索,直接搜索关键字高亮
这个东东很意思,感谢楼主的分享 不明觉厉系例~~!!
页:
[1]