[SOLVED] Fitting control to StringGrid cell lazarus / 21-General ---------------------------------------------------------------------- pcurtis · 2021-02-28 16:55 Hi All, why doesn't the control (TButton) fit the cell in a StringGrid when I do this Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i procedure TForm1.StringGrid1DrawCell(Sender: TObject; aCol, aRow: Integer; aRect: TRect;  aState: TGridDrawState);begin  if (aCol = 1) and (aRow = 2) then    Button2.SetBounds(aRect.Left, aRect.Top, aRect.Width, aRect.Height);   (Sender as TStringGrid).DefaultDrawCell(aCol, aRow, aRect, aState);end;  Its close but about 10 pixels off ---------------------------------------------------------------------- Handoko · 2021-02-28 17:26 It should be something like this: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i procedure TForm1.StringGrid1DrawCell(Sender: TObject; aCol, aRow: Integer;  aRect: TRect; aState: TGridDrawState);var  TheGrid: TStringGrid;begin  if not(Sender is TStringGrid) then Exit;  TheGrid := (Sender as TStringGrid);  if (aCol = 1) and (aRow = 2) then    Button1.SetBounds(aRect.Left + TheGrid.Left, aRect.Top + TheGrid.Top,      aRect.Width, aRect.Height);end; ---------------------------------------------------------------------- jamie · 2021-02-28 17:26 hard to say... could be borderspacing values set in the control? the control may have the wrong parent..? The control could be scrolled alittle ? ---------------------------------------------------------------------- Handoko · 2021-02-28 17:30 Not hard.  It's about the coordinate origin. The button's coordinate origin is the form's top left corner but the aRect in the event is using the grid's top left corner as its origin. ---------------------------------------------------------------------- pcurtis · 2021-02-28 17:43 Thanks