TListBox a RadioButton Eklemek

Yazdığınız makaleleri ve üyelerimizin işine yarayacağını düşündüğünüz kodlarınızı gönderebilirsiniz. Bu foruma soru sormayın!
Cevapla
RamazanG
Üye
Mesajlar: 73
Kayıt: 16 Tem 2010 03:38

TListBox a RadioButton Eklemek

Mesaj gönderen RamazanG »

Makale: Zarko Gajic.
Çeviri: Ramazan Gülbahar.


Resim

TListboxın MultiSelect özelliğini False yapın.
Not: Forma bir TListBox ekleyin ve items özelliğine metinler girin:

Kod: Tümünü seç

procedure TForm1.FormCreate(Sender: TObject);
begin
    ListBox1.Style := lbOwnerDrawFixed;
    ListBox1.ItemHeight := 20;
    ListBox1.OnDrawItem := ListBox1DrawItem;
end;

procedure TForm1.ListBox1DrawItem(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;
end.
Cevapla