Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

StringGrid focus rectangle!

34 views
Skip to first unread message

cOOl

unread,
Dec 21, 2003, 5:23:00 AM12/21/03
to
Hi,

Can I remove focus rectangle around the selected cell in StringGrid when
DefaultDrawing = True

Thanks.


Os2

unread,
Dec 22, 2003, 11:22:40 AM12/22/03
to
in the OnExit event:

procedure TForm1.StringGrid1Exit(Sender: TObject);
Var
Rc : TGridRect;
begin
Rc.Left := -1;
Rc.Top := -1;
Rc.Right := -1;
Rc.Bottom := -1;
StringGrid1.Selection := Rc;
end;

cOOl

unread,
Dec 22, 2003, 3:12:50 PM12/22/03
to
Hi Os2,

Your sample is cool, but I want remove dot-mark from active cell?
Thanks.


Scott

unread,
Dec 22, 2003, 3:31:13 PM12/22/03
to
Try this, redraw the cell in an ondrawcell procedure.

if gdFocused in State then
with Rect do begin
StringGrid1.Canvas.Rectangle( Left, Top, Right, Bottom);
StringGrid1.Canvas.Textout( Left+2, Top+2,
StringGrid1.Cells[ACol,ARow]);
end;

This is off the top of my head so you'll have to deal with the syntax.


cOOl

unread,
Dec 23, 2003, 2:17:10 AM12/23/03
to
Hi Scott,

Can you see a picture on Url:
http://www.nekbg.com/dot.jpg

Thanks.


Scott

unread,
Dec 23, 2003, 10:14:24 AM12/23/03
to
Sorry, I thought this intercepted the program flow after everything was
drawn. Evidently the focus square is drawn after ondrawcell. If you knew
what the variable is for cell focus you might be able to reset it here. I
think someone mentioned it in a post not too long ago.

Good luck.


Olivier Beltrami

unread,
Dec 23, 2003, 1:36:58 PM12/23/03
to
> Sorry, I thought this intercepted the program flow after everything was
> drawn. Evidently the focus square is drawn after ondrawcell.

If you use DrawFocustRect() at the end of your OnDrawCell it will draw a
focus rect that will be canceled out after the OnDrawCell when the VCL does
a DrawFocusRect() again.

Olivier


Scott

unread,
Dec 24, 2003, 7:53:18 AM12/24/03
to
If you search the NG archives you'll see this gets asked alot. So here is a
procedure which is a reasonable replacement for the default drawing. Set
default drawing to false and modify this to suit.

procedure TMiscForm.StringGrid1DrawCell(Sender: TObject;
ACol, ARow: Integer;
Rect : TRect;
State : TGridDrawState);
var SG: TStringGrid;
begin
if Sender is TStringGrid then begin
SG:= TStringGrid(Sender);
with SG.Canvas do begin
Font:= SG.Font;
Brush.Color:= SG.Color;
Brush.Style:= bsSolid;

if gdFixed in State
then begin
Brush.Color:= SG.FixedColor;
end;

if ( gdSelected in State)
and not (gdFocused in State)
then begin
Brush.Color:= clHighLight;
Font.color := clHighLightText;
end;

Pen.Color := Brush.Color;
Pen.Mode := pmCopy;
Pen.Style := psSolid;
Pen.Width := 1;
Rectangle(Rect);

if Ctl3D
and (gdFixed in State)
then begin
if goFixedVertLine in SG.Options
then begin
Pen.Color := clBtnHighLight;
MoveTo(Rect.Left, Rect.Bottom-1);
LineTo(Rect.Left, Rect.Top);
Pen.Color := clBtnShadow;
MoveTo(Rect.Right-1, Rect.Top);
if goFixedHorzLine in SG.Options
then LineTo(Rect.Right-1, Rect.Bottom)
else LineTo(Rect.Right-1, Rect.Bottom+SG.GridLineWidth);
end;
if goFixedHorzLine in SG.Options
then begin
Pen.Color := clBtnHighLight;
MoveTo(Rect.Left, Rect.Top);
LineTo(Rect.Right, Rect.Top);
Pen.Color := clBtnShadow;
if goFixedVertLine in SG.Options
then begin
MoveTo(Rect.Left+1, Rect.Bottom-1);
LineTo(Rect.Right, Rect.Bottom-1)
end else begin
MoveTo(Rect.Left, Rect.Bottom-1);
LineTo(Rect.Right+SG.GridLineWidth, Rect.Bottom-1);
end;
end;
end;

Brush.Style:= bsClear;
TextRect( Rect, Rect.Left+2, Rect.Top+2, SG.Cells[ACol,ARow]);

Brush.Style:= bsSolid;
if gdFocused in State then DrawFocusRect(Rect);
end;
end;
end;

cOOl

unread,
Dec 29, 2003, 6:12:56 AM12/29/03
to
Thank you
Merry Christmas and Happy new year !


0 new messages