TImage and Resize

I have a component that is inherited from TImage. I place the component on a form and resize it to larger than it's default size. In the resize event I create a new bitmap and assign it to the picture property, then free the bitmap. So far so good.

When the form is created and made visible at runtime the resize event of my component is invoked twice:  Once when the width is set and once when the height is set.

My problem is that during the resize event the ClientWidth and ClientHeight of my component have the default component size as their values, instead of the size that I dragged out when I dropped the control on the form at development time.

How can I, when the form is first shown, know the size of my component?

LVL 6
zebadaAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

MadshiCommented:
Umhh... Have you tried overriding the SetBounds method instead of using the resize event? And then do you set the width and height in two different calls? Please call SetBounds(Left, Top, newWidth, newHeight) instead...

Does this help?

Regards, Madshi.
0
LischkeCommented:
I would limit the resize event (or SetBounds method for that matter, which will likely produce the same result as the event solution) not to react as long as the form is loading. You can check this either by csReading or csLoading in the image's or the form's component state. This avoids unnecessary execution during program start. The override TImage.Loaded and adjust the new image the first time. At this time you already know the correct size.

In the case you don't want to derive a new class from TImage you can also use those methods from the form you are designing. The resize event is already using OnResize, no problem, and the Loaded method also exists for TForm.

Ciao, Mike
0
zebadaAuthor Commented:
Madshi,
I think you misunderstood the question. I am not trying to change the size of my component. I am trying to find out what its size is.

Mike,
Thanks, the TImage.Loaded event gives me the component size, thanks.
So Mike, answer for the points.


0
Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

LischkeCommented:
Rrrrright, pleased to help :-)

Ciao, Mike
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
MadshiCommented:
Hmm... Overriding the SetBounds method probably would have given you the correct size, too - but doesn't matter. Nice, that TImage.Loaded works for you...   :-)

Regards, Madshi.

P.S: My suggestion had two parts: Part 1 was the suggestion to override the SetBounds method to get the correct size. Part 2 was the suggestion to call SetBounds to SET the correct size. Okay, seems that Part 2 was not what you needed anyway...   (-:
0
zebadaAuthor Commented:
Quick followup question...

csLoading appears to have the desired effect at runtime of restricting what happens in the resize event.

However at design time csLoading doesn't appear to be set, nor does the Loading event get executed (probably 'cause its not streaming in from a form file).

What can I use at desing time to restrict what happens in resize.

All I need to do is to create a new bitmap when the image is a) created and b) resized. Both at runtime and development time.

0
zebadaAuthor Commented:
Madshi,

How would I use (override) the SetBounds method to "get the correct size"?

0
MadshiCommented:
Something like this:

  public
    procedure SetBounds(ALeft, ATop, AWidth, AHeight: integer); override;

procedure TYourComponent.SetBounds(ALeft, ATop, AWidth, AHeight: integer);
begin
  inherited SetBounds(ALeft, ATop, AWidth, AHeight);
  // here you should have the correct size...
end;

Hmmm... I didn't test it. It's just an idea and written out of my mind...

Regards, Madshi.
0
LischkeCommented:
zebada,

Loaded gets also called at design time with one exception: When the component is created the very first time (when you dropped it onto the form). In this case you will have no choice than to listen to a resize method (SetBounds, OnResize) in order to adjust your component. This is also necessary for all other size changes after the component has been created loaded with the stored values. So you need that anyway.

Madshi,

yep, your code is okay. We are using this kind of sizing notification all the time here ...

Ciao, Mike
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Delphi

From novice to tech pro — start learning today.