窗体上放一MainMenu1,包含的菜单项为MenuItem1,MenuItem2...
设置为MainMenu的OwnerDraw为True,
MenuItem1的OnDrawItem事件:
procedure TForm1.MenuItem1DrawItem(Sender: TObject; ACanvas: TCanvas;
ARect: TRect; Selected: Boolean);
begin
ACanvas.FillRect(ARect);
ACanvas.Font.Size:=20; //设置为足够大的字号
ACanvas.Font.Name:='Times New Roman'; //设置为你喜欢的字体
//输出菜单项
ACanvas.TextOut(ARect.Left,ARect.Top,(Sender as TMenuItem).Caption);
end;
MenuItem1的OnMeasureItem事件:
procedure TForm1.MenuItem1MeasureItem(Sender: TObject; ACanvas: TCanvas;
var Width, Height: Integer);
begin
Height:=40; //设置为足够高以容纳你的菜单项
Width:=200; //设置为足够宽以容纳你的菜单项
end;
将其他菜单项的OnDrawItem设置为MenuItem1DrawItem
OnMeasureItem设置为MenuItem1DrawItem
上述代码在我的机器上(D6+Winxp)测试通过
设置为MainMenu的OwnerDraw为True,
MenuItem1的OnDrawItem事件:
procedure TForm1.MenuItem1DrawItem(Sender: TObject; ACanvas: TCanvas;
ARect: TRect; Selected: Boolean);
begin
ACanvas.FillRect(ARect);
ACanvas.Font.Size:=20; //设置为足够大的字号
ACanvas.Font.Name:='Times New Roman'; //设置为你喜欢的字体
//输出菜单项
ACanvas.TextOut(ARect.Left,ARect.Top,(Sender as TMenuItem).Caption);
end;
MenuItem1的OnMeasureItem事件:
procedure TForm1.MenuItem1MeasureItem(Sender: TObject; ACanvas: TCanvas;
var Width, Height: Integer);
begin
Height:=40; //设置为足够高以容纳你的菜单项
Width:=200; //设置为足够宽以容纳你的菜单项
end;
将其他菜单项的OnDrawItem设置为MenuItem1DrawItem
OnMeasureItem设置为MenuItem1DrawItem
上述代码在我的机器上(D6+Winxp)测试通过