Use of PaintBox lazarus / 55-TAChart ---------------------------------------------------------------------- Davidous · 2019-07-03 18:02 Hello, I would like to ask you of how to use a PaintBox on my Form. I can draw on the Form Canvas, but now I would like to draw a line on the Paintbox. Could someone please provide me with a short sample code? ---------------------------------------------------------------------- wp · 2019-07-03 18:05 Not tested but it should give you the idea: 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.PaintboxPaint(Sender: TObject);begin  with Paintbox1 do begin  Canvas.Brush.Color := clWhite;    Canvas.FillRect(0, 0, Width, Height);    Canvas.Pen.Color := clRed;    Canvas.Line(0, 0, Width, Height);  end;end; ---------------------------------------------------------------------- Davidous · 2019-07-03 19:05 Thank you, but how to call it. For the canvas of the form there is an OnPaint event, but there isn't such for the PaintBox. ---------------------------------------------------------------------- howardpc · 2019-07-03 19:10 Quote from: Davidous on July 03, 2019, 09:05:59 pmThank you, but how to call it. For the canvas of the form there is an OnPaint event, but there isn't such for the PaintBox. Yes there is. Why do you think otherwise? ---------------------------------------------------------------------- Davidous · 2019-07-03 19:27 Oh yes, there is, sorry But what I wanted to say, that I cannot type Paintbox.Paint for some reason. Why is that? (For my form I can type Form.Paint and then the canvas is painted.) ---------------------------------------------------------------------- VTwin · 2019-07-03 19:41 You don't normally call Paint, it is called as necessary when the form or control is redrawn. Use Update if required to force it for some reason, or Invalidate: https://stackoverflow.com/questions/1251009/whats-the-difference- between-refresh-update-and-repaint ---------------------------------------------------------------------- lucamar · 2019-07-03 19:48 Quote from: Davidous on July 03, 2019, 09:27:20 pmOh yes, there is, sorry But what I wanted to say, that I cannot type Paintbox.Paint for some reason. Why is that? (For my form I can type Form.Paint and then the canvas is painted.) Paint is a protected method in both classes. You can call it for the form because you're dealing with a derived class (MyForm = class(TForm)). However, all the default Paint method does is call the OnPaint event if set, so you may as well call it directly; i.e. instead of calling Code: [Select]MyPaintBox.Paintinvoke the handler directly as, for example: Code: [Select]MyPaintBoxPaint(Self)(whatever it is called in your program, of course). ---------------------------------------------------------------------- Davidous · 2019-07-03 20:10 Thank you. Sadly I cannot get it to work. I don't know why... ---------------------------------------------------------------------- Davidous · 2019-07-03 20:18 I just created a whole new form and placed a paintbox on it. Now it works Thank you for all the ideas! ---------------------------------------------------------------------- lucamar · 2019-07-03 20:50 Quote from: Davidous on July 03, 2019, 10:18:03 pmI just created a whole new form and placed a paintbox on it. Now it works Thank you for all the ideas! How were you doing it before? Just curiousity. ---------------------------------------------------------------------- Davidous · 2019-07-03 21:04 I have a very long procedure and a form. On this form I have many graphs. It is still interesting, because if I place a PaintBox on this Form, then for some reason I cannot draw the line I want. If I give a PaintBox to an other (empty) form, then it works. So I still don't understand... Right now I work with these 2 lines: PaintBox1.Canvas.Pen.Color:=clBlack;  PaintBox1.Canvas.Line(PaintBox1. Left+20,PaintBox1.Top+PaintBox1.Height,PaintBox1.Left+20,PaintBox1.Top ); On 1 form it doesn't work, on the other it does... ---------------------------------------------------------------------- lucamar · 2019-07-03 23:52 And you're doing that in the PaintBox's OnPaint handler? Strange; it should work the same wherever it is. ---------------------------------------------------------------------- Davidous · 2019-07-04 07:02 Yes