Главная страница
Top.Mail.Ru    Яндекс.Метрика
Текущий архив: 2007.02.04;
Скачать: CL | DM;

Вниз

компонент владельцем которого является TStringGrid   Найти похожие ветки 

 
KSN ©   (2006-05-16 04:53) [0]

Доброго времени суток!

Есть такой вот код


unit Unit1;

interface

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

type
 TForm1 = class(TForm)
   StringGrid1: TStringGrid;
   ComboBox1: TComboBox;
   Label1: TLabel;
   procedure StringGrid1DrawCell(Sender: TObject; ACol, ARow: Integer;
     Rect: TRect; State: TGridDrawState);
   procedure FormCreate(Sender: TObject);
 private
   { Private declarations }
 public
   { Public declarations }
 end;
const
cell_x = 2;
cell_y = 2;

var
 Form1: TForm1;
 CheckBox1: TCheckBox;

implementation

{$R *.dfm}

procedure TForm1.StringGrid1DrawCell(Sender: TObject; ACol, ARow: Integer;
 Rect: TRect; State: TGridDrawState);
var
r:trect;
begin
if(cell_x>=StringGrid1.LeftCol) and
  (cell_x<=StringGrid1.LeftCol+StringGrid1.VisibleColCount) and
  (cell_y>=StringGrid1.TopRow) and
  (cell_x<=StringGrid1.TopRow+StringGrid1.VisibleRowCount) then
    CheckBox1.Visible:=true
else
    CheckBox1.Visible:=false;

if (acol=cell_x) and (arow=cell_y) then
begin
  r:=stringgrid1.CellRect(cell_x,cell_y);
  r.Left:=r.left;
  r.right:=r.right;
  r.top:=r.top;
  r.bottom:=r.bottom;
  CheckBox1.BoundsRect:=r;
end;
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
 CheckBox1:=TCheckBox.Create(stringgrid1);
 CheckBox1.parent:=stringgrid1;
 Label1.Caption:=IntToStr(stringgrid1.ComponentCount);
 CheckBox1.Caption:="proba";
 CheckBox1.Color:=clRed;
end;


Если владелец stringgrid1 то CheckBox1 отображается некоректно,
если поменять владельца на form1 и изменить код в StringGrid1DrawCell на

  r:=stringgrid1.CellRect(cell_x,cell_y);
  r.Left:=r.left+stringgrid1.left+2;
  r.right:=r.right+stringgrid1.left+2;
  r.top:=r.top+stringgrid1.top+2;
  r.bottom:=r.bottom+stringgrid1.top+2;
  CheckBox1.BoundsRect:=r;


то CheckBox1 будет отображен так как надо

Если кто знает подскажите плиз в чем тут проблема, просидел всю ночь так и не смог разобраться :)


 
MBo ©   (2006-05-16 08:09) [1]

TControlgrid = class(TStringgrid)
private
  { Private declarations }
  Procedure WMCommand( var msg: TWMCommand ); message WM_COMMAND;
...

procedure TControlgrid.WMCommand(var msg: TWMCommand);
begin
 If EditorMode and ( msg.Ctl = InplaceEditor.Handle ) Then
   inherited
 Else
   If msg.Ctl <> 0 Then
     msg.result :=
       SendMessage( msg.ctl, CN_COMMAND,
                    TMessage(msg).wparam,
                    TMessage(msg).lparam );
end;

P.Below


 
KSN ©   (2006-05-16 20:02) [2]

Спасибо за ответ, так я и думал что с событиями какая то проблема :)
Но осталась все таки еще одна проблемка, если промотать с помошью стрелки Scrollbar-а, так что checkbox исчезает из видимости грида, а потом мотать в обратную сторону, то checkbox рисуется во всех ячейках, до самого конца


procedure TDiagramGrid.DrawCell(ACol, ARow: Integer; ARect: TRect;
 AState: TGridDrawState);
var r:TRect;
begin
 inherited;
if(cell_x>=LeftCol) and
  (cell_x<=LeftCol+VisibleColCount) and
  (cell_y>=TopRow) and
  (cell_x<=TopRow+VisibleRowCount) then
    c.Visible:=true
else
    c.Visible:=false;

if (acol=cell_x) and (arow=cell_y) then
begin
  r:=CellRect(cell_x,cell_y);
  c.BoundsRect:=r;
end;
end;

выше приведен код метода перерисовки ячейки грида, c это checkbox
cell_x, cell_y = 2

Если владелец форма, то подобных проблем нет



Страницы: 1 вся ветка

Текущий архив: 2007.02.04;
Скачать: CL | DM;

Наверх




Память: 0.47 MB
Время: 0.073 c
2-1169369909
Strate
2007-01-21 11:58
2007.02.04
Автосоздание объекта


2-1168764914
-John-Doe-
2007-01-14 11:55
2007.02.04
Прогресс бар с надписью?


4-1159092228
Psychedelic
2006-09-24 14:03
2007.02.04
Как отключить сервис ZoneAlarm?


2-1168203924
Альберт
2007-01-08 00:05
2007.02.04
проблема с dll и hook


15-1168767111
vasIzmax
2007-01-14 12:31
2007.02.04
Работа в Интернете?