Re: When to create TCustomControl's child controls?



As I've demonstrated, you can use CreateWND, but then your dimensions
are 0 unless you've specified default values beforehand, which I did in
Create. The advantage of doing it this way is that those values are can
be automatically overridden when the control is streamed in, but are
still available should you choose dynamic creation.

Another, though clunky, method, is to use Paint as your common hook,
although you need a variable and a test for it in Paint, for example:

Type TMyControl = class(TCustomControl);
private
fControlInitialised : Boolean;
Procedure InitControl;
.
protected
Procedure Paint; override;
.
.
end;
..
..
..

Procedure TMyControl.Paint;
begin
if not fControlInitialized then InitControl;
..
..// do your painting as usual
..
end

Procedure TMyControl.InitControl;
begin
// create your objects and so on
.
.
fControlinitialised := true;

end;

As you can see it's not the most efficient way of doing it, although it
might be the most intuitive for novices.

On the other hand, Paint will only be called once the form and the
control becomes visible, so you have to take extra care to make sure
you don't reference those controls before they have been created....

Yep, a recipe for problems.

.



Relevant Pages

  • Re: Help with SendKeys
    ... That's a very good suggestion. ... MS Paint myself and so in my previous response I was just going by the ... handles by the fairly straightforward VB Sendkeys function. ... apparent that there are too many bridges to cross to control MSPaint ...
    (comp.lang.basic.visual.misc)
  • Re: Subclassing dynamically created controls
    ... I have achieved being able to paint the background colour of the CEdit box ... painting of the control in MFC by making a derived class will fail at this ... so this is the colour that you want to paint the background of the ... I call pDC->SetBkColor which tells the GDI pointer for this control, ...
    (microsoft.public.vc.mfc)
  • RE: Subclassing dynamically created controls
    ... I have achieved being able to paint the background colour of the CEdit box ... painting of the control in MFC by making a derived class will fail at this ... so this is the colour that you want to paint the background of the ... I call pDC->SetBkColor which tells the GDI pointer for this control, ...
    (microsoft.public.vc.mfc)
  • Re: When to create TCustomControls child controls?
    ... As I've demonstrated, you can use CreateWND, but then your dimensions ... are 0 unless you've specified default values beforehand, ... Another, though clunky, method, is to use Paint as your common hook, ... Procedure InitControl; ...
    (alt.comp.lang.borland-delphi)
  • Re: Weird problem when re-painting form while moving it outside of the screen!
    ... You can only paint what is actually visible on the screen. ... If you want to determine what portion of your control is visible, ... When the control gets the paint event, I use a memory bitmap ...
    (microsoft.public.dotnet.framework.drawing)