As shown in figure, I need to make a list with buttons on each item, one button at down left of the item, and some on the down right.
I Make the demo app using ListBox
control and some Buttons within Panel above on ListBox
, but when the ListBox
scrolling, it's difficult to make the Buttons follow the ListItem
.
who can help, thanks~~~
I got the way to make it!so, I'll post the answer myself~, but Remy Lebeau inspired me.
in the beginning, I used DrawFrameControl()
to make button on list, It works but the style was look like classic windows style, and it's hard to make back color like the pic in the example.
then, I used FillRect()
and DrawEdge()
make the Button, I think it's well, here is the code:
hitPoint := lst1.ScreenToClient(Mouse.CursorPos);
// there is a btnRect var of the Button Rect
edgeRect.Left := btnRect.Left - 1;
edgeRect.Top := btnRect.Top - 1;
edgeRect.Right := btnRect.Right + 1;
edgeRect.Bottom := btnRect.Bottom + 1;
// make button
lst1.Canvas.FillRect(btnRect);
// make edge, FListMouseDown is bool var and setting value at MouseDown/MouseUp Event
//
if PtInRect(edgeRect, hitPoint) and FListMouseDown then begin
DrawEdge(lst1.Canvas.Handle, edgeRect, EDGE_ETCHED, BF_RECT); // button down style
end else begin
DrawEdge(lst1.Canvas.Handle, edgeRect, EDGE_RAISED, BF_RECT);
end;
The following work is store the Rect of Buttons in memory, write the ButtonOnClick event code, and calling ButtonOnClick event at ListMouseUp()
event after judge if Mouse Hit Position is in the Button Rect, The Code is not important like the above drawing Buttons, so it is omitted