Код у моего наследника TListBox:
| Код | procedure TListBox.CreateWnd; begin inherited CreateWnd; FButton := TButton.Create(Self); FButton.Parent := Self; FButton.Visible := False; FButton.Caption := 'Êíîïêà…'; FButtonRect := Rect(0, 0, 0, 0); end;
procedure TListBox.DrawItem(Index: Integer; Rect: TRect; State: TOwnerDrawState); begin FButtonRect := Rect; InflateRect(FButtonRect, -2, -2); if odSelected in State then begin FButtonRect.Left := FButtonRect.Right - 100; FButton.BoundsRect := FButtonRect; FButton.Visible := True; Canvas.Brush.Color := clHighlight; Canvas.Font.Color := clHighlightText; end else begin Canvas.Brush.Color := Color; Canvas.Font.Color := Font.Color; end; inherited DrawItem(Index, Rect, State); end;
|
Этот код даже как-то работает, но: первый раз ткнешь в элемент TListBox и кнопка показывается, а потом начинаешь тыкать в другие элементы из списка и кнопка при этом не появляется. Для того что бы появилась кнопка нужно мышкой навести на то место в котором кнопка должна предположительно быть, тогда кнопка появляется. |