运气不错,昨天刚好有人叫我帮他做此功能:
1.MainMenu1.Ondraw := True;
2.MainMenu1.AutoHotKeys:=maManual;
3.随便在一个菜单项的OnDrawItem写下如下代码
procedure TForm1.gsdagf1DrawItem(Sender: TObject;
ACanvas: TCanvas;
ARect: TRect;
Selected: Boolean);
begin
SetCanvasFont(ACanvas, '宋体', 11, clRed, [fsBold]);
ACanvas.TextOut(ARect.Left, ARect.Top, (Sender as TMenuItem).Caption);
end;
4.{其它代码:}
procedure TForm1.SetCanvasFont(ACanvas: TCanvas;
sFontName: String;
iFontSize, iFontColor: Integer;
fsStyle: TFontStyles);
begin
with ACanvas.Font do
begin
Name := sFontName;
Size := iFontSize;
Color := iFontColor;
Style := fsStyle;
end;
end;
procedure TForm1.DrawMenuItem;
var
i,j: integer;
begin
for i := 0 to MainMenu1.Items.Count - 1 do
begin
MainMenu1.Items.OnDrawItem := gsdagf1DrawItem;
for j := 0 to MainMenu1.Items.Count - 1do
MainMenu1.Items.Items[j].OnDrawItem := gsdagf1DrawItem;
//指向菜单自画事件
end;
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
DrawMenuItem;
end;