Thread: Builder Canvas & TListBox question

  1. #1
    Joan Lesas

    Builder Canvas & TListBox question


    I'm programming a componente derivated from TListBox. What I'm trying to do, is to put the strings in the objetc, centered inside the Canvas.

    For example; I have one TListBox with an Height of 100. But i only have one Item, so I don't want that it displays in the top. I would want that it displays in the middle of the control, about in the pixel 40 of "y", so it looks more centered.

    I'm unable to get this, although i tried with MoveTo(), making Draw(0,40), and so on.

    Please, how can I do that? Is it possible?


  2. #2
    Code Monkey Davros's Avatar
    Join Date
    Jun 2002
    Have you set the Style property to OwnerDraw and created an OnDraw event?

  3. #3
    Registered User
    Join Date
    Apr 2003
    Add blanks lines
    ListBox1->Items->Insert(0, "");
    until its centered
    then when you need to delete them

  4. #4
    Joan Lesas
    Yes Davros, I set the Style variable to lbOwnerDrawVariable, and I created a DrawItem method wich override the original one. Realize that I'm developing a component itself, not an application. In fact, the MoveTo() and Draw() methods wich i said I use, was called from the DrawItem method of the component.

    Also, the problem with the suggestion of Rflindberg, is that if I add some Items in tne first positions of the ListBox, then the user can select some "white blanks".

    Anyway, so you understand my problem, what i would want to get is to be able of doing exactly that.

    I tried to down the Canvas by making some like:

    Canvas->TextOut(Rect.Left, Rect.Top+OFFSET, Items->Strings[Index]);

    But although in that way, the text of the ListBox appears at Y+Offset, the selection of the item is done at (Rect.Left, Rect.Top), so if you click in the text, you get nothing, because the control only understands clicks in their correct place.

    Please, what I would like is to get the items a little down in the Y axis control, i'm not able to get it.


  5. #5
    Code Monkey Davros's Avatar
    Join Date
    Jun 2002
    Hi Joan,

    So I take it that your Draw method is being called, and that text is being placed on the canvas. So it's only a question of setting the selection colour and focus rectangle in the right place?

    I think you will need to draw these yourself, at your required positions, in your draw method. The OnDrawItem event looks like this:

    typedef void __fastcall (__closure *TDrawItemEvent)(Controls::TWinControl* Control, int Index, const Windows::TRect &Rect, TOwnerDrawState State);
    Rect gives you the drawing rectangle area, AND State gives you the required state. It is a Set and can be a combination of the following:

    dSelected The item is selected.
    odGrayed The item should appear grayed.
    odDisabled The item is disabled.
    odChecked The item should appear checked. (This does not apply to all objects)
    odFocused Keyboard input is directed to the item.
    odDefault The item is the default item (This does not apply to all objects)
    odHotLight The item is hot-lighted because under the mouse (only if the operating system supports hot-lighting)
    odInactive The item and its associated menu are inactive (only under Windows 98 or later)

    odNoAccel Any underline of an accelerator character should be skipped when drawing the control (only under Windows 2000 or later)
    odNoFocusRect Do not display visual cues that indicate focus (only under Windows 2000 or later)
    odReserved1 Not currently used.
    odReserved2 Not currently used.
    odComboBoxEdit The drawing takes place in the edit box of a combo box control.

    It might also be worth taking a look at the OnMeasureItem event also.

    Hope this helps.

  6. #6
    Artelo Leser
    Thanks for rour help, although i didn't was able to get these days to get the result i wanted.

    Yes, it was only a question about setting colour and focus rectangle in the correct place, but I'm going to try another approach. In the DrawItem method, I didn't was able to get it.

    Thanks again!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. another do while question
    By kbpsu in forum C++ Programming
    Replies: 3
    Last Post: 03-23-2009, 12:14 PM
  2. Replies: 2
    Last Post: 10-03-2006, 04:48 PM
  3. THE END - Borland C++ Builder, Delphi, J Builder?
    By Davros in forum A Brief History of
    Replies: 5
    Last Post: 02-28-2006, 11:23 PM
  4. TStringGrid component with TListBox inside
    By Daniel Pertin in forum Windows Programming
    Replies: 3
    Last Post: 06-18-2003, 01:53 PM
  5. opengl DC question
    By SAMSAM in forum Game Programming
    Replies: 6
    Last Post: 02-26-2003, 09:22 PM