Recent

Author Topic: object width, object.canvas width  (Read 901 times)

BubikolRamios

  • Sr. Member
  • ****
  • Posts: 350
object width, object.canvas width
« on: March 24, 2024, 11:52:53 am »
At start of program:
Code: Pascal  [Select][+][-]
  1. procedure TForm1.Button5Click(Sender: TObject);
  2. begin
  3.   //640
  4.   showmessage(inttostr(PaintBox1.Width));
  5.   //0
  6.   showmessage(inttostr(PaintBox1.Canvas.Width));
  7. end;  
  8.  

Later on canvas dimensions gets right value (executing some code), same as object. Have no idea how and why.
Paintbox: align:allClient if that has anything to do with it.
lazarus 3.2-fpc-3.2.2-win32/win64

jamie

  • Hero Member
  • *****
  • Posts: 6964
Re: object width, object.canvas width
« Reply #1 on: March 24, 2024, 02:40:39 pm »
The properties in the canvas as for the width and rect. etc., should not be used as a reference, its use is only valid when the canvas is in play and even then, it really shouldn't be used because it can stagnate in values that do not seem to follow the course of your code.
 
 You may find at times the value there could be at some obscured value, like 2000x2000 or even more.

  You may even find old left over values from where the client was larger and you just reduced the size of the form, it will report the largest ever value that it reached but not reduce when client shrinks.

 use the client properties to obtain this needed info.

 
The only true wisdom is knowing you know nothing

TRon

  • Hero Member
  • *****
  • Posts: 4377
Re: object width, object.canvas width
« Reply #2 on: March 25, 2024, 03:22:43 am »
As mentioned by jamie a canvas is only valid at (or in between) certain events and for a paintbox that usually is the onpaint event. If you need to have something more stable then an offscreen bitmap can be used that can be drawn to the paintbox canvas at the right moment.
Today is tomorrow's yesterday.

Phoenix

  • Full Member
  • ***
  • Posts: 112
Re: object width, object.canvas width
« Reply #3 on: May 14, 2025, 01:31:31 pm »
  You may even find old left over values from where the client was larger and you just reduced the size of the form, it will report the largest ever value that it reached but not reduce when client shrinks.

Awesome, I fully agree  >:(

I just fell badly and also rolled on the ground because of the same "problem". So that's how it is..  :P

 

TinyPortal © 2005-2018