Author: Tomas Rutkauskas
I have created my own listbox control as a descendant of TListBox. What I want to
be able to do is to change the client area of the listbox so that I can draw a
label above the list box area. I can change the client rect by overriding the
CreateWnd method like this:
1 procedure TMyListBox.CreateWnd;
2 begin3 inherited CreateWnd;
4 ClientHeight := Height - 20;
5 end;
But I can't move the client rect down (ie change the origin). Using ClientOrigin.X
:= 20 does not work as the ClientOrigin property is read only. I'm thinking maybe I
need to override the CreateParams method to do this. Any ideas?
Answer:
You have to respond to the WM_NCCALCSIZE message:
6 7 procedure TREDCustomListBox.WMNCCalcSize(var Msg: TWMNCCALCSIZE);
8 begin9 inherited;
10 Inc(MSG.CalcSize_Params^.rgrc[0].Top, FHeader.Height);
11 end;
That is a the method within my own listbox which does exactly what you want to do.
Notice how I'm incrementing the client area by the height of the header (which I
implemented as a separate class so I can do the same thing in other controls). It
was a fun exercise.
Another clue: You have to paint the header in WM_NCPAINT