设置菜单的ownerdraw属性为true
procedure TForm1.PopDrawItem(Sender: TMenuItem;
ACanvas: TCanvas;
ARect: TRect;
Selected: Boolean;
strOUt: String);
begin
if Selected then
begin
ACanvas.Font.Color := clBlack;
ACanvas.Brush.Color := $00ff00ff;
ACanvas.FillRect(ARect);
end
else
begin
ACanvas.Font.Color := clBlack;
ACanvas.Brush.Color := $0000ffff;
ACanvas.FillRect(ARect);
end;
ACanvas.TextOut(ARect.Left+15,ARect.Top,strOut);
end;
//菜单某一项的onDrawItem事件里面调用PopDrawItem函数
procedure TForm1.N31DrawItem(Sender: TObject;
ACanvas: TCanvas;
ARect: TRect;
Selected: Boolean);
begin
PopDrawItem(TMenuItem(Sender),ACanvas,ARect,Selected,'N31');
end;