Board index » cppbuilder » TComboBox->Style = csOwnerDrawVariable

TComboBox->Style = csOwnerDrawVariable

Hello!
TComboBox->Style = csOwnerDrawVariable

On my computer this seems to be exactly the same as TComboBox->Style =
csOwnerDrawFixed. Because there isn't an edit box in the combobox in any of
these cases. But if I select csComboBox, the ComboBox is how I want it, but
without ownerdrawn.

What's wrong? Bug?

/best regards Marcus

 

Re:TComboBox->Style = csOwnerDrawVariable


Hi Marcus,

Quote
> TComboBox->Style = csOwnerDrawVariable
> On my computer this seems to be exactly the same as TComboBox->Style =
> csOwnerDrawFixed. Because there isn't an edit box in the combobox in any of
> these cases. But if I select csComboBox, the ComboBox is how I want it, but
> without ownerdrawn.

The csOwnerDrawnVariable style is intended for use with the OnMeaureItem event
in which you can set the height of each item.  In this way, you can draw items
of differing heights.  What exactly are you trying to achieve?

Good luck.

--------------------------------------
Damon Chandler

http://bcbcaq.freeservers.com
Answers to <Commonly Asked Questions>
52064929

Re:TComboBox->Style = csOwnerDrawVariable


Hi!
In the help:
csOwnerDrawVariable - Creates an owner-draw drop-down list with an edit box
for manually entered text. List items can have varying heights.

I only want one height but an edit box would be fine. But I don't know how.
It's not enough to set the property Style property to csOwnerDrawVariable.

An example would be great.

/Marcus

Quote
> The csOwnerDrawnVariable style is intended for use with the OnMeaureItem
event
> in which you can set the height of each item.  In this way, you can draw
items
> of differing heights.  What exactly are you trying to achieve?

Re:TComboBox->Style = csOwnerDrawVariable


Hi Marcus,

Quote
> In the help:
> csOwnerDrawVariable - Creates an owner-draw drop-down list with an edit box
> for manually entered text. List items can have varying heights.

I do not have the newest version of Builder so I can't comment on the accuracy
of the help entry, however, in my version there are only four styles: csSimple,
csDropDown, csOwnerDrawFixed, and csOwnerDrawVariable.  None of these styles
will prvide for the combination of an owner-drawn combobox and the CBS_DROPDOWN
style (i.e, an edit control instead of a static text control).  If only these
four styles exist in your vesion as well, then this is a clear documentation
error.  It is possible, however, to add the mix of styles by simply deriving a
new component from TComboBox and augmenting the CreateParams() method.  For
example...

// in header...
class TMyComboBox : public TComboBox
{
protected:
    void __fastcall CreateParams(TCreateParams &Params);
public:
    __fastcall TMyComboBox(TComponent* Owner);
__published:

Quote
};

// in source...
void __fastcall TMyComboBox::CreateParams(TCreateParams &Params)
{
    TCustomComboBox::CreateParams(Params);
    Params.Style = Params.Style | CBS_OWNERDRAWVARIABLE;

Quote
}

Install the component, set its Style property to csDropDown, then implement the
OnDrawItem and OnMeasureItem event handlers as usual...

void __fastcall TForm1::MyComboBox1MeasureItem(TWinControl *Control, int Index,
    int &Height)
{
    Height = 30;        

Quote
}

void __fastcall TForm1::MyComboBox1DrawItem(TWinControl *Control, int Index,
    TRect &Rect, TOwnerDrawState State)
{
    TCanvas *CBCanvas = MyComboBox1->Canvas;
    if (State.Contains(odSelected))
    {
        CBCanvas->Font->Color = clHighlightText;
        CBCanvas->Brush->Color = clHighlight;
    }
    else
    {
        CBCanvas->Font->Color = clBlue;
        CBCanvas->Brush->Color = clYellow;
    }
    CBCanvas->FillRect(Rect);

    AnsiString text = MyComboBox1->Items->Strings[Index];
    DrawText(CBCanvas->Handle, text.c_str(), text.Length(),
                 &RECT(Rect), DT_LEFT | DT_VCENTER | DT_SINGLELINE);

Quote
}

Good luck!

--------------------------------------
Damon Chandler

http://bcbcaq.freeservers.com
Answers to <Commonly Asked Questions>
52064929

Re:TComboBox->Style = csOwnerDrawVariable


Thank you very much Deamon!

It was only one problem...
&RECT(Rect) didn't work
Error: Must take address of a memory location

But maybe you know another way to take the address of the return value
without placing it in a temp variabel like: RECT ARect = RECT(Rect)

Thanks for all help...

/Marcus

Re:TComboBox->Style = csOwnerDrawVariable


