unit CardView;

interface
{$I AnyLib.Inc}
uses
  Windows, Messages, SysUtils, {$IFDEF Delphi6} Variants,{$ENDIF} Classes,
  Graphics, Controls, Forms,
  Dialogs, BaseForm, AnyPrint, AnyGrids, ComCtrls, Buttons, ExtCtrls,
  ImgList,StdCtrls;

type
  TfrmCardView = class(TfrmBase)
    ImageList1: TImageList;
    procedure AnyGridChange(Sender: TObject; Row, Col: Integer);
    procedure AnyGridDrawComboItem(Control: TWinControl; Index: Integer;
      Rect: TRect; State: TOwnerDrawState);
    procedure FormCreate(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  frmCardView: TfrmCardView;                    
                                        
implementation

{$R *.dfm}

procedure TfrmCardView.AnyGridChange(Sender: TObject; Row, Col: Integer);
var
  Cell:TCellInfo;
begin
  Cell:=AnyGrid.Cells(Row,Col);
  if (Cell.Tag='Gender') then
  begin
    Cell.Graphic.Bitmap.Width:=0;
    Cell.Graphic.Bitmap.Height:=0;
    Cell.TransparentColor:=clWhite;
    if Cell.Text='Male' then
      ImageList1.GetBitmap(0,Cell.Graphic.Bitmap)
    else
      ImageList1.GetBitmap(1,Cell.Graphic.Bitmap);
  end;
end;

procedure TfrmCardView.AnyGridDrawComboItem(Control: TWinControl;
  Index: Integer; Rect: TRect; State: TOwnerDrawState);
var
  Combo:TCustomListbox;
  Flags: Longint;
  Data: String;
begin
  Combo:=TCustomListbox(Control);
  Combo.Canvas.FillRect(Rect);
  if Index < Combo.Items.Count then
  begin
    Flags := DrawTextBiDiModeFlags(DT_SINGLELINE or DT_VCENTER or DT_NOPREFIX);
    if not Combo.UseRightToLeftAlignment then
      Inc(Rect.Left, 2)
    else                        
      Dec(Rect.Right, 2);
    if (AnyGrid.SelectedCell.Tag='Gender') then
    begin
      ImageList1.Draw(Combo.Canvas,Rect.Left,Rect.Top+2,Index);
      Inc(Rect.Left, ImageList1.Width+2);
    end;
    Data := '';
    Data := Combo.Items[Index];
    DrawText(Combo.Canvas.Handle, PChar(Data), Length(Data), Rect, Flags);
  end;
end;

procedure TfrmCardView.FormCreate(Sender: TObject);
begin
  inherited;
  LayoutSection:='CardView';
end;

end.
