我用的是DELPHI7 我想知道怎么样可以直接写代码把菜单做成XP风格的
解决方案 »
- 高分求自定义gina的例子,屏蔽开机启动界面的,直接进入某软件界面
- 又是一个很简单的问题。
- aspack为什么能给程序减肥?
- 如何用Delphi启/禁用服务程序,主意不是启动,顺便问下SPI是什么,听说是网络,哪里又有资料那
- 找工程师 --DELPHI/SQLSERVER
- 都来看看,这是在MDI的子窗口退出问题。
- 奇怪,奇怪,真奇怪。按MDI子窗体的关闭按钮为何该子窗体不关闭而是最小化了呢?用CLOSE方法同样是进行了最小化。
- Table的简单问题
- 祝各位老鸟、大鸟、小鸟、菜鸟新年快乐!(散分)
- 这到底是怎么回事啊?
- 毕业设计搞什么课题好?
- ###### 如何让报表一条一条显示? 在线等待!! #######
这里有问必答
http://systemer.51.net/cgi-bin/leoboard.cgi
希望你能在这里找到你满意的答案!
Windows, Messages,SysUtils, Classes,Menus,Graphics;type
TXPMenu = class(TComponent)
private
{ Private declarations }
FSelColor,FBdyColor,FIcnColor,FFntColor:TColor;
procedure SetSelColor(SelColor:TColor);
function GetSelColor:TColor;
procedure SetBdyColor(BdyColor:TColor);
function GetBdyColor:TColor;
procedure SetFntColor(FntColor:TColor);
function GetFntColor:TColor;
procedure SetIcnColor(IcnColor:TColor);
function GetIcnColor:TColor;
procedure DrawItem(Sender: TObject; ACanvas: TCanvas;
ARect: TRect; Selected: Boolean);
procedure MeasureItem(Sender: TObject; ACanvas: TCanvas;
var Width, Height: Integer);
protected
{ Protected declarations }
public
{ Public declarations } constructor Create(AOwner:TComponent);override;
published
{ Published declarations }
property BodyColor:TColor read GetBdyColor write SetBdyColor;
property SelectedColor:TColor read GetSelColor write SetSelColor;
property FontColor:TColor read GetFntColor write SetFntColor;
property GlyphColor:TColor read GetIcnColor write SetIcnColor;
end;procedure Register;implementationprocedure Register;
begin
RegisterComponents('Snake_Eye', [TXPMenu]);
end;{ TXPMenu }procedure TXPMenu.MeasureItem(Sender: TObject; ACanvas: TCanvas;
var Width, Height: Integer);
var
Txt:String;
begin
ACanvas.Font.Size:=8;
Txt:=(Sender as TMenuItem).Caption;
Width :=ACanvas.TextWidth(Txt)+20;
Height:=ACanvas.TextHeight(Txt)+6;
if Txt='-' then
Height:=ACanvas.TextHeight(Txt) div 2;
end;constructor TXPMenu.Create(AOwner: TComponent);
var
icount:integer;
begin
inherited create(AOwner);
FBdyColor:=$00E6E6E6;
FIcnColor:=$0074F1B9;
FFntColor:=clBlack;
FSelColor:=$00FFD8CE;
for icount:=0 to Owner.ComponentCount-1 do
begin
if Owner.Components[icount] Is TMenu then
(Owner.Components[icount] as TMenu).OwnerDraw:=True;
if Owner.Components[icount] Is TMenuItem then
begin
(Owner.Components[icount] as TMenuItem).OnDrawItem:=DrawItem;
(Owner.Components[icount] as TMenuItem).OnMeasureItem:=MeasureItem;
end;
end;
end;procedure TXPMenu.DrawItem(Sender: TObject; ACanvas: TCanvas; ARect: TRect;
Selected: Boolean);
var
MenuItem:TMenuItem;
IcnRect,TxtRect:TRect;
Txt:String;
B:TBitmap;
icount:integer;
IsTopItem:Boolean;
begin
MenuItem:=Sender as TMenuItem;
Txt:=MenuItem.Caption;
IcnRect:=Rect(ARect.Left,ARect.Top, ARect.Left+20,ARect.Bottom);
TxtRect:=Rect(ARect.Left+22,ARect.Top,ARect.Right,ARect.Bottom);
IsTopItem:=False;
if MenuItem.GetParentMenu Is TMainMenu then
for icount:=0 to MenuItem.GetParentMenu.Items.Count-1 do
if MenuItem.GetParentMenu.Items[icount]=MenuItem then
begin
IsTopItem:=True;
break;
end;
if IsTopItem then
begin
ACanvas.Brush.Color:=clBtnFace;
ACanvas.Pen.Color:=clBtnFace;
ACanvas.Rectangle(IcnRect);
end
else
begin
ACanvas.Brush.Color:=FIcnColor;
ACanvas.Pen.Color:=FIcnColor;
ACanvas.Rectangle(IcnRect);
ACanvas.Brush.Color:=FBdyColor;
ACanvas.Pen.Color:=FBdyColor;
end;
ACanvas.Rectangle(TxtRect.Left-2,TxtRect.Top,TxtRect.Right,TxtRect.Bottom);
if Selected then
begin
ACanvas.Brush.Color:=FSelColor;
ACanvas.Pen.Color :=clBlack;
ACanvas.Rectangle(ARect);
end;
if Txt='-' then
begin
ACanvas.Pen.Width :=1;
ACanvas.Pen.Color:=clGray;
ACanvas.MoveTo(TxtRect.Left -1 ,TxtRect.Top+(TxtRect.Bottom-TxtRect.Top) div 2);
ACanvas.LineTo(TxtRect.Right-2 ,TxtRect.Top+(TxtRect.Bottom-TxtRect.Top) div 2);
end
else
begin
ACanvas.Font.Size:=8;
if MenuItem.Enabled then
ACanvas.Font.Color:=FFntColor
else
ACanvas.Font.Color:=clGray;
SetBkMode(ACanvas.Handle,Transparent);
DrawText(ACanvas.Handle,
Pchar(Txt),
Length(Txt),
TxtRect,
DT_VCenter or DT_Left or DT_SingleLine );
end;
if MenuItem.Checked then
begin
ACanvas.Pen.Color :=clGray;
ACanvas.Pen.Width :=1;
ACanvas.Polyline([Point(IcnRect.Left+2 ,IcnRect.Bottom-2),
Point(IcnRect.Left+2 ,IcnRect.Top+2 ),
Point(IcnRect.Right-2,IcnRect.Top+2 )]);
ACanvas.Pen.Color :=clWhite;
ACanvas.Pen.Width :=1;
ACanvas.Polyline([Point(IcnRect.Right-2,IcnRect.Top+2 ),
Point(IcnRect.Right-2,IcnRect.Bottom-2),
Point(IcnRect.Left+2 ,IcnRect.Bottom-2)]);
ACanvas.Pen.Color :=clRed ;
ACanvas.Pen.Width :=2;
ACanvas.Polyline([Point(IcnRect.Left+4 ,IcnRect.Top+10 ),
Point(IcnRect.Left+8 ,IcnRect.Top+14 ),
Point(IcnRect.Right-5,IcnRect.Top+5 )]);
end
else if (MenuItem.GetParentMenu.Images<>nil)and(Txt<>'-') then
begin
B:=TBitmap.Create;
B.Transparent:=True;
MenuItem.GetParentMenu.Images.GetBitmap(MenuItem.ImageIndex,B);
IcnRect:=Rect(IcnRect.Left+2,IcnRect.Top+2,IcnRect.Right-2,IcnRect.Bottom-2);
ACanvas.StretchDraw(IcnRect,B);
B.Free;
end;
end;function TXPMenu.GetSelColor: TColor;
begin
Result:=FSelColor;
end;procedure TXPMenu.SetSelColor(SelColor: TColor);
begin
FSelColor:=SelColor;
end;function TXPMenu.GetBdyColor: TColor;
begin
Result:=FBdyColor;
end;procedure TXPMenu.SetBdyColor(BdyColor: TColor);
begin
FBdyColor:=BdyColor;
end;function TXPMenu.GetFntColor: TColor;
begin
Result:=FFntColor;
end;procedure TXPMenu.SetFntColor(FntColor: TColor);
begin
FFntColor:=FntColor;
end;function TXPMenu.GetIcnColor: TColor;
begin
Result:=FIcnColor;
end;procedure TXPMenu.SetIcnColor(IcnColor: TColor);
begin
FIcnColor:=IcnColor;
end;end.
使用方法非常简单,只要将Active属性设为True即可。