Top.Mail.Ru
Мастера DELPHI, Delphi programming community Титульная страница Поиск, карта сайта Написать письмо 
| Новости | Поиск | FAQ | Статьи | Книги | Новости VCL |
| Форумы ЧАТ | Орешник | KOL и MCK |
Форумы -» Основная («Начинающим»)/ Базы / WinAPI / Компоненты / Сети / Media / Игры / Corba и COM / KOL / FreePascal / .Net / Прочее / RSDN.ORG

« предыдущая ветвь | форум | следующая ветвь »

компонент владельцем которого является TStringGrid [D7, WinXP]


KSN ©   (2006-05-16 04:53:00) 

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

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


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 будет отображен так как надо

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


KSN   (2006-05-16 20:02:00) [1]

Спасибо за ответ, так я и думал что с событиями какая то проблема :)
Но осталась все таки еще одна проблемка, если промотать с помошью стрелки 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

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


MBo   (2006-05-16 08:09:00) [2]

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


Наверх

Титульная страница Поиск, карта сайта Написать письмо