Recent

Author Topic: Resize event only when stretch but not when shrink  (Read 602 times)

BubikolRamios

  • Sr. Member
  • ****
  • Posts: 307
Resize event only when stretch but not when shrink
« on: March 05, 2024, 12:17:46 am »
paintbox is on panel, both alClient.

Code: Pascal  [Select][+][-]
  1. procedure TForm1.PaintBox1Paint(Sender: TObject);
  2. begin
  3.   Form1.Caption := IntToStr(PaintBox1.Canvas.Width) + ',' + IntToStr(PaintBox1.Canvas.height);
  4.   PaintBox1.Canvas.Line(0, 0, PaintBox1.Canvas.Width-1, PaintBox1.Canvas.Height-1);
  5. end;
  6.  
  7. procedure TForm1.PaintBox1Resize(Sender: TObject);
  8. begin
  9.   PaintBox1.Invalidate;
  10. end;
  11.  
  12.  
  13.  
  14.  

When form stretched out, numbers are printed, when shrank, nothing happens about numbers at form caption.
Thought "PaintBox1.Canvas.Line" works all the time as expected.
Do tell how this works ?
« Last Edit: March 05, 2024, 12:29:41 am by BubikolRamios »
lazarus 3.2-fpc-3.2.2-win32/win64

domasz

  • Hero Member
  • *****
  • Posts: 553
Re: Resize event only when stretch but not when shrink
« Reply #1 on: March 05, 2024, 12:30:34 am »
How about?

Code: Pascal  [Select][+][-]
  1. procedure TForm1.PaintBox1Paint(Sender: TObject);
  2. begin
  3.   Form1.Caption := IntToStr(PaintBox1.Width) + ',' + IntToStr(PaintBox1.height);
  4.   PaintBox1.Canvas.Line(0, 0, PaintBox1.Canvas.Width-1, PaintBox1.Canvas.Height-1);
  5. end;
  6.  

jamie

  • Hero Member
  • *****
  • Posts: 6734
Re: Resize event only when stretch but not when shrink
« Reply #2 on: March 05, 2024, 12:33:14 am »
Don't use the Canvas.Width and height. That is not a reliable source, as you can see, it only reports the maximum size.

Use ClientWidth and height etc.
The only true wisdom is knowing you know nothing

BubikolRamios

  • Sr. Member
  • ****
  • Posts: 307
Re: Resize event only when stretch but not when shrink
« Reply #3 on: March 05, 2024, 12:34:31 am »
Quote
it only reports the maximum size

Hmm this is right description of what I see.

Thanks.

« Last Edit: March 05, 2024, 01:48:34 am by BubikolRamios »
lazarus 3.2-fpc-3.2.2-win32/win64

 

TinyPortal © 2005-2018