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

Вниз

CheckBox в Cell e StringGrid a   Найти похожие ветки 

 
Yaro ©   (2002-08-30 09:45) [0]

как сделать сабж?

Заранее благодарен!


 
MBo ©   (2002-08-30 09:51) [1]

поищи по форуму или в архиве. Был мой пример с настоящими CheckBox и от Бурундук с нарисованными (экономит ресурсы)


 
Yaro ©   (2002-08-30 09:58) [2]

Ключевое слово?


 
Yaro ©   (2002-08-30 10:00) [3]

Поиск тупой!!! Только по теме ищет... MBo, название темы вспомнить не можешь?


 
Johnny Smith   (2002-08-30 10:02) [4]

Используй DrawFrameControl
Пример:

dc:HDC;
s:string;
begin
dc:=Grid.Canvas.Handle;
if (ACol=3) and (ARow>0)
then
with Grid.Canvas do
begin
FillRect( Rect );
if Grid.Cells[ACol,ARow]="1" then
DrawFrameControl(dc,Rect, DFC_BUTTON , DFCS_CHECKED)
else
DrawFrameControl(dc,Rect ,DFC_BUTTON , DFCS_BUTTONCHECK)
end;
end;



 
MBo ©   (2002-08-30 10:10) [5]

CheckBox in StringGrid
(13.06.02)


 
Yaro ©   (2002-08-30 10:41) [6]

