Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8349819
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T08:07:24+00:00 2026-06-09T08:07:24+00:00

I want to create a custom control derived from TPanel that contains an image

  • 0

I want to create a custom control derived from TPanel that contains an image and a bunch of other controls on it.
After writing the code I have some weird behavior in my program. I realized that some vars that were supposed to be initialized in TDisplay.Resize (override) was never initialized because the Resize was never executed.

To ‘solve it’ I put a button on a form and called the LoadSample function which calls ClientHeight which calls Resize FOR THE FIRST TIME!

constructor TDisplay.Create(AOwner: TComponent);
begin
 inherited Create(AOwner);
 Ready         := FALSE;                                                       
 Parent        := Owner as TWinControl;
 Width         := 200;
 Height        := 86;                 
 Color         := clSilver;
 Caption       := '';
 DoubleBuffered:= TRUE;


  InternalDisplay:= TImage32.Create(Self);
  with Display DO
   begin
    Parent        := Self;
    Bitmap.Width  := 1;                                                        
    Bitmap.Height := 1;
    RepaintMode   := rmOptimizer;     
    Align         := alClient;
    SetupBitmap(TRUE, clBlack32);    
    Visible       := TRUE;
    OnMouseDown   := DMouseDown;
   end;
 ...
end;

Update:
Also the InternalDisplay won’t be aligned to its parent size until I manually resize the form (the control) at runtime. Only then it will act as it was supposed to act (to stay aligned to alClient).

Update 2:
Resize is declared like that: procedure Resize; override;

Update 3:
I removed the ClientHeight line from my construnctor and move it here:

procedure TDisplay.LoadSample(VAR Obj: TMySample; CONST bReleaseOnExit: boolean)
begin
 ClientHeight;  <--------- this will call Resize for the first time and my code will be finally initialized. But until this point my display will look odd because the code was never initialized. So the user will see weird stuff until it pushes the 'LoadSample' button.
 more code here....
end;

Update 4:
I used HandleNeeded as David suggested and it solved the initialization problem. However, the Image still won’t align to the entire client area unless I manually resize the form/control.

Update 5
Continued here, as David suggested: TImage won't align to parent

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T08:07:25+00:00Added an answer on June 9, 2026 at 8:07 am

    Your form isn’t showing yet, so it isn’t yet able to receive Windows messages (such as the resize message that triggers the OnResize event).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to create a new custom control derived from ContentControl (it will be
I want to create simple custom control (derived from control and with look defined
I want to create a control (derived from TCustomControl) that is invisible but reacts
I want to create a Custom Control derived from ComboBox , however if I
I want to create a custom control (derived from Control class), and when I
I tried to create a custom user control in C# that handles other controls
I'm writing a custom control derived from CWnd . I want to initialize a
i want create a custom json data from the mssql 2008 results so that
I would like to create a set of custom controls that are basically image
I want to create custom templated control which controls inside of template coluld be

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.