Transparent stringGrid

Transparent stringGrid

Post by Bob Bedfor » Wed, 02 Jul 2003 00:23:55



I'm looking for a way to have a "transparent" stringGrid.

I've seen around this possibility, but it doesn't work.

constructor TExtendedMonthCalendar.Create(AOwner: TComponent);
begin
  inherited Create(AOwner);
  { defaults }
  ControlStyle:= ControlStyle - [csOpaque];
...

procedure TExtendedMonthCalendar.CreateParams(var Params: TCreateParams);
begin
  Inherited CreateParams(Params);
  Params.ExStyle:= Params.ExStyle or WS_EX_TRANSPARENT;
end;

procedure TExtendedMonthCalendar.SetParent(AParent: TWinControl);
begin
  inherited SetParent(AParent);
  If Parent <> Nil then
    SetWindowLong(Parent.Handle, GWL_STYLE,
       GetWindowLong(Parent.Handle, GWL_STYLE) And Not WS_ClipChildren);
end;

Procedure TExtendedMonthCalendar.Invalidate;
Var
  Rect :TRect;
Begin
  Rect:= cellrect(col,row);
  If (Parent <> Nil) and Parent.HandleAllocated then

  Else
    Inherited Invalidate;
End;

procedure TExtendedMonthCalendar.WMEraseBkGnd(var MSG: TWMEraseBkGnd);
begin
  setBkMode(msg.DC, transparent);
  MSG.Result:= 1;
end;

/***********************************

I've also seen a DrawCell override:
procedure TForm1.StringGrid1DrawCell(Sender: TObject; Col,
  Row: Longint; Rect: TRect; State: TGridDrawState);
begin
  StringGrid1.Canvas.CopyRect(Rect, Image1.Picture.Bitmap.Canvas,
    Rect);
end;
but this also doesn't work well (as the top left grid shown the top left
image instead of the actual position)