Hello again!
Problem two: The OnMeasureItem event is never called. The height is always
16.

What's wrong?

/Marcus

Damon Chandler <dm...@cornell.edu> skrev i
diskussionsgruppsmeddelandet:384DC2CD.BAF20...@cornell.edu...

Quote
> Hi Marcus,
> > In the help:
> > csOwnerDrawVariable - Creates an owner-draw drop-down list with an edit
box
> > for manually entered text. List items can have varying heights.

> I do not have the newest version of Builder so I can't comment on the
accuracy
> of the help entry, however, in my version there are only four styles:
csSimple,
> csDropDown, csOwnerDrawFixed, and csOwnerDrawVariable.  None of these
styles
> will prvide for the combination of an owner-drawn combobox and the
CBS_DROPDOWN
> style (i.e, an edit control instead of a static text control).  If only
these
> four styles exist in your vesion as well, then this is a clear
documentation
> error.  It is possible, however, to add the mix of styles by simply
deriving a
> new component from TComboBox and augmenting the CreateParams() method.
For
> example...

> // in header...
> class TMyComboBox : public TComboBox
> {
> protected:
>     void __fastcall CreateParams(TCreateParams &Params);
> public:
>     __fastcall TMyComboBox(TComponent* Owner);
> __published:
> };

> // in source...
> void __fastcall TMyComboBox::CreateParams(TCreateParams &Params)
> {
>     TCustomComboBox::CreateParams(Params);
>     Params.Style = Params.Style | CBS_OWNERDRAWVARIABLE;
> }

> Install the component, set its Style property to csDropDown, then
implement the
> OnDrawItem and OnMeasureItem event handlers as usual...

> void __fastcall TForm1::MyComboBox1MeasureItem(TWinControl *Control, int
Index,
>     int &Height)
> {
>     Height = 30;
> }

> void __fastcall TForm1::MyComboBox1DrawItem(TWinControl *Control, int
Index,
>     TRect &Rect, TOwnerDrawState State)
> {
>     TCanvas *CBCanvas = MyComboBox1->Canvas;
>     if (State.Contains(odSelected))
>     {
>      CBCanvas->Font->Color = clHighlightText;
>         CBCanvas->Brush->Color = clHighlight;
>     }
>     else
>     {
>     CBCanvas->Font->Color = clBlue;
> CBCanvas->Brush->Color = clYellow;
>     }
>     CBCanvas->FillRect(Rect);

>     AnsiString text = MyComboBox1->Items->Strings[Index];
>     DrawText(CBCanvas->Handle, text.c_str(), text.Length(),
>     &RECT(Rect), DT_LEFT | DT_VCENTER | DT_SINGLELINE);
> }

> Good luck!

> --------------------------------------
> Damon Chandler

> http://bcbcaq.freeservers.com
> Answers to <Commonly Asked Questions>
> 52064929

Re:TComboBox->Style = csOwnerDrawVariable


Hello again!
Problem two: The OnMeasureItem event is never called. The height is always
16.

What's wrong?

/Marcus

Re:TComboBox->Style = csOwnerDrawVariable


Hello again!
Problem two: The OnMeasureItem event is never called. The height is always
16.

What's wrong?

/Marcus

Re:TComboBox->Style = csOwnerDrawVariable


Very sorry for the "mass posting". Sometimes Outlook Express hangs when I
post and then I thought the post wasn't okey.

/Marcus

Re:TComboBox->Style = csOwnerDrawVariable


Quote
: "Marcus" <mest...@hem.passagen.se> wrote:
>Very sorry for the "mass posting". Sometimes Outlook Express hangs when I
>post and then I thought the post wasn't okey.

And when you detect that your Microsoft tool had one of its usual hiccups,
please have a look at the "Cancel" menu item with which you can delete
your own messages.

Thank you.

--
General information:
  * Post to the right group - http://www.borland.com/newsgroups/
    * Do not cross- or multipost
      * Research at http://www.mers.com/searchsite.html

Stefan Hoffmeister - http://www.econos.de/
(TeamB - http://www.teamb.com/)

Re:TComboBox->Style = csOwnerDrawVariable


Hi Marcus,

Quote
> But maybe you know another way to take the address of the return value
> without placing it in a temp variabel like: RECT ARect = RECT(Rect)

I depends on your version of Builder, as the TRect definitions have changed.
For most of my projects, I usually do use a temp "RECT ARect = RECT(Rect)"
scheme.  Usually, you'll want to offset the rectangle a bit anyway, and by using
a separate RECT, you can use the OffsetRect() and InflateRect() API functions.  

Good luck on your project Marcus!

--------------------------------------
Damon Chandler

http://bcbcaq.freeservers.com
Answers to <Commonly Asked Questions>
52064929

Other Threads