您现在的位置:首页 >> VCL >> VCL >> 内容

Delphi中编写带有Radio Buttons的TListBox

时间:2011/9/3 16:23:52 点击:

  核心提示:600) this.width = 600;'>procedure TRadioListBoxForm.FormCreate(Sender: TObject) ;begin //or use Obje...

600) this.width = 600;">

procedure TRadioListBoxForm.FormCreate(Sender: TObject) ;
begin
   //or use Object Inspector to assign the
   //OnDrawItem event handler,
   //Style and ItemHeight properties...

   ListBox1.Style := lbOwnerDrawFixed;
   ListBox1.ItemHeight := 20;
   ListBox1.OnDrawItem := ListBox_DrawItem;
end;

procedure TRadioListBoxForm.ListBox_DrawItem(
   Control: TWinControl;
   Index: Integer;
   Rect: TRect;
   State: TOwnerDrawState) ;
const
   IsSelected : array[Boolean] of Integer = (DFCS_BUTTONRADIO, DFCS_BUTTONRADIO or DFCS_CHECKED) ;
var
   optionButtonRect: TRect;
   listBox : TListBox;
begin
   listBox := Control as TListBox;
   with listBox.Canvas do
   begin
     FillRect(rect) ;

     optionButtonRect.Left := rect.Left + 1;
     optionButtonRect.Right := Rect.Left + 13;
     optionButtonRect.Bottom := Rect.Bottom;
     optionButtonRect.Top := Rect.Top;

     DrawFrameControl(Handle, optionButtonRect, DFC_BUTTON, IsSelected[odSelected in State]) ;

     TextOut(15, rect.Top + 3, listBox.Items[Index]) ;
   end;
end;

Tags:编写 带有 
作者:网络 来源:转载
共有评论 0相关评论
发表我的评论
  • 大名:
  • 内容:
本类推荐
  • 没有
本类固顶
  • 没有
  • 盒子文章(www.2ccc.com) © 2022 版权所有 All Rights Reserved.
  • 沪ICP备05001939号