Solved

Custom control size change notification?

Posted on 1998-07-10
1
173 Views
Last Modified: 2010-04-04
I am writing a descendant of TCustomControl and my control needs notification when it is resized (at design and run time), what is the easiest way of doing this?
0
Comment
Question by:khenr29j
1 Comment
 
LVL 6

Accepted Solution

by:
Holger101497 earned 100 total points
ID: 1357672
You need to override SetBounds which is called when the size changes (also when assignments to Height, Width, Left, Top are made).
You can do whatever you want before calling the inherited method, even specify different behavior for design mode and runtime...


Here's an example from the Delphi FAQs that shows how to prevent a form from resizing. It should solve your problem as well...:

================ Delphi FAQ:
Preventing Components from Resizing

            Question:

            How can I prevent resizing of my component at design-time?

            Answer:

            Have your constructor  set the default size of the object.
            Override the SetBounds method, and then check the
            component state. If it is in design mode (csDesigning in
            ComponentState) simply pass the default values for width
            and heights to the inherited SetBounds, otherwise you
            pass the parameters unchanged.

            Example:

            procedure TVu.SetBounds(ALeft : integer;
                                    ATop : integer;
                                    AWidth : integer;
                                    AHeight : integer);
            begin
              if csdesigning in componentstate then begin
                AWidth := 50;
                AHeight := 50;
                inherited;
              end;

well, that's the whole sample code... My guess yould be there's an "end" missing after AHeight:=50; but it's also possible that you want to specify other non-standard behavior for runtime-resizing before calling the inherited function...
Good luck!
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
automatically logging in via bde delphi 3 67
System restore point 4 91
Process Javascript errors with Delphi TWebBrowser 1 111
Convert a string into a TDateTime 5 50
The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
I designed this idea while studying technology in the classroom.  This is a semester long project.  Students are asked to take photographs on a specific topic which they find meaningful, it can be a place or situation such as travel or homelessness.…

937 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

6 Experts available now in Live!

Get 1:1 Help Now