我有一个关于TPopoupMenu和OwnerDraw的问题。我正在尝试做一些自定义绘图,并将OwnerDraw设置为true并分配了事件处理函数OnDrawItem。我编程调用MyPopup.Popup(X,Y),但OnDrawItem永远不会被调用。我在这里做错了什么?TMenuItem自动绘图时调用PopUp
感谢您的帮助。
编辑:
我进一步发现显示出,有一些问题,使用VCL样式时。我分配了OnDrawItem和OnMeasureItem。现在这些处理程序被调用。实现OnDrawItem的常规方法不起作用,所以我尝试使用VCL样式,但我的弹出菜单不显示任何文本。
我的事件处理程序代码(的OnDrawItem):
procedure TMyDisplay.EngineMenuDraw(Sender: TObject; ACanvas: TCanvas; ARect: TRect; Selected: Boolean);
var LStyles: TCustomStyleServices;
Text: string;
const
ColorStates: array[Boolean] of TStyleColor = (scComboBoxDisabled, scComboBox);
FontColorStates: array[Boolean] of TStyleFont = (sfPopupMenuItemTextDisabled, sfPopupMenuItemTextNormal);
begin
LStyles := StyleServices;
Text := (Sender as TMenuItem).Caption;
ACanvas.Brush.Color := LStyles.GetStyleColor(ColorStates[(Sender as TMenuItem).Enabled]);
ACanvas.Font.Color := LStyles.GetStyleFontColor(FontColorStates[(Sender as TMenuItem).Enabled]);
if Selected then
begin
ACanvas.Brush.Color := LStyles.GetSystemColor(clHighlight);
ACanvas.Font.Color := LStyles.GetSystemColor(clHighlightText);
end;
ACanvas.FillRect(ARect);
ACanvas.TextOut(ARect.Left + 2, ARect.Top, Text);
end;
这应该工作。你确定你有分配给你的处理程序的'OnDrawItem'事件吗? – TLama 2014-10-27 15:42:11
是的,我确定。我检查出每个项目都设置了事件处理程序。 – Nix 2014-10-27 20:42:06