MBo -> В архивах (за это число) скачал фалик - перерыл, Result := nil;
Что делать?
Johnny Smith -> Кинул в Paint - нифига не пашет :(


 
MBo ©   (2002-08-30 10:43) [7]

MBo © (13.06.02 15:28)
SG1 - StringGrid

procedure TForm1.FormCreate(Sender: TObject);
var cb:TCheckBox;
i:integer;
begin
for i:=1 to SG1.RowCount-1 do begin
cb:=TCheckBox.Create(self);
cb.Parent:=self;
cb.width:=12;
cb.tag:=I;
cb.Caption:="";
cb.color:=SG1.Color;
cb.Visible:=(i in [SG1.TopRow..SG1.TopRow+SG1.VisibleRowCount-1]);
cb.onClick:=CheckBox1Click;
SG1.Cols[3].Objects[i]:=cb;
end;
end;

procedure TForm1.CheckBox1Click(Sender: TObject);
begin
if TCheckBox(Sender).Checked then
Sg1.Cells[3,TCheckBox(Sender).Tag]:="Ку-Ку"
else
Sg1.Cells[3,TCheckBox(Sender).Tag]:="Тссс...";
end;


procedure TForm1.SG1DrawCell(Sender: TObject; ACol, ARow: Integer;
Rect: TRect; State: TGridDrawState);
begin
if (ACol=3) and (ARow>0) then begin
TCheckBox(SG1.Cols[3].Objects[ARow]).top:=SG1.top+Rect.Top+5;
TCheckBox(SG1.Cols[3].Objects[ARow]).left:=SG1.left+Rect.right-12;
end;
end;

procedure TForm1.SG1TopLeftChanged(Sender: TObject);
var i:integer;
begin
for i:=1 to SG1.RowCount-1 do
TCheckBox(SG1.Cols[3].Objects[i]).Visible:=
(SG1.LeftCol<=3) and (i in [SG1.TopRow..SG1.TopRow+SG1.VisibleRowCount-1]);
end;





--------------------------------------------------------------------------------
Бурундук (13.06.02 18:36)
Вариант с рисованием рисованием чекбоксов:
(Мне лично он больше нравится)

const
CheckBoxCol = 2;
imgChecked = 0;

{---------------------------------------------------------------}
function GetCheckBoxRect(CellRect: TRect): TRect;
begin
Result := Classes.Rect(0, 0, 16, 16);
OffSetRect(Result, CellRect.Left + 4, CellRect.Top + 4);
end;

function CheckBoxValue(ACol, ARow: Integer): Boolean;
begin
Result := Form1.SGrid.Cells[ACol, ARow] = "True";
end;

function SwitchCheckBox(ACol, ARow: Integer): TRect;
begin
with Form1.SGrid do
if Cells[Col, Row] = "True" then Cells[Col, Row] := "False"
else Cells[Col, Row] := "True";
end;
{---------------------------------------------------------------}

procedure TForm1.FormCreate(Sender: TObject);
begin
SGrid.DefaultDrawing := False;
end;

procedure TForm1.SGridDrawCell(Sender: TObject; ACol, ARow: Integer;
Rect: TRect; State: TGridDrawState);
var CbRect: TRect;
begin
with Sender as TStringGrid do
begin
Canvas.Font.Color := clBlack;
if (gdFixed in State) then
Canvas.Brush.Color := clBtnFace
else if (gdSelected in State) and (not (gdFocused in State)) then
begin
Canvas.Brush.Color := clHighlight;
Canvas.Font.Color := clWhite;
end else
Canvas.Brush.Color := Color;

Canvas.FillRect(Rect);

if (ACol = CheckBoxCol)and(ARow >= FixedRows) then
begin
// CheckBox
CbRect := GetCheckBoxRect(Rect);

Canvas.Brush.Color := Color;
Canvas.FillRect(CbRect);
DrawEdge(Canvas.Handle, CbRect, EDGE_SUNKEN, BF_RECT);

if CheckBoxValue(ACol, ARow) then
begin
Canvas.Pen.Width := 2;
Canvas.Pen.Color := clBlack;
Canvas.MoveTo(CbRect.Left+2, CbRect.Top+6);
Canvas.LineTo( (CbRect.Left + CbRect.Right-2) div 2, CbRect.Bottom-5);
Canvas.LineTo(CbRect.Right-3, CbRect.Top+5);
InflateRect(CbRect, -2, -2);
Canvas.FrameRect(CbRect);
// Вместо этого можно хранить изображение галочки в ImageList
// ImgList.Draw(Canvas, CbRect.Left, CbRect.Top, imgChecked);
end;
end else
begin
// Text
Canvas.TextRect(Rect, Rect.Left+2, Rect.Top+2, Cells[ACol, ARow]);
end;
if gdFixed in State then DrawEdge(Canvas.Handle, Rect, BDR_RAISEDINNER, BF_RECT);
if (gdFocused in State) then Canvas.DrawFocusRect(Rect);
end;
end;

procedure TForm1.SGridMouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
var
DownCol, DownRow: Integer;
Rect, CbRect: TRect;
begin
with Sender as TStringGrid do
begin
MouseToCell(X, Y, DownCol, DownRow);

if (DownCol = CheckBoxCol)and(DownRow >= FixedRows) then
begin
Rect := CellRect(DownCol, DownRow);
CbRect := GetCheckBoxRect(Rect);
if PtInRect(CbRect, Point(X, Y)) then SwitchCheckBox(DownCol, DownRow);
end;
end;
end;

procedure TForm1.SGridSelectCell(Sender: TObject; ACol, ARow: Integer;
var CanSelect: Boolean);
begin
with Sender as TStringGrid do
if ACol = CheckBoxCol then Options := Options - [goEditing]
else Options := Options + [goEditing];
end;

procedure TForm1.SGridKeyPress(Sender: TObject; var Key: Char);
begin
with Sender as TStringGrid do
if (Key = " ") and (Col = CheckBoxCol)and(Row >= FixedRows) then
SwitchCheckBox(Col, Row);
end;




 
Yaro ©   (2002-08-30 10:46) [8]

Есть, работает! Спасибо!
Остальсь только с событиями помучаться...
(А всавить Делфийский контрол никак нельзя?)


 
Yaro ©   (2002-08-30 10:52) [9]

Пердыдущее - для "Johnny Smith"
Настоящее - для MBo:
Буду юзать Бурундука (проще и быстрее).
Почему проще? Дело в том, что StringGrid - не StringGrid, а потомок от него... Я прорисовкой сам руковожу (цвета, стили и все такое)... Теперь и ЧекБох будет :)



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

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

Наверх




Память: 0.49 MB
Время: 0.017 c
1-35715
$HiC0
2002-09-02 18:48
2002.09.12
Передача двумерного массива методу объекта...


1-35728
Ahmad
2002-09-02 23:45
2002.09.12
*.log, каким образом?


4-35956
Nils
2002-07-21 17:58
2002.09.12
Движение курсора мыши


7-35923
anton_private
2002-06-07 15:57
2002.09.12
Как зарегистрить ActiveX компонет в runtime?


1-35756
Krann
2002-08-30 16:24
2002.09.12
Reg.WriteBool в Win2k