很久以前写的一段:给你看看~<br>注意用bmp图片~<br><br>在form上放置Image1、MainMenu1。 <br>其中MainMenu1设了10几个菜单选项, 这可以根据你的图片的高度自己重新设置!<br>------------------------<br>unit Unit1;<br><br>interface<br><br>uses<br> Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,<br> Menus, jpeg, ExtCtrls, StdCtrls, Buttons; <br><br>type<br> TForm1 = class(TForm)<br> MainMenu1: TMainMenu;<br> main1: TMenuItem;<br> caption1: TMenuItem;<br> caption2: TMenuItem;<br> caption3: TMenuItem;<br> caption4: TMenuItem;<br> caption5: TMenuItem;<br> caption6: TMenuItem;<br> Image1: TImage;<br> caption61: TMenuItem;<br> caption81: TMenuItem;<br> caption62: TMenuItem;<br> caption63: TMenuItem;<br> caption64: TMenuItem;<br> caption65: TMenuItem;<br> caption66: TMenuItem;<br> N451: TMenuItem;<br> N23461: TMenuItem;<br> N231: TMenuItem;<br> N41: TMenuItem;<br> N51: TMenuItem;<br> N61: TMenuItem;<br> N71: TMenuItem;<br> N81: TMenuItem;<br> N91: TMenuItem;<br> N101: TMenuItem;<br> N111: TMenuItem;<br> N121: TMenuItem;<br> N131: TMenuItem;<br> N24351: TMenuItem;<br> N2561: TMenuItem;<br> N23462: TMenuItem;<br> N23471: TMenuItem;<br> N34561: TMenuItem;<br> N35761: TMenuItem;<br> N43561: TMenuItem;<br> N241: TMenuItem;<br> N23463: TMenuItem;<br> N2351: TMenuItem;<br> N23464: TMenuItem;<br> N1231: TMenuItem;<br> N45761: TMenuItem;<br> N23465: TMenuItem;<br> procedure caption1MeasureItem(Sender: TObject; ACanvas: TCanvas;<br> var Width, Height: Integer);<br> procedure caption2MeasureItem(Sender: TObject; ACanvas: TCanvas;<br> var Width, Height: Integer);<br> procedure caption3MeasureItem(Sender: TObject; ACanvas: TCanvas;<br> var Width, Height: Integer);<br> procedure caption4MeasureItem(Sender: TObject; ACanvas: TCanvas;<br> var Width, Height: Integer);<br> procedure caption5MeasureItem(Sender: TObject; ACanvas: TCanvas;<br> var Width, Height: Integer);<br> procedure caption6MeasureItem(Sender: TObject; ACanvas: TCanvas;<br> var Width, Height: Integer);<br> procedure caption1DrawItem(Sender: TObject; ACanvas: TCanvas;<br> ARect: TRect; Selected: Boolean);<br> procedure caption2DrawItem(Sender: TObject; ACanvas: TCanvas;<br> ARect: TRect; Selected: Boolean);<br> procedure caption3DrawItem(Sender: TObject; ACanvas: TCanvas;<br> ARect: TRect; Selected: Boolean);<br> procedure caption4DrawItem(Sender: TObject; ACanvas: TCanvas;<br> ARect: TRect; Selected: Boolean);<br> procedure caption5DrawItem(Sender: TObject; ACanvas: TCanvas;<br> ARect: TRect; Selected: Boolean);<br> procedure caption6DrawItem(Sender: TObject; ACanvas: TCanvas;<br> ARect: TRect; Selected: Boolean);<br> procedure caption61DrawItem(Sender: TObject; ACanvas: TCanvas;<br> ARect: TRect; Selected: Boolean);<br> procedure caption81DrawItem(Sender: TObject; ACanvas: TCanvas;<br> ARect: TRect; Selected: Boolean);<br> procedure caption62DrawItem(Sender: TObject; ACanvas: TCanvas;<br> ARect: TRect; Selected: Boolean);<br> procedure caption64DrawItem(Sender: TObject; ACanvas: TCanvas;<br> ARect: TRect; Selected: Boolean);<br> procedure caption63DrawItem(Sender: TObject; ACanvas: TCanvas;<br> ARect: TRect; Selected: Boolean);<br> procedure caption66DrawItem(Sender: TObject; ACanvas: TCanvas;<br> ARect: TRect; Selected: Boolean);<br> procedure caption65DrawItem(Sender: TObject; ACanvas: TCanvas;<br> ARect: TRect; Selected: Boolean);<br> procedure caption61MeasureItem(Sender: TObject; ACanvas: TCanvas;<br> var Width, Height: Integer);<br> procedure caption81MeasureItem(Sender: TObject; ACanvas: TCanvas;<br> var Width, Height: Integer);<br> procedure caption62MeasureItem(Sender: TObject; ACanvas: TCanvas;<br> var Width, Height: Integer);<br> procedure caption64MeasureItem(Sender: TObject; ACanvas: TCanvas;<br> var Width, Height: Integer);<br> procedure caption63MeasureItem(Sender: TObject; ACanvas: TCanvas;<br> var Width, Height: Integer);<br> procedure caption66MeasureItem(Sender: TObject; ACanvas: TCanvas;<br> var Width, Height: Integer);<br> procedure caption65MeasureItem(Sender: TObject; ACanvas: TCanvas;<br> var Width, Height: Integer);<br> procedure BitBtn1Click(Sender: TObject);<br> private<br> { Private declarations }<br> public<br> //自定义<br> procedure DrawItem(Sender: TMenuItem; ACanvas: TCanvas;<br> ARect: TRect; Selected: Boolean;StrOut:String);<br> { Public declarations }<br> end;<br><br>var<br> Form1: TForm1;<br> i,ih,ind,iw,irate:integer;<br> rtemp:trect;<br> ig1,ig2:integer;<br>implementation<br><br>{$R *.DFM}<br>procedure TForm1.DrawItem(Sender: TMenuItem; ACanvas: TCanvas;<br> ARect: TRect; Selected: Boolean;StrOut:String);<br>var j:integer;<br>begin<br> i:=arect.Bottom-arect.Top;<br> ind:=sender.MenuIndex;<br> ih:=round(image1.Height/13*ind);<br> stretchBlt(acanvas.Handle,arect.Left,arect.Top,iw,i,image1.Canvas.Handle,0,ih,image1.Width,round(image1.Height/13),srccopy);<br> if selected then<br> begin<br> acanvas.Font.Color:=clwhite;<br> rtemp:=arect;<br> rtemp.Left:=rtemp.Left+iw;<br> ig1:=round((rtemp.Right-rtemp.Left)/10);<br> rtemp.Right:=rtemp.Left+ig1;<br> for j:=0 to 9 do<br> begin<br> acanvas.Brush.Color:=rgb(0,0,j*25);<br> acanvas.FillRect(rtemp);<br> rtemp.Left:=rtemp.Left+ig1;<br> rtemp.Right:=rtemp.Left+ig1;<br> end;<br> end<br> else<br> begin<br> acanvas.Brush.Color:=cl3dlight;<br> rtemp:=arect;<br> rtemp.Left:=rtemp.Left+iw;<br> acanvas.FillRect(rtemp);<br> acanvas.Font.Color:=clblack;<br> end;<br> acanvas.Brush.Style:=bsclear;<br> acanvas.TextOut(arect.Left+iw+5,arect.Top,strout);<br>end;<br><br>procedure TForm1.caption1MeasureItem(Sender: TObject; ACanvas: TCanvas;<br> var Width, Height: Integer);<br>begin<br>height:=acanvas.TextHeight('caption1')+5;<br>width:=acanvas.TextWidth('caption1')+50;<br>irate:=round(image1.height/(height*13));<br>iw:=round(image1.width/irate);<br>width:=width+iw;<br>end;<br><br>procedure TForm1.caption2MeasureItem(Sender: TObject; ACanvas: TCanvas;<br> var Width, Height: Integer);<br>begin<br>height:=acanvas.TextHeight('caption1')+5;<br>width:=acanvas.TextWidth('caption1')+50;<br>irate:=round(image1.height/(height*13));<br>iw:=round(image1.width/irate);<br>width:=width+iw;<br>end;<br><br>procedure TForm1.caption3MeasureItem(Sender: TObject; ACanvas: TCanvas;<br> var Width, Height: Integer);<br>begin<br>height:=acanvas.TextHeight('caption1')+5;<br>width:=acanvas.TextWidth('caption1')+5;<br>irate:=round(image1.height/(height*13));<br>iw:=round(image1.width/irate);<br>width:=width+iw;<br>end;<br><br>procedure TForm1.caption4MeasureItem(Sender: TObject; ACanvas: TCanvas;<br> var Width, Height: Integer);<br>begin<br>height:=acanvas.TextHeight('caption1')+5;<br>width:=acanvas.TextWidth('caption1')+5;<br>irate:=round(image1.height/(height*13));<br>iw:=round(image1.width/irate);<br>width:=width+iw;<br>end;<br><br>procedure TForm1.caption5MeasureItem(Sender: TObject; ACanvas: TCanvas;<br> var Width, Height: Integer);<br>begin<br>height:=acanvas.TextHeight('caption1')+5;<br>width:=acanvas.TextWidth('caption1')+5;<br>irate:=round(image1.height/(height*13));<br>iw:=round(image1.width/irate);<br>width:=width+iw;<br>end;<br><br>procedure TForm1.caption6MeasureItem(Sender: TObject; ACanvas: TCanvas;<br> var Width, Height: Integer);<br>begin<br>height:=acanvas.TextHeight('caption1')+5;<br>width:=acanvas.TextWidth('caption1')+5;<br>irate:=round(image1.height/(height*13));<br>iw:=round(image1.width/irate);<br>width:=width+iw;<br>end;<br><br>procedure TForm1.caption1DrawItem(Sender: TObject; ACanvas: TCanvas;<br> ARect: TRect; Selected: Boolean);<br>begin<br>DrawItem(TMenuItem(Sender),ACanvas,ARect,Selected,'234643623562346');<br>end;<br><br>procedure TForm1.caption2DrawItem(Sender: TObject; ACanvas: TCanvas;<br> ARect: TRect; Selected: Boolean);<br>begin<br>DrawItem(TMenuItem(Sender),ACanvas,ARect,Selected,'Caption2');<br>end;<br><br>procedure TForm1.caption3DrawItem(Sender: TObject; ACanvas: TCanvas;<br> ARect: TRect; Selected: Boolean);<br>begin<br>DrawItem(TMenuItem(Sender),ACanvas,ARect,Selected,'Caption3');<br>end;<br><br>procedure TForm1.caption4DrawItem(Sender: TObject; ACanvas: TCanvas;<br> ARect: TRect; Selected: Boolean);<br>begin<br>DrawItem(TMenuItem(Sender),ACanvas,ARect,Selected,'Caption4');<br>end;<br><br>procedure TForm1.caption5DrawItem(Sender: TObject; ACanvas: TCanvas;<br> ARect: TRect; Selected: Boolean);<br>begin<br>DrawItem(TMenuItem(Sender),ACanvas,ARect,Selected,'Caption5');<br>end;<br><br>procedure TForm1.caption6DrawItem(Sender: TObject; ACanvas: TCanvas;<br> ARect: TRect; Selected: Boolean);<br>begin<br>DrawItem(TMenuItem(Sender),ACanvas,ARect,Selected,'Caption6');<br>end;<br><br>procedure TForm1.caption61DrawItem(Sender: TObject; ACanvas: TCanvas;<br> ARect: TRect; Selected: Boolean);<br>begin<br>DrawItem(TMenuItem(Sender),ACanvas,ARect,Selected,'Caption7');<br>end;<br><br>procedure TForm1.caption81DrawItem(Sender: TObject; ACanvas: TCanvas;<br> ARect: TRect; Selected: Boolean);<br>begin<br>DrawItem(TMenuItem(Sender),ACanvas,ARect,Selected,'Caption8');<br>end;<br><br>procedure TForm1.caption62DrawItem(Sender: TObject; ACanvas: TCanvas;<br> ARect: TRect; Selected: Boolean);<br>begin<br>DrawItem(TMenuItem(Sender),ACanvas,ARect,Selected,'Caption9');<br>end;<br><br>procedure TForm1.caption64DrawItem(Sender: TObject; ACanvas: TCanvas;<br> ARect: TRect; Selected: Boolean);<br>begin<br>DrawItem(TMenuItem(Sender),ACanvas,ARect,Selected,'Caption10');<br>end;<br><br>procedure TForm1.caption63DrawItem(Sender: TObject; ACanvas: TCanvas;<br> ARect: TRect; Selected: Boolean);<br>begin<br>DrawItem(TMenuItem(Sender),ACanvas,ARect,Selected,'Caption11');<br>end;<br><br>procedure TForm1.caption66DrawItem(Sender: TObject; ACanvas: TCanvas;<br> ARect: TRect; Selected: Boolean);<br>begin<br>DrawItem(TMenuItem(Sender),ACanvas,ARect,Selected,'Caption12');<br>end;<br><br>procedure TForm1.caption65DrawItem(Sender: TObject; ACanvas: TCanvas;<br> ARect: TRect; Selected: Boolean);<br>begin<br>DrawItem(TMenuItem(Sender),ACanvas,ARect,Selected,'Caption13');<br>end;<br><br>procedure TForm1.caption61MeasureItem(Sender: TObject; ACanvas: TCanvas;<br> var Width, Height: Integer);<br>begin<br>height:=acanvas.TextHeight('caption1')+5;<br>width:=acanvas.TextWidth('caption1')+5;<br>irate:=round(image1.height/(height*13));<br>iw:=round(image1.width/irate);<br>width:=width+iw;<br>end;<br><br>procedure TForm1.caption81MeasureItem(Sender: TObject; ACanvas: TCanvas;<br> var Width, Height: Integer);<br>begin<br>height:=acanvas.TextHeight('caption1')+5;<br>width:=acanvas.TextWidth('caption1')+5;<br>irate:=round(image1.height/(height*13));<br>iw:=round(image1.width/irate);<br>width:=width+iw;<br>end;<br><br>procedure TForm1.caption62MeasureItem(Sender: TObject; ACanvas: TCanvas;<br> var Width, Height: Integer);<br>begin<br>height:=acanvas.TextHeight('caption1')+5;<br>width:=acanvas.TextWidth('caption1')+5;<br>irate:=round(image1.height/(height*13));<br>iw:=round(image1.width/irate);<br>width:=width+iw;<br>end;<br><br>procedure TForm1.caption64MeasureItem(Sender: TObject; ACanvas: TCanvas;<br> var Width, Height: Integer);<br>begin<br>height:=acanvas.TextHeight('caption1')+5;<br>width:=acanvas.TextWidth('caption1')+5;<br>irate:=round(image1.height/(height*13));<br>iw:=round(image1.width/irate);<br>width:=width+iw;<br>end;<br><br>procedure TForm1.caption63MeasureItem(Sender: TObject; ACanvas: TCanvas;<br> var Width, Height: Integer);<br>begin<br>height:=acanvas.TextHeight('caption1')+5;<br>width:=acanvas.TextWidth('caption1')+5;<br>irate:=round(image1.height/(height*13));<br>iw:=round(image1.width/irate);<br>width:=width+iw;<br>end;<br><br>procedure TForm1.caption66MeasureItem(Sender: TObject; ACanvas: TCanvas;<br> var Width, Height: Integer);<br>begin<br>height:=acanvas.TextHeight('caption1')+5;<br>width:=acanvas.TextWidth('caption1')+5;<br>irate:=round(image1.height/(height*13));<br>iw:=round(image1.width/irate);<br>width:=width+iw;<br>end;<br><br>procedure TForm1.caption65MeasureItem(Sender: TObject; ACanvas: TCanvas;<br> var Width, Height: Integer);<br>begin<br>height:=acanvas.TextHeight('caption1')+5;<br>width:=acanvas.TextWidth('caption1')+5;<br>irate:=round(image1.height/(height*13));<br>iw:=round(image1.width/irate);<br>width:=width+iw;<br>end;<br><br>end.<br>----------------------------------<br>等于重新绘制菜单! 将图片一块一块画上去的,能实现你要求的功能! <br><br>D6 下通过! 其中有代码冗余,你自己可以优化一下! <br>