유돌이

calendar

1 2
3 4 5 6 7 8 9
10 11 12 13 14 15 16
17 18 19 20 21 22 23
24 25 26 27 28 29 30

Notice

2010. 1. 11. 14:32 델파이

간단한 예제로 만들어 봤습니다.

 

참고하세요.

 

unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, Grids, JvExGrids, JvStringGrid;

type
  TForm1 = class(TForm)
    JvStringGrid1: TJvStringGrid;
    Button1: TButton;
    Memo1: TMemo;
    procedure Button1Click(Sender: TObject);
  private
    { Private declarations }
    procedure CheckBoxKeyUp(Sender: TObject; var Key: Word; Shift: TShiftState);
    procedure CheckBoxMouseUp(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: integer);
    procedure OnClickEx(Sender: TObject);
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);
var
  r : TRect;
  i, j: integer;

begin
  i := 1;
  for j:=1 to JvStringGrid1.RowCount - 1 do
  begin
    JvStringGrid1.Objects[i, j] := TCheckBox.Create(JvStringGrid1);

    with TCheckBox(JvStringGrid1.Objects[i, j]) do
    begin
      OnKeyUp   := CheckBoxKeyUp;
      OnMouseUp := CheckBoxMouseUp;
      Tag    := j;
      Hint   := IntToStr(i);
      Parent := JvStringGrid1;
      r := JvStringGrid1.CellRect(i, j);
      BoundsRect := r;
      Top := r.Top;
      Width := r.Right - r.Left - 25;
      Left := r.Left + 25;
      Height := r.Bottom - r.Top;
      Checked := False;
      Caption := '';
    end;
  end;
end;

procedure TForm1.CheckBoxMouseUp(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: integer);
begin
  if not TCheckBox(Sender).Checked then
  begin
    JvStringGrid1.Row := TCheckBox(Sender).Tag;
    JvStringGrid1.Col := StrToInt(TCheckBox(Sender).Hint);
    JvStringGrid1.Cells[JvStringGrid1.ColCount -1, JvStringGrid1.Row] := 'False';
  end else begin
    JvStringGrid1.Row := TCheckBox(Sender).Tag;
    JvStringGrid1.Col := StrToInt(TCheckBox(Sender).Hint);
    JvStringGrid1.Cells[JvStringGrid1.ColCount -1, JvStringGrid1.Row] := 'True';
    OnClickEx(JvStringGrid1);
  end;
end;

procedure TForm1.CheckBoxKeyUp(Sender: TObject; var Key: Word; Shift: TShiftState);
begin
  if Key <> VK_SPACE then
  begin
    Exit;
  end else if not TCheckBox(Sender).Checked then
  begin
    Exit;
  end else begin
    JvStringGrid1.Row := TCheckBox(Sender).Tag;
    JvStringGrid1.Col := StrToInt(TCheckBox(Sender).Hint);
    OnClickEx(JvStringGrid1);
  end;
end;

procedure TForm1.OnClickEx(Sender: TObject);
begin
  Memo1.Lines.Add('ROW: ' + IntToStr(JvStringGrid1.Row));
end;

end.


'델파이' 카테고리의 다른 글

실행프로그램(task,태스크) 죽이기  (0) 2010.01.11
한영 변환 방법  (0) 2010.01.11
중복 실행 방지 (Mutex)  (0) 2009.06.26
Caps Lock 체크 하는 방법  (0) 2009.06.26
현재 날짜 구하는 함수  (0) 2009.06.26
posted by 유돌이