Recent

Author Topic: (SOLVED) TSynEdit draw vertical line  (Read 1352 times)

xinyiman

  • Hero Member
  • *****
  • Posts: 2164
    • Lazarus and Free Pascal italian community
(SOLVED) TSynEdit draw vertical line
« on: March 30, 2021, 05:40:22 pm »
Hello guys. Sorry for the stupid question. But I want to draw a vertical line on a TSynEdit component between the seventh and eighth characters.

But this code not run correct

Code: Pascal  [Select][+][-]
  1.  
  2. procedure TFrameEditorCobol.SynEdit1Paint(Sender: TObject; ACanvas: TCanvas);
  3. var
  4.    posizione_x : integer;
  5.    color1      : TColor;
  6. begin
  7.      color1    := ACanvas.Font.Color;
  8.  
  9.      posizione_x := (SynEdit1.Gutter.Width + SynEdit1.CharWidth * 7)+1;
  10.      ACanvas.Pen.Color := clMoneyGreen;
  11.      ACanvas.Line(posizione_x, 0, posizione_x, SynEdit1.Height);
  12.  
  13.      ACanvas.Font.Color := color1;
  14. end;
  15.  
  16.  

In part it works. Because I draw the line as I want. But if I write other characters on the same line, when the line has to disappear because I'm too far to the right, the code doesn't work (because it keeps showing me the line when it should disappear or at least move to the right).

What am I doing wrong?
« Last Edit: March 30, 2021, 09:53:13 pm by xinyiman »
Win10, Ubuntu and Mac
Lazarus: 2.1.0
FPC: 3.3.1

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 7516
  • Debugger - SynEdit - and more
    • wiki
Re: TSynEdit draw vertical line
« Reply #1 on: March 30, 2021, 08:31:26 pm »
Maybe you need SynEdit.LeftChar ?

LeftChar is 1, if the editor is NOT scrolled.
If you scroll one char out then LeftChar = 2, and so on.

Code: Pascal  [Select][+][-]
  1.     posizione_x := (SynEdit1.Gutter.Width + SynEdit1.CharWidth * (8 - SynEdit1.LeftChar)+1;

and
Code: Pascal  [Select][+][-]
  1. if SynEdit1.LeftChar > 8 then exit; // do not draw

Note, I increased your 7 to 8, because LeftChar subtracts 1.

xinyiman

  • Hero Member
  • *****
  • Posts: 2164
    • Lazarus and Free Pascal italian community
Re: TSynEdit draw vertical line
« Reply #2 on: March 30, 2021, 09:52:53 pm »
Thank you  ;D
Win10, Ubuntu and Mac
Lazarus: 2.1.0
FPC: 3.3.1

 

TinyPortal © 2005-2018