Canvas.Rectangle wrong [Solved] lazarus / 39-Graphics ---------------------------------------------------------------------- lainz · 2019-12-21 12:12 Hi, try this code on Windows: 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.PaintBox1Paint(Sender: TObject);begin  PaintBox1.Canvas.Pen.Width:=2;  PaintBox1.Canvas.Rectangle(0, 0, PaintBox1.Width, PaintBox1.Height);end; You will notice that the top and left borders has 1px wide only, instead of 2. Also try 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.PaintBox1Paint(Sender: TObject);begin  PaintBox1.Canvas.Pen.Width:=2;  PaintBox1.Canvas.Rectangle(1, 1, PaintBox1.Width, PaintBox1.Height);end; This fixes the width, but there are 2 missing pixels, at the top left and top right. Tested on Windows 10. There are more properties I need to set to get a proper drawing? (I mean 2px width in each border, without missing pixels). Thanks  Edit: On Delphi I get the first test the same (missing 1px at left and top), and the second is without missing pixels (the output is the desired). ---------------------------------------------------------------------- winni · 2019-12-21 12:26 Hi! This error was already there in Delphi 1. In Lazarus with gtk you get the same result. The problem is that it should be the same result for all 4 sides. Either: (0,0,width,height) draws 1 pixel - the other pixel is "outside" the component Or : this draws 2 pixel per line -  then you run in trouble in the very center of the paintbox. Winni ---------------------------------------------------------------------- lainz · 2019-12-21 12:36 Ok thanks. Problem solved, just adding these properties: 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 PaintBox1.Canvas.Pen.Width:=2; // or any width, the settings will respectPaintBox1.Canvas.Pen.JoinStyle:=pjsMiter;// remove rounded bordersPaintBox1.Canvas.Pen.Style:=psInsideframe; // draw border inside rectanglePaintBox1.Canvas.Rectangle(0, 0, PaintBox1.Width, PaintBox1.Height); If I not set pjsMiter it draw rounded borders. If I not set psInsideframe it draws the line centered in the border (half inside, half outside). Setting these two properties solves the problem, I get perfect borders for any pen width values.