![]() |
|
|
|||||||
| Регистрация | << Правила форума >> | FAQ | Пользователи | Календарь | Поиск | Сообщения за сегодня | Все разделы прочитаны |
![]() |
|
|
Опции темы | Поиск в этой теме | Опции просмотра |
|
#1
|
||||
|
||||
|
Подскажите пожалуйста как добавить ColorBox в StringGrid как в delphi в окне ObjectInspector?
или нужно работать с другим компонентом? |
|
#2
|
|||
|
|||
|
способов много:
1 мона разместить кнопку в StringGrid и по нажатию сгенерировать вызов окна TColorDialog 2. мона сгенерировать это событие....StringGrid.OnClick |
|
#3
|
||||
|
||||
|
а сам colorbox разместить нельзя?
![]() |
|
#4
|
||||
|
||||
|
Код:
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ExtCtrls, Grids, DBGrids;
type
TForm1 = class(TForm)
StringGrid1: TStringGrid;
ColorBox1: TColorBox;
procedure StringGrid1DrawCell(Sender: TObject; ACol, ARow: Integer;
Rect: TRect; State: TGridDrawState);
procedure StringGrid1SelectCell(Sender: TObject; ACol, ARow: Integer;
var CanSelect: Boolean);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
uses Types;
{$R *.dfm}
procedure TForm1.StringGrid1DrawCell(Sender: TObject; ACol, ARow: Integer;
Rect: TRect; State: TGridDrawState);
begin
if gdFocused in State then
begin
if ACol=2 then
begin
ColorBox1.Parent:=Self;
ColorBox1.Left:=Rect.Left+StringGrid1.Left+2;
ColorBox1.Top:=Rect.Top+StringGrid1.Top+2;
ColorBox1.Width:=Rect.Right-Rect.Left;
ColorBox1.Visible:=True;
end;
end;
end;
procedure TForm1.StringGrid1SelectCell(Sender: TObject; ACol,
ARow: Integer; var CanSelect: Boolean);
begin
ColorBox1.Visible:=False;
end;
end. |
|
#5
|
||||
|
||||
|
Спасибо!
подстроил код под себя:Код:
procedure TForm1.StringGrid1DrawCell(Sender: TObject; ACol, ARow: Integer;
Rect: TRect; State: TGridDrawState);
begin
if (ACol=2) and (ARow=2) then
begin
ColorBox1.Parent:=Self;
ColorBox1.Left:=Rect.Left+StringGrid1.Left+2;
ColorBox1.Top:=Rect.Top+StringGrid1.Top+2;
ColorBox1.Width:=Rect.Right-Rect.Left;
ColorBox1.Visible:=True;
end;
end;
end. |