国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > .NET > 正文

講解:自己做出VS.NET風格的右鍵菜單

2024-07-10 13:08:36
字體:
來源:轉載
供稿:網友

  自己做出vs.net風格的右鍵菜單(簡單,實用)

  此主題相關圖片如下:class mymenuitem : system.windows.forms.menuitem


public mymenuitem() 

//這里很重要,必須把owerdraw設為true,這樣可以自己畫菜單,否則便是讓操作系統畫菜單了,默認的是false 
this.ownerdraw=true; 

protected override void ondrawitem(sysdrawitemeventargs e) 

//要重畫菜單,是沒有onpaint方法重載的,只有重載ondrawitem方法! 
graphics g=e.graphics; 
g.smoothingmode=smoothingmode.antialias;//抗鋸齒 
font f = new font(fontfamily.genericserif, 12, fontstyle.regular, graphicsunit.pixel);//設定菜單的字體 
pen p=new pen(color.navy,1);//這是畫邊框的字體 
if(e.state==drawitemstate.noaccelerator)//一開始右鍵單擊出現菜單,但是鼠標并沒有移上去 
{ //用白色的底色 
g.fillrectangle(brushes.whitesmoke,e.bounds.x-2,e.bounds.y-2,121,23); 

//鼠標移上去,但是并沒有單擊 
if ((e.state &drawitemstate.selected)==drawitemstate.selected) 

//花邊框和底色 
g.fillrectangle(brushes.lightsteelblue,e.bounds.x,e.bounds.y,109,20); 
g.drawline(p,e.bounds.x,e.bounds.y,e.bounds.x,e.bounds.y+19); 
g.drawline(p,e.bounds.x,e.bounds.y+19,e.bounds.x+109,e.bounds.y+19); 
g.drawline(p,e.bounds.x+109,e.bounds.y+19,e.bounds.x+109,e.bounds.y); 
g.drawline(p,e.bounds.x+109,e.bounds.y,e.bounds.x,e.bounds.y); 

//顯示文字 
g.drawstring(this.text,f,brushes.black,e.bounds.x,e.bounds.y); 
g.dispose(); 

//這是很重要的,這給你的菜單定義了大小,高20,寬100,否則你的菜單什么也看不到 
protected override void onmeasureitem(measureitemeventargs e) 

e.itemheight=20; 
e.itemwidth=100; 

  說明:這里我沒有畫按鈕按下時的樣子(懶:),主要是以后進一步改進),當然也沒有畫圖標,也是為了以后改進,這只是一個初步的形態,大家看看有什么更高的方法?!

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 都安| 松滋市| 兰溪市| 邛崃市| 安康市| 舒城县| 东源县| 东港市| 阳朔县| 凤台县| 墨脱县| 米泉市| 镇巴县| 衡南县| 漯河市| 鄱阳县| 开远市| 巴彦淖尔市| 黄大仙区| 巴青县| 清远市| 达日县| 沈阳市| 吴旗县| 黄大仙区| 龙山县| 得荣县| 花莲县| 富锦市| 建昌县| 台南市| 东兰县| 前郭尔| 江源县| 浪卡子县| 茶陵县| 滦南县| 玉山县| 定陶县| 甘洛县| 科尔|