Q&A

  • 3번짼데 아무두 모르시나...stringgrid에서hint사용방법
안녕하세여.

스트링그리드의 각셀에 마우스를 가져갈때 각각의 셀에 대한 자세한

정보를 hint에서 뿌려주고 싶은데 잘안데네여

마우스를옮길시 전에 있던셀 정보가 사라지고 다른 셀정보가 떠야하고

hint에 여러줄이나올 수도 있거든여

그리고 hint박스는 고정인가여?

아시는분 자세히 도와주세여..

1  COMMENTS
  • Profile
    조규춘 2001.10.29 02:38
    111 wrote:

    > 안녕하세여.

    > 스트링그리드의 각셀에 마우스를 가져갈때 각각의 셀에 대한 자세한

    > 정보를 hint에서 뿌려주고 싶은데 잘안데네여

    > 마우스를옮길시 전에 있던셀 정보가 사라지고 다른 셀정보가 떠야하고

    > hint에 여러줄이나올 수도 있거든여

    > 그리고 hint박스는 고정인가여?

    > 아시는분 자세히 도와주세여..



    쩌비.. 제목이 쫌 무섭네요..^^



    저는 항상 예제와 함께 답변을... ^^



    unit Unit1;



    interface



    uses

    Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,

    Grids, StdCtrls;



    type

    TForm1 = class(TForm)

    StringGrid1: TStringGrid;

    Label1: TLabel;

    procedure FormActivate(Sender: TObject);

    procedure FormCreate(Sender: TObject);

    private

    { Private declarations }

    procedure DoShowHint(var HintStr: string; var CanShow: Boolean;

    var HintInfo: THintInfo);

    public

    { Public declarations }

    end;



    var

    Form1: TForm1;



    implementation

    {$R *.DFM}



    procedure TForm1.DoShowHint(var HintStr: string; var CanShow: Boolean;

    var HintInfo: THintInfo);

    var

    ACol,ARow: Integer;

    ARect: TRect;

    begin

    {현재 Hint가 StringGrid일때만...}

    if HintInfo.HintControl = StringGrid1 then

    begin

    with HintInfo do

    begin

    {힌트의 색의 지정}

    HintColor := clAqua;

    {셀의 위치를 구한다}

    StringGrid1.MouseToCell(CursorPos.x, CursorPos.Y, ACol, ARow);

    {셀의 범위를 구한다}

    ARect := StringGrid1.CellRect(ACol, ARow);

    {힌트의 표시 위치}

    HintPos := StringGrid1.ClientToScreen(Point(ARect.Left,ARect.Bottom));

    {힌트의 내용}

    HintStr := '이 셀은 ('+IntToStr(ACol)+', '+IntToStr(ARow)+') 입니다';

    // +#13#10+StringGrid1.Cells[ACol, Arow]; // 힌트를 두줄로 하고 싶을때...

    {힌트의 유효 범위의 설정}

    CursorRect := ARect;

    end;

    end;

    end;





    procedure TForm1.FormActivate(Sender: TObject);

    var

    i, j: Integer;

    begin

    // StrringGrid의 각 Cell에 임의의 값을 넣는다

    for i := 1 to StringGrid1.ColCount - 1 do

    StringGrid1.Cells[i, 0] := Char(Ord('A')+i-1);



    for i := 1 to StringGrid1.RowCount - 1 do

    StringGrid1.Cells[0, i] := IntToStr(i);;



    for i := 1 to StringGrid1.ColCount - 1 do

    for j := 1 to StringGrid1.RowCount - 1 do

    StringGrid1.Cells[i, j] := Format('%.0n', [i * j * 10000.0]);



    end;



    procedure TForm1.FormCreate(Sender: TObject);

    begin

    // Application.OnShowHint 이벤트 핸들러의 설정

    Application.OnShowHint := DoShowHint;

    StringGrid1.ShowHint := True;

    end;



    end.



    그럼 수고하셔요.~