使菜单有颜色如下
unit sample;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
Menus, ExtCtrls, StdCtrls;
type
TForm1 = class(TForm)
MainMenu1: TMainMenu;
aaa1: TMenuItem;
bbb1: TMenuItem;
ccc1: TMenuItem;
Image1: TImage;
ddd1: TMenuItem;
eee1: TMenuItem;
fff1: TMenuItem;
ggg1: TMenuItem;
hhhh1: TMenuItem;
iiii1: TMenuItem;
jjj1: TMenuItem;
ColoredMenuItem1: TMenuItem;
Coloritem11: TMenuItem;
Coloritem21: TMenuItem;
Coloritem31: TMenuItem;
Coloritem41: TMenuItem;
HHHH2: TMenuItem;
hhhh11: TMenuItem;
hhh21: TMenuItem;
hhh31: TMenuItem;
hhhh12: TMenuItem;
hhh22: TMenuItem;
hhh32: TMenuItem;
hhhh13: TMenuItem;
hhh23: TMenuItem;
hhh33: TMenuItem;
hhhh14: TMenuItem;
hhh24: TMenuItem;
hhh34: TMenuItem;
procedure ccc1MeasureItem(Sender: TObject; ACanvas: TCanvas; var Width,
Height: Integer);
procedure bbb1DrawItem(Sender: TObject; ACanvas: TCanvas; ARect: TRect;
Selected: Boolean);
procedure jjj1Click(Sender: TObject);
procedure Coloritem11DrawItem(Sender: TObject; ACanvas: TCanvas;
ARect: TRect; Selected: Boolean);
procedure Coloritem11MeasureItem(Sender: TObject; ACanvas: TCanvas;
var Width, Height: Integer);
procedure hhh31DrawItem(Sender: TObject; ACanvas: TCanvas;
ARect: TRect; Selected: Boolean);
procedure hhh34MeasureItem(Sender: TObject; ACanvas: TCanvas;
var Width, Height: Integer);
procedure Coloritem41Click(Sender: TObject);
procedure hhh34Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.DFM}
procedure TForm1.ccc1MeasureItem(Sender: TObject; ACanvas: TCanvas;
var Width, Height: Integer);
begin
height:=18;
width:=60;
acanvas.brush.Color:=clblue;
acanvas.TextOut(1,1,TMenuitem(sender).caption);
end;
procedure TForm1.bbb1DrawItem(Sender: TObject; ACanvas: TCanvas;
ARect: TRect; Selected: Boolean);
begin
acanvas.Draw(0,2,image1.picture.bitmap);
acanvas.TextOut(arect.left+image1.picture.bitmap.width+2,arect.top,tmenuitem(sender).caption);
end;
procedure TForm1.jjj1Click(Sender: TObject);
begin
showmessage('You clicked "'+Tmenuitem(sender).caption+'" Item'#13#10'Welcome to http://www.wapsec.com.cn/delphi/');
end;
procedure TForm1.Coloritem11DrawItem(Sender: TObject; ACanvas: TCanvas;
ARect: TRect; Selected: Boolean);
begin
Acanvas.brush.Color:=$00EBC596;
// Acanvas.FillRect(acanvas.cliprect);
Acanvas.Font.Color:=clblack;
if Selected then begin
Acanvas.brush.Color:=$00A00000;
Acanvas.Font.Color:=clwhite;
end;
Acanvas.TextOut(arect.left+5,arect.top,tmenuitem(sender).caption);
end;
procedure TForm1.Coloritem11MeasureItem(Sender: TObject; ACanvas: TCanvas;
var Width, Height: Integer);
begin
Height:=20;
end;
procedure TForm1.hhh31DrawItem(Sender: TObject; ACanvas: TCanvas;
ARect: TRect; Selected: Boolean);
var i:integer;
begin
Acanvas.brush.Color:=$00EBC596;
Acanvas.FillRect(acanvas.cliprect);
for i:=0 to HHHH2.Count-1 do begin
Acanvas.Font.Color:=clred;
Acanvas.TextOut(5,20*i,hhhh2.Items.caption);
end;
if Selected then begin
Acanvas.brush.Color:=$00A00000;
Acanvas.Font.Color:=clwhite;
end;
Acanvas.TextOut(arect.left+5,arect.top,tmenuitem(sender).caption);
end;
procedure TForm1.hhh34MeasureItem(Sender: TObject; ACanvas: TCanvas;
var Width, Height: Integer);
begin
height:=20;
end;
procedure TForm1.Coloritem41Click(Sender: TObject);
begin
showmessage('You clicked ColorMenuItem "'+Tmenuitem(sender).caption+'" Item'#13#10'Welcome to http://www.wapsec.com.cn/delphi/');
end;
procedure TForm1.hhh34Click(Sender: TObject);
begin
showmessage('You clicked "'+Tmenuitem(sender).caption+'" Item'#13#10'Welcome to http://www.wapsec.com.cn/delphi/');
end;
end.