Board index » cppbuilder » Remove border of ComboBox

Remove border of ComboBox

Hi!
Maybe this is a API question but anyway. What's the best way to remove the
border of a TComboBox? The VCL have no way to remove it and I don't want it.

Thanks for help

/regards Marcus

 

Re:Remove border of ComboBox


Hi Marcus,

Quote
> Maybe this is a API question but anyway. What's the best way to remove the
> border of a TComboBox? The VCL have no way to remove it and I don't want it.

Provide a handler for the WM_PAINT message, in which you render the new border
after the combo box has drawn itself.  For example...

class TMyComboBox : public TComboBox
{
private:
    MESSAGE void __fastcall WMPaint(TMessage& AMsg)
    {
        // have the combo box render itself first
        TComboBox::Dispatch(&AMsg);

        // next, render the new border
        HDC Hdc = GetDC(Handle);
        int save_id = SaveDC(Hdc);
        try
        {
            RECT R = static_cast<RECT>(ClientRect);
            SelectObject(Hdc, GetStockObject(NULL_BRUSH));
            SelectObject(Hdc, GetStockObject(WHITE_PEN));
            Rectangle(Hdc, R.left, R.top, R.right, R.bottom);
        }
        catch (...)
        {
            RestoreDC(Hdc, save_id);
            ReleaseDC(Handle, Hdc);
        }
        RestoreDC(Hdc, save_id);        
        ReleaseDC(Handle, Hdc);
    }
public:
    __fastcall TMyComboBox(TComponent* AOwner) : TComboBox(AOwner) {}

BEGIN_MESSAGE_MAP
    MESSAGE_HANDLER(WM_PAINT, TMessage, WMPaint)
END_MESSAGE_MAP(TComboBox)

Quote
};

Good luck!

--
Damon Chandler (TeamB)
http://bcbcaq.freeservers.com

Re:Remove border of ComboBox


Thanks...

Maybe you could say how to move the content of the ComboBox inside the
border to the upper left point? I want to delete the border, not only hide
it.
Like this:
BitBlt(Hdc, 0, 0, R.right - 4, R.bottom - 4, Hdc, 2, 2, SRCCOPY);

But that doesn't work very well.

Then I need to be able to set the height to the new area. It don't allow any
height under 21 now.

Thanks again...
/regards Marcus

"Damon Chandler (TeamB)" <dm...@cornell.edu> wrote in message
news:38F6B367.8D31D06D@cornell.edu...

Quote
> Hi Marcus,
> > Maybe this is a API question but anyway. What's the best way to remove
the
> > border of a TComboBox? The VCL have no way to remove it and I don't want
it.

> Provide a handler for the WM_PAINT message, in which you render the new
border
> after the combo box has drawn itself.  For example...

> class TMyComboBox : public TComboBox
> {
> private:
>     MESSAGE void __fastcall WMPaint(TMessage& AMsg)
>     {
>         // have the combo box render itself first
>         TComboBox::Dispatch(&AMsg);

>         // next, render the new border
>         HDC Hdc = GetDC(Handle);
>         int save_id = SaveDC(Hdc);
>         try
>         {
>             RECT R = static_cast<RECT>(ClientRect);
>             SelectObject(Hdc, GetStockObject(NULL_BRUSH));
>             SelectObject(Hdc, GetStockObject(WHITE_PEN));
>             Rectangle(Hdc, R.left, R.top, R.right, R.bottom);
>         }
>         catch (...)
>         {
>             RestoreDC(Hdc, save_id);
>             ReleaseDC(Handle, Hdc);
>         }
>         RestoreDC(Hdc, save_id);
>         ReleaseDC(Handle, Hdc);
>     }
> public:
>     __fastcall TMyComboBox(TComponent* AOwner) : TComboBox(AOwner) {}

> BEGIN_MESSAGE_MAP
>     MESSAGE_HANDLER(WM_PAINT, TMessage, WMPaint)
> END_MESSAGE_MAP(TComboBox)
> };

> Good luck!

> --
> Damon Chandler (TeamB)
> http://bcbcaq.freeservers.com

Other Threads