delphi 在 ListBox 中放置一��可�� item 的 TEdit �M件


本文整理自网络,侵删。

  
type
   TForm1 = class(TForm)
     ...
   private
     ListEdit : TEdit;
     procedure ListEditKeyPress(Sender: TObject; var Key: Char) ;
   end;


//create the TEdit and make ListBox its parent
procedure TForm1.FormCreate(Sender: TObject) ;
begin
   ListEdit := TEdit.Create(self) ;
   ListEdit.Visible := false;
   ListEdit.Ctl3D := false;
   ListEdit.BorderStyle := bsNone;
   ListEdit.Parent := ListBox1;
   ListEdit.Width := ListBox1.ClientWidth;
   ListEdit.OnKeyPress := ListEditKeyPress;
end;

//ListView Item selected - position the Edit
procedure TForm1.ListBox1Click(Sender: TObject) ;
var
   ii : integer;
   lRect: TRect;
begin
   ii := ListBox1.ItemIndex;
   if ii = -1 then exit;

   lRect := ListBox1.ItemRect(ii) ;
   ListEdit.Top := lRect.Top + 1;
   ListEdit.Left := lRect.Left + 1;
   ListEdit.Height := (lRect.Bottom - lRect.Top) + 1;

   ListEdit.Text := ListBox1.Items.Strings[ii];
   ListBox1.Selected[ii] := False;

   ListEdit.Visible := True;
   ListEdit.SelectAll;
   ListEdit.SetFocus;
end;

//apply editing when enter key is pressed
procedure TForm1.ListEditKeyPress(Sender: TObject; var Key: Char) ;
var
   ii: Integer;
begin
   if Key = #13 then
   begin
     ii := ListBox1.ItemIndex;
     ListBox1.Items.Delete(ii) ;
     ListBox1.Items.Insert(ii, ListEdit.Text) ;
     ListEdit.Visible := False;
     Key := #0;
   end;
end;

//hide Edit when ListBox looses the focus
procedure TForm1.ListBox1Exit(Sender: TObject) ;
begin
   ListEdit.Visible := false;
end;

相关阅读 >>

Delphi将n个相同字符提取到左边,m个相同字符提取到右边

Delphi unix时间转换成Delphi时间

Delphi inttohexansi

Delphi 检测文件数字签名

Delphi跨平台检测网络连接状态

Delphi 学习 sql 语句 - select(8): 分组条件

Delphi superobject json操作类的基本用法

Delphi 守护进程 杀死自己的进程再重新启动自己

Delphi 在长文件名和短文件名之间转换

Delphi xe mysql数据库操作类 mysqlhelper

更多相关阅读请进入《Delphi》频道 >>



打赏

取消

感谢您的支持,我会继续努力的!

扫码支持
扫码打赏,您说多少就多少

打开支付宝扫一扫,即可进行扫码打赏哦

分享从这里开始,精彩与您同在

评论

管理员已关闭评论功能...