Главная страница
    Top.Mail.Ru    Яндекс.Метрика
Форум: "Компоненты";
Текущий архив: 2007.02.04;
Скачать: [xml.tar.bz2];

Вниз

компонент владельцем которого является 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;
Скачать: [xml.tar.bz2];

Наверх





Память: 0.45 MB
Время: 0.038 c
3-1163601062
Patrick
2006-11-15 17:31
2007.02.04
Утилита RMAN


2-1168931007
Alex_06
2007-01-16 10:03
2007.02.04
Создание програмно пунктов основного меню


2-1169105268
s
2007-01-18 10:27
2007.02.04
PChar


15-1168848855
ocean
2007-01-15 11:14
2007.02.04
С прошедшим Старым НГ!


15-1169018219
vajo
2007-01-17 10:16
2007.02.04
Программа для диспетчера такси





Afrikaans Albanian Arabic Armenian Azerbaijani Basque Belarusian Bulgarian Catalan Chinese (Simplified) Chinese (Traditional) Croatian Czech Danish Dutch English Estonian Filipino Finnish French
Galician Georgian German Greek Haitian Creole Hebrew Hindi Hungarian Icelandic Indonesian Irish Italian Japanese Korean Latvian Lithuanian Macedonian Malay Maltese Norwegian
Persian Polish Portuguese Romanian Russian Serbian Slovak Slovenian Spanish Swahili Swedish Thai Turkish Ukrainian Urdu Vietnamese Welsh Yiddish Bengali Bosnian
Cebuano Esperanto Gujarati Hausa Hmong Igbo Javanese Kannada Khmer Lao Latin Maori Marathi Mongolian Nepali Punjabi Somali Tamil Telugu Yoruba
Zulu
Английский Французский Немецкий Итальянский Португальский Русский Испанский