title: How to fill cell of a string grid using custom color?
body: <p>I am trying to write custom date picker(calendar). The dates will be displayed on the stringgrid. I am trying to fill the clicked cell with a custom color and make that selected celltext bold.</p>
  
  <p>Here is my code: </p>
  
  <pre><code>    type
        TStringGrid = Class(Vcl.Grids.TStringGrid)
        private
          FHideFocusRect: Boolean;
        protected
           Procedure Paint;override;
        public
           Property HideFocusRect:Boolean Read FHideFocusRect Write FHideFocusRect;
        End;
  
  
      TfrmNepaliCalendar = class(TForm)
      ...
      ...
      ...
      end;
  
  
      procedure TfrmNepaliCalendar.StringGridDrawCell(Sender: TObject; ACol, ARow: Integer;
        Rect: TRect; State: TGridDrawState);
      begin
         if gdSelected in State then begin
          StringGrid.Canvas.Brush.Color := $00940A4B;
          StringGrid.Canvas.FillRect(Rect);
  
          StringGrid.Canvas.Font.Style := [fsBold];
          StringGrid.Canvas.Font.Color := clHighlightText;
          StringGrid.Canvas.TextOut(Rect.Left + 3, Rect.Top + 5, StringGrid.Cells[ACol,ARow]);
  
          StringGrid.HideFocusRect := True;
        end;
      end;
  
  
  { TStringGrid }
  
  procedure TStringGrid.Paint;
  var
    LRect: TRect;
  begin
    inherited;
    if HideFocusRect then begin
      LRect := CellRect(Col,Row);
      if DrawingStyle = gdsThemed then InflateRect(LRect,-1,-1);
  
      DrawFocusrect(Canvas.Handle,LRect)
    end;
  end;
  </code></pre>
  
  <p>The output, I am getting:</p>
  
  <p><a href="https://i.stack.imgur.com/mxGYq.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/mxGYq.png" alt="When clicked on cell containing no text"></a></p>
  
  <p><a href="https://i.stack.imgur.com/0qQDw.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/0qQDw.png" alt="When clicked, the background is clipped from left"></a></p>
  
  <p>Problem #1: I need to hide that unwanted rectangle appearing as border for the selected cell</p>
  
  <p>Problem #2: Avoid the cell background clipping</p>