简体   繁体   中英

how to make list with buttons at each item in Delphi

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~~~

PIC

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM