您的位置:首页 > 其它

输入“\”或“.”的时候弹出选择对话框,让你选择?

2004-04-16 13:15 288 查看
unit Unit1;

interface

uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls;

type
TForm1 = class(TForm)
Memo1: TMemo;
ListBox1: TListBox;
procedure Memo1KeyPress(Sender: TObject; var Key: Char);
procedure ListBox1DblClick(Sender: TObject);
procedure Memo1MouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;

var
Form1: TForm1;

implementation

{$R *.DFM}

procedure TForm1.Memo1KeyPress(Sender: TObject; var Key: Char);
const
cInfo = ['/', '.'];
var
cPos: TPoint;
i: integer;
cText: String;
begin
GetCaretPos(cPos);
if Key in cInfo then
begin
for i := 0 to ListBox1.Items.Count-1 do
begin
cText := ListBox1.Items[i];
if cText[1] = Key then
begin
ListBox1.ItemIndex := i;
Break;
end;
end;
ListBox1.Visible := True;
ListBox1.Left := TMemo(Sender).Left+cPos.x;
ListBox1.Top := TMemo(Sender).Top+cPos.y+15;
end else
begin
ListBox1.Visible := False;
end;
end;

procedure TForm1.ListBox1DblClick(Sender: TObject);
begin
Memo1.Text := Copy(Memo1.Text, 0, Length(Memo1.Text)-1);
Memo1.Text := Memo1.Text+ListBox1.Items[ListBox1.ItemIndex];
ListBox1.Visible := False;
Memo1.SetFocus;
Memo1.SelStart := Length(Memo1.Text);
end;

procedure TForm1.Memo1MouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
begin
ListBox1.Visible := False;
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
ListBox1.Visible := False;
end;

end.
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