Delphi 之 列表框组件(TListBox)

  TListBox组件属性

AutoComplete

  设置是否将焦点移到用户键盘输入选项上

BorderStyle

  设置组件是否有边框

Canvas

  提供一个绘图面板。

Columns

  指定列表框的可见列数

Count

  获得列表框的组件选项数

ExtendedSelect

  是否可以在列表框中选取一个范围的选项

IntegralHeight

  设置列表框是否部分显示那些显示不全的选项

ItemHeight

  设置列表框的高度

Items

  设置列表框的所有选项

MultiSelect

  是否使用多项选择功能

ScrollWidth

  指定列表框的宽度

SeltCount

  返回当前选项中的总数

Sorted

  设置列表框选项释放按字母排序

Style

  设置列表框的风格

TabWidth

  设置Tab的宽度

TopIndex

  设置选项中顶端的索引编号

示例:自动获取列表框中的组件焦点

procedure TForm1.Edit1KeyUp(Sender: TObject; var Key: Word;
  Shift: TShiftState);
var
  i:Integer;
begin
   for i:= 1 to Length(Trim(Edit1.text))do
    SendMessage(ListBox1.Handle,WM_CHAR,Integer(Edit1.Text[i]),0);
  SendMessage(ListBox1.Handle,WM_CHAR,Integer(Key),0);
end;
end.

示例 用Canvas属性绘图

procedure TForm1.ListBox1DrawItem(Control: TWinControl; Index: Integer;
  Rect: TRect; State: TOwnerDrawState);
var
  i:integer;
begin
  with Control as TListBox do
  begin
    Canvas.FrameRect(Clientrect);
    if odSelected in State then
    begin
      Canvas.Brush.Color:=clRed;
      Canvas.RoundRect(Rect.Left,Rect.Top,Rect.Right,Rect.Bottom,8,15);
      setBkMode(Canvas.Handle,TRANSPARENT    );
      Canvas.TextOut((Rect.right-Rect.Left) div 2,Rect.Top,Items.Strings[Index]);
    end
    else
    begin
      Canvas.Brush.Color:=clSkyBlue;
      Canvas.RoundRect(Rect.Left,Rect.Top,Rect.Right,Rect.Bottom,15,15);
      Canvas.TextRect(Rect,Rect.Left,Rect.Top,Items.Strings[Index]);
    end;
  end;
end;


end.

示例 模糊查找文字

procedure TForm1.Edit1Change(Sender: TObject);
var
  LIndex:Integer;
begin
  LIndex:=SendMessage(ListBox1.Handle,LB_SELECTSTRING,-1,LongInt(Edit1.Text));
end;

end.

 

转载于:https://www.cnblogs.com/delphi2014/p/4028632.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值