problem with a component that has other components

Hi ! I am writing a component that has multiple elements inside (edit, buttons etc).
I started with TWinControl and then created inside TEdit and other elements.
The problem: when window below my component is updated, the Edit does not repaint (looks transparent).
Apparently I violate the paint message propagation ... Please help me! Also let me know if there are better ways to make such a control. 
Boris
0
Boris
12/3/2010 7:48:56 PM
📁 embarcadero.cppbuilder.writing
📃 359 articles.
⭐ 0 followers.

💬 5 Replies
👁️‍🗨️ 1360 Views


<Boris Epel> wrote in message news:310889@forums.embarcadero.com...
> I started with TWinControl
Consider deriving your main component from TPanel or TFrame or some other 
container, instead of TWinControl directly.
-- 
Remy Lebeau (TeamB)
0
Remy
12/3/2010 10:33:55 PM
Thank you, Remy.
> Consider deriving your main component from TPanel or TFrame or some other 
> container, instead of TWinControl directly.
TPanel container works the same like TWin Control (edit disappears until it forced to repaint).
When I put my control on Form - no problem. When I use control as a child on a stringgrid to edit a cell and grid is updated later then my control
the Edit is not repainted. Funny enough buttons are fine. Panel itself is also fine. May be it is a Windows bug ...
Regards,
Boris
0
Boris
12/4/2010 12:53:47 AM
<Boris Epel> wrote in message news:311013@forums.embarcadero.com...
> TPanel container works the same like TWin Control
> (edit disappears until it forced to repaint).
Then you are likely not setting up the components correctly to begin with. 
Please show your actual code.
-- 
Remy Lebeau (TeamB)
0
Remy
12/6/2010 7:23:33 PM
Hi Remy,
The control is derived from TPanel, beside TEdit a custom made button is added.
everything else is painted directly on TPanel in Paint
other functions are keyboard events.
Boris
..h
class PACKAGE SSpinEdit : public TPanel
{
private:
    SSpinButton *FButton;
    TEdit       *FEdit;
....
    void __fastcall ChangeControlLayout(void);
    void __fastcall Paint(void);
}
..cpp
__fastcall SSpinEdit::SSpinEdit(TComponent* Owner)
        : FEdit(NULL), FButton(NULL), TPanel(Owner)
{
  FButton = new SSpinButton(this);
....
  FEdit   = new TEdit(this);
  FEdit->Visible = true;
  FEdit->Parent = this;
  FEdit->OnKeyDown = EditKeyDown;
  FEdit->OnKeyUp = EditKeyUp;
  FEdit->OnKeyPress = EditKeyPress;
  FEdit->OnChange = EditChange;
  FEdit->ParentFont = true;
....
}

void __fastcall SSpinEdit::ChangeControlLayout(void)
{
....
    FButton->SetBounds(0, 0, Height, Height);
    FEdit->SetBounds(Height, 0, btn_shift, Height);
....
}
0
Boris
12/6/2010 9:20:16 PM
<Boris Epel> wrote in message news:311476@forums.embarcadero.com...
> The control is derived from TPanel, beside TEdit a
> custom made button is added.
If that is all the component consists of, then I would suggest deriving from 
TEdit directly instead, and let it manage its own associated button (much 
like the VCL's own TLabeledEdit and TButtonedEdit components do), eg:
{code:cpp}
class PACKAGE SSpinEdit : public TEdit
{
    typedef TEdit inherited;
private:
    SSpinButton *FButton;
    MESSAGE void __fastcall CMEnabledChanged(TMessage &Message);
    MESSAGE void __fastcall CMVisibleChanged(TMessage &Message);
protected:
    virtual void __fastcall Notification(TComponent *AComponent, TOperation 
Operation);
    virtual void __fastcall SetBounds(int ALeft, int ATop, int AWidth, int 
AHeight);
    virtual void __fastcall SetParent(TWinControl *AParent);
    DYNAMIC void __fastcall KeyDown(Word &Key, TShiftState Shift);
    DYNAMIC void __fastcall KeyUp(Word &Key, TShiftState Shift);
    DYNAMIC void __fastcall KeyPress(Char &Key);
    DYNAMIC void __fastcall Change();
public:
    __fastcall SSpinEdit(TComponent *Owner);
    BEGIN_MESSAGE_MAP
        VCL_MESSAGE_HANDLER(CM_ENABLEDCHANGED, TMessage, CMEnabledChanged)
        VCL_MESSAGE_HANDLER(CM_VISIBLECHANGED, TMessage, CMVisibleChanged)
    END_MESSAGE_MAP(TEdit)
};
__fastcall SSpinEdit::SSpinEdit(TComponent* Owner)
    : TEdit(Owner), FButton(NULL)
{
    FButton = new SSpinButton(this);
    FButton->FreeNotification(this);
    ParentFont = true;
}
void __fastcall SSpinEdit::CMEnabledChanged(TMessage &Message)
{
    inherited::Dispatch(&Message);
    if( FButton ) FButton->Enabled = Enabled;
}
void __fastcall SSpinEdit::CMVisibleChanged(TMessage &Message)
{
    inherited::Dispatch(&Message);
    if( FButton ) FButton->Visible = Visible;
}
void __fastcall SSpinEdit::Notification(TComponent *AComponent, TOperation 
Operation)
{
    inherited::Notification(AComponent, Operation);
    if( (AComponent == FButton) && (Operation == opRemove) )
        FButton = NULL;
}
void __fastcall SSpinEdit::SetBounds(int ALeft, int ATop, int AWidth, int 
AHeight)
{
    FButton->SetBounds(ALeft, ATop, AHeight, AHeight);
    inherited::SetBounds(ALeft + AHeight, ATop, AWidth - AHeight, AHeight);
}
void __fastcall SSpinEdit::SetParent(TWinControl *AParent)
{
    inherited::SetParent(AParent);
    if( FButton ) FButton->Parent = AParent;
}
void __fastcall SSpinEdit::KeyDown(Word &Key, TShiftState Shift)
{
    ...
    inherited::KeyDown(Key, Shift);
}
void __fastcall SSpinEdit::KeyUp(Word &Key, TShiftState Shift)
{
    ...
    inherited::KeyUp(Key, Shift);
}
void __fastcall SSpinEdit::KeyPress(Char &Key)
{
    ...
    inherited::KeyPress(Key);
}
void __fastcall SSpinEdit::Change()
{
    ...
    inherited::Change();
}
{code}
-- 
Remy Lebeau (TeamB)
0
Remy
12/6/2010 10:51:27 PM
Reply: