成人午夜视频全免费观看高清-秋霞福利视频一区二区三区-国产精品久久久久电影小说-亚洲不卡区三一区三区一区

vb.net菜單 vb net

VB.net如何動(dòng)態(tài)獲取菜單欄中的菜單名并用樹型表示

添加:(先在加一個(gè)contextMenu,再它的添加子菜單的click事件編程)

創(chuàng)新互聯(lián)公司2013年開創(chuàng)至今,是專業(yè)互聯(lián)網(wǎng)技術(shù)服務(wù)公司,擁有項(xiàng)目成都網(wǎng)站設(shè)計(jì)、網(wǎng)站建設(shè)、外貿(mào)網(wǎng)站建設(shè)網(wǎng)站策劃,項(xiàng)目實(shí)施與項(xiàng)目整合能力。我們以讓每一個(gè)夢想脫穎而出為使命,1280元下花園做網(wǎng)站,已為上家服務(wù),為下花園各地企業(yè)和個(gè)人服務(wù),聯(lián)系電話:028-86922220

Try

’使TreeView可以被編輯

TreeView1.LabelEdit = True

‘判斷你是不是選定的是不可編輯的節(jié)點(diǎn),我這里工種節(jié)點(diǎn)不可以被編輯,只有工種下級(jí)的

各個(gè)工種名稱可以被編輯

If Trim(TreeView1.SelectedNode.Text) = "工種" Then

‘添加節(jié)點(diǎn)

AddNode = New TreeNode("請輸入新工種名字")

TreeView1.SelectedNode.Nodes.Add(AddNode)

TreeView1.ExpandAll()

AddNode.BeginEdit()

TreeView1.LabelEdit = True

NodeAdded = True

End If

Catch err As Exception

MsgBox(err.ToString)

End Try

刪除與添加類似,只是如果你的節(jié)點(diǎn)名字從其他處(如數(shù)據(jù)庫)得來,那么你還需要更新數(shù)據(jù)庫

編輯:

Private Sub TreeView1_BeforeLabelEdit(ByVal sender As Object, ByVal e As System.Windows.Forms.NodeLabelEditEventArgs) Handles TreeView1.BeforeLabelEdit

TreeView1.LabelEdit = True ‘使可以編輯

AddNode = TreeView1.SelectedNode

End Sub

Private Sub TreeView1_AfterLabelEdit(ByVal sender As Object, ByVal e As System.windows.Forms.NodeLabelEditEventArgs) Handles TreeView1.AfterLabelEdit

Try

‘此時(shí)你改完了節(jié)點(diǎn)名字

TreeView1.SelectedNode.EndEdit(True)

If e.Label Is Nothing Then

'do nothing

ElseIf e.Node.Text = "工種" Then ‘工種不能改

e.CancelEdit() = True

‘e.Node.Text ,e.Label.ToString 一個(gè)是改前的名字一個(gè)是該后的名字,具體哪個(gè)對

哪個(gè)請查MSDN

ElseIf Trim(e.Node.Text) "工種" And e.Node.Text e.Label.ToString Then

If MsgBox("此操作會(huì)導(dǎo)致當(dāng)前工種中的所有人員的工種都被更改,是否確定?", MsgBoxStyle.YesNo + MsgBoxStyle.Information, "警告") = MsgBoxResult.Yes Then

。。。。 ‘我的更改

MsgBox("更改成功!", MsgBoxStyle.OKOnly, "提示")

'Call InitTree() ‘有時(shí)要重新把treeview初始化一遍,視需求定

End If

End If

Catch err As Exception

MsgBox(err.ToString)

End Try

End Sub

其他:

擋treeview得到焦點(diǎn)時(shí)你可以使用ContextMenu,反之ContextMenu禁用

Private Sub TreeView1_GotFocus(ByVal sender As Object, ByVal e As System.EventArgs) Handles TreeView1.GotFocus

TreeView1.ContextMenu = ContextMenu1

End Sub

Private Sub TreeView1_LostFocus(ByVal sender As Object, ByVal e As System.EventArgs) Handles TreeView1.LostFocus

TreeView1.ContextMenu = Nothing

End Sub

注意:這里沒有在ContextMenu菜單添加“更改”項(xiàng),而是直接更改:即左鍵單擊節(jié)點(diǎn)表示

選中,再單擊一下就可以編輯了,更改之后單擊他處就完成更改,和你在windows中更改文

件名字相似。

VB.NET菜單設(shè)計(jì)初級(jí)入門[3]

五.繪制個(gè)性化菜單

先執(zhí)行以下操作步驟 下列步驟是通過菜單編輯器設(shè)計(jì)一個(gè)簡單的菜單 為后面重新繪制做基礎(chǔ)

啟動(dòng)Visual Studio Net

選擇菜單【文件】|【新建】|【項(xiàng)目】后 彈出【新建項(xiàng)目】對話框

將【項(xiàng)目類型】設(shè)置為【Visual Basic項(xiàng)目】

將【模板】設(shè)置為【W(wǎng)indows應(yīng)用程序】

在【名稱】文本框中輸入【自己畫菜單】

在【位置】的文本框中輸入【E:\VS NET項(xiàng)目】 然后單擊【確定】按鈕 這樣在 E:\VS NET項(xiàng)目 目錄中就產(chǎn)生了名稱為 自己畫菜單 的文件夾 并在里面創(chuàng)建了名稱為 自己畫菜單 的項(xiàng)目文件

把Visual Studio Net的當(dāng)前窗口切換到【Form vb(設(shè)計(jì))】窗口 并從【工具箱】中的【W(wǎng)indows窗體組件】選項(xiàng)卡中往Form 窗體中拖入下列組件

一個(gè)MainMenu組件 名稱為 MainMenu

選中 MainMenu 組件 單擊鼠標(biāo)右鍵 在彈出的菜單中選擇 編輯菜單 并按照圖 所示界面設(shè)計(jì)菜單

圖 【自己畫菜單】項(xiàng)目設(shè)計(jì)界面之一

此時(shí)保存上述步驟 并單擊快捷鍵F 則得到圖 所示界面

圖 【自己畫菜單】運(yùn)行界面之一

這樣通過菜單編輯器就完成了一個(gè)非常普通的菜單 下面就對此菜單進(jìn)行改造 在改造之前 要先設(shè)定項(xiàng)目中的三個(gè)MenuItem類實(shí)例的OwnerDraw屬性值為 True 因?yàn)橹挥写藢傩灾禐?True 才會(huì)觸發(fā)繪制菜單時(shí)所需要的DrawItem事件和MeasureItem事件 之后再在上面項(xiàng)目的基礎(chǔ)上執(zhí)行下一步操作

把Visual Stuido Net的當(dāng)前窗口切換到Form vb的代碼編輯窗口 并在InitializeComponent過程之后添加下列代碼 下列代碼是繪制 文件 菜單項(xiàng) 其作用是改變 文件 菜單項(xiàng)的字體 大小和菜單項(xiàng)的 其具體的繪制方法請參考下列代碼中的注釋

Private Sub MenuItem _DrawItem ( ByVal sender As Object ByVal e As System Windows Forms DrawItemEventArgs ) Handles MenuItem DrawItem Dim rfBound As RectangleF = New RectangleF ( e Bounds X e Bounds Y e Bounds Width e Bounds Height )  根據(jù)DrawItemEventArgs參數(shù)獲得菜單項(xiàng)矩形區(qū)域并存儲(chǔ)到RectangleF類型實(shí)例中 Dim rfBound As Rectangle = New Rectangle ( e Bounds X e Bounds Y e Bounds Width e Bounds Height )  根據(jù)DrawItemEventArgs參數(shù)獲得菜單項(xiàng)矩形區(qū)域并存儲(chǔ)到Rectangle類型實(shí)例中  Rectangle類型實(shí)例和RectangleF類型實(shí)例差不多 但在后面代碼中繪制菜單的函數(shù)是有區(qū)別的  e Graphics FillRectangle(New SolidBrush(Color LightGreen) rfBound) 以LightGreen色彩填充MenuItem 菜單項(xiàng)對應(yīng)的矩形區(qū)域 Dim s As MenuItem = CType ( sender MenuItem ) Dim s As String = s Text  獲得MenuItem 菜單項(xiàng)的名稱 Dim sfTemp As StringFormat = New StringFormat ( ) sfTemp Alignment = StringAlignment Center  設(shè)定要畫的菜單名稱的對齊方式 中間對齊 e Graphics DrawString ( s New Font ( 宋體 FontStyle Bold ) New SolidBrush ( Color Black ) rfBound sfTemp )  以中間對齊方式 指定字體 大小 在指定的矩形區(qū)域重畫菜單 If e State = ( DrawItemState NoAccelerator Or DrawItemState Selected ) Then 根據(jù)菜單項(xiàng)的當(dāng)前繪制狀態(tài)來繪制菜單項(xiàng) e Graphics FillRectangle ( New SolidBrush ( Color LightYellow ) rfBound ) 對菜單項(xiàng)所在的矩形區(qū)域進(jìn)行色彩填充 e Graphics DrawString ( s New Font ( 宋體 FontStyle Bold ) New SolidBrush ( Color Black ) rfBound sfTemp )  對菜單項(xiàng)名稱繪制 End If e DrawFocusRectangle ( )  在 DrawItemEventArgs參數(shù)得到矩形范圍內(nèi)繪制聚焦框  e Graphics DrawRectangle ( New Pen ( New SolidBrush ( Color Black ) ) rfBound )  對菜單項(xiàng)的矩形區(qū)域繪制矩形框End Sub

操作完成后 保存修改 此時(shí)再單擊快捷鍵F 運(yùn)行程序 可得到如圖 所示的界面

圖 【自己畫菜單】運(yùn)行界面之二

可見繪制的 文件 菜單項(xiàng)并沒有完全顯示出來 并且后面的菜單項(xiàng)也沒有顯示 這是因?yàn)椴藛雾?xiàng)的顯示區(qū)域并沒有設(shè)定 而缺省的空間又不能完全顯示造成的 設(shè)定菜單項(xiàng)的顯示區(qū)域大小是通過MeasureItem事件來完成的 具體操作是在MenuItem 的DrawItem事件后添加下列代碼 下列代碼是是定義MenuItem 的MeasureItem事件 在此事件中設(shè)定菜單項(xiàng)的寬度(當(dāng)然也可以設(shè)定高度等)

Private Sub MenuItem _MeasureItem ( ByVal sender As Object ByVal e As System Windows Forms MeasureItemEventArgs ) Handles MenuItem MeasureItem e ItemWidth =   設(shè)定菜單項(xiàng)的寬度End Sub

保存上述修改后 單擊快捷鍵F 運(yùn)行程序可得到圖 所示界面

圖 【自己畫菜單】運(yùn)行界面之三

可見 文件 菜單項(xiàng)就算繪制出來了 由于其他菜單項(xiàng)沒有繪制處理 所以也未顯示 其他菜單項(xiàng)的繪制方法和 文件 菜單項(xiàng)的繪制方法基本相似 以下是在上述完成的基礎(chǔ)上 對其他菜單項(xiàng)進(jìn)行繪制 從而得到圖 所示菜單的具體實(shí)現(xiàn)步驟

圖 【自己畫菜單】運(yùn)行界面之四

在Form vb中的MenuItem 的MeasureItem事件處理程序之后添加下列代碼 下列代碼是定義MenuItem 的DrawItem事件 其功能是對 新建 菜單項(xiàng)重新繪制

Private Sub MenuItem _DrawItem ( ByVal sender As Object ByVal e As System Windows Forms DrawItemEventArgs ) Handles MenuItem DrawItem Dim rfBound As RectangleF = New RectangleF ( e Bounds X e Bounds Y e Bounds Width e Bounds Height )   根據(jù)DrawItemEventArgs參數(shù)獲得菜單項(xiàng)矩形區(qū)域并存儲(chǔ)到RectangleF類型實(shí)例中 Dim rfBound As Rectangle = New Rectangle ( e Bounds X e Bounds Y e Bounds Width e Bounds Height )   根據(jù)DrawItemEventArgs參數(shù)獲得菜單項(xiàng)矩形區(qū)域并存儲(chǔ)到Rectangle類型實(shí)例中  Rectangle類型實(shí)例和RectangleF類型實(shí)例差不多 但在后面代碼中繪制菜單的函數(shù)是有區(qū)別的 e Graphics FillRectangle ( New SolidBrush ( Color LightGray ) rfBound )  Dim s As MenuItem = CType ( sender MenuItem )  Dim s As String = s Text  獲得菜單項(xiàng)對應(yīng)的文本名稱 Dim sfTemp As StringFormat = New StringFormat ( )  sfTemp Alignment = StringAlignment Center  設(shè)定文本在矩形區(qū)域的對齊方式 sfTemp LineAlignment = StringAlignment Center Dim rcText As RectangleF = rfBound rcText Width =  e Graphics DrawString ( s New Font ( 宋體 ) New SolidBrush ( Color Blue ) rcText sfTemp )  e Graphics DrawRectangle ( New Pen ( New SolidBrush ( Color LightGray ) ) rfBound )  If e State = ( DrawItemState NoAccelerator Or DrawItemState Selected ) Thene Graphics FillRectangle ( New SolidBrush ( Color LightYellow ) rfBound ) e Graphics DrawString ( s New Font ( 宋體 FontStyle Bold Or FontStyle Underline ) New SolidBrush ( Color Red ) rcText sfTemp ) e Graphics DrawRectangle ( New Pen ( New SolidBrush ( Color Black ) ) rfBound ) e DrawFocusRectangle ( )  End IfEnd Sub

MenuItem 的DrawItem事件處理代碼之后添加下列代碼 下列代碼是定義MenuItem 的MeasureItem事件 在此事件中實(shí)現(xiàn)設(shè)定 新建 菜單項(xiàng)的長度和高度

Private Sub MenuItem _MeasureItem ( ByVal sender As Object ByVal e As System Windows Forms MeasureItemEventArgs ) Handles MenuItem MeasureItem e ItemWidth =   設(shè)定菜單項(xiàng)的寬度 e ItemHeight =   設(shè)定菜單項(xiàng)的高度End Sub

在完成上述操作步驟后 再在MenuItem 的MeasureItem事件處理程序之后添加下列代碼 下列代碼是定義MenuItem 的DrawItem事件 其功能是對 打開 菜單項(xiàng)重新繪制

Private Sub MenuItem _DrawItem ( ByVal sender As Object ByVal e As System Windows Forms DrawItemEventArgs ) Handles MenuItem DrawItemDim rfBound As RectangleF = New RectangleF ( e Bounds X e Bounds Y e Bounds Width e Bounds Height ) 根據(jù)DrawItemEventArgs參數(shù)獲得菜單項(xiàng)矩形區(qū)域并存儲(chǔ)到RectangleF類型實(shí)例中Dim rfBound As Rectangle = New Rectangle ( e Bounds X e Bounds Y e Bounds Width e Bounds Height ) 根據(jù)DrawItemEventArgs參數(shù)獲得菜單項(xiàng)矩形區(qū)域并存儲(chǔ)到Rectangle類型實(shí)例中 Rectangle類型實(shí)例和RectangleF類型實(shí)例差不多 但在后面代碼中繪制菜單的函數(shù)是有區(qū)別的Dim s As MenuItem = CType ( sender MenuItem ) Dim s As String = s TextDim sfTemp As StringFormat = New StringFormat ( ) sfTemp Alignment = StringAlignment CentersfTemp LineAlignment = StringAlignment CenterDim rcText As RectangleF = rfBoundrcText Width = e Graphics DrawString ( s New Font ( Veranda ) New SolidBrush ( Color Blue ) rcText sfTemp ) e Graphics DrawRectangle ( New Pen ( New SolidBrush ( Color LightGray ) ) rfBound ) If e State = ( DrawItemState NoAccelerator Or DrawItemState Selected ) Then e Graphics FillRectangle ( New SolidBrush ( Color LightYellow ) rfBound )  e Graphics DrawString ( s New Font ( Veranda FontStyle Bold Or FontStyle Underline ) New SolidBrush ( Color Red ) rcText sfTemp )  e Graphics DrawRectangle ( New Pen ( New SolidBrush ( Color Black ) ) rfBound )  e DrawFocusRectangle ( ) End IfEnd Sub

MenuItem 的DrawItem事件處理代碼之后添加下列代碼 下列代碼是定義MenuItem 的MeasureItem事件 在此事件中實(shí)現(xiàn)設(shè)定 新建 菜單項(xiàng)的長度和高度

Private Sub MenuItem _MeasureItem ( ByVal sender As Object ByVal e As System Windows Forms MeasureItemEventArgs ) Handles MenuItem MeasureItem e ItemWidth =   設(shè)定菜單項(xiàng)的寬度 e ItemHeight =   設(shè)定菜單項(xiàng)的高度End Sub

在上述步驟都正確完成后 本文介紹的手工繪制菜單就完成 此時(shí)單擊快捷鍵F 運(yùn)行 程序就可以得到圖 所示的運(yùn)行界面

六.總結(jié)

本文主要內(nèi)容是介紹VB NET設(shè)計(jì)和創(chuàng)建菜單 其中不僅介紹了使用菜單設(shè)計(jì)器來靜態(tài)設(shè)計(jì)菜單 還介紹了使用MainMenu類 MenuItem類和ContextMenu類動(dòng)態(tài)創(chuàng)建菜單的實(shí)現(xiàn)方法 在動(dòng)態(tài)創(chuàng)建時(shí) 首先要了解要?jiǎng)?chuàng)建的菜單類型 是下拉菜單 首先要?jiǎng)?chuàng)建一個(gè)MainMenu實(shí)例 是彈出菜單 首先要?jiǎng)?chuàng)建一個(gè)ContextMenu實(shí)例 然后根據(jù)菜單中的組成結(jié)構(gòu) 即菜單項(xiàng)中的父子關(guān)系 創(chuàng)建出相應(yīng)菜單 最后就是顯示出菜單 如果是下拉菜單 指派給Form的Menu屬性 如果是彈出菜單 指派給可視組件或Form的ContextMenu屬性 這樣動(dòng)態(tài)創(chuàng)建菜單才能夠顯示出來 動(dòng)態(tài)創(chuàng)建菜單的工作才算完成

此外還介紹了在Visual Basic Net中繪制個(gè)性化菜單的實(shí)現(xiàn)方法和注意事項(xiàng) 在繪制個(gè)性化菜單時(shí)最重要的是掌握DrawItem事件和MeasureItem事件用法 及繪制菜單時(shí)所要使用到的方法 雖然本文繪制的菜單并不美觀 但你可以通過本文介紹的方法來修改 從而實(shí)現(xiàn)更美觀 更有個(gè)性的菜單 最后請記住 在繪制菜單時(shí) 首先把菜單項(xiàng)的 OwnerDraw 屬性設(shè)定為 True

lishixinzhi/Article/program/net/201311/15454

vb.net 如何添加菜單快捷鍵

ToolStripMenuItem.ShortcutKeys 屬性

獲取或設(shè)置與 ToolStripMenuItem 關(guān)聯(lián)的快捷鍵。

使用 ShortcutKeys 屬性可以將組合鍵分配給菜單命令,例如,將 Ctrl+C 分配給“復(fù)制”命令。 您可以使用快捷鍵而不使用訪問鍵,也可以同時(shí)使用快捷鍵和訪問鍵,訪問鍵是菜單或菜單項(xiàng)中與 Alt 鍵一起使用的帶下劃線的字母。 通過在要用于訪問鍵的字母前面鍵入一個(gè)“and”符 (),可以在代碼中定義訪問鍵。

vb.net外接程序不顯示菜單

系統(tǒng)bug,網(wǎng)絡(luò)問題。

1、系統(tǒng)bug是vb.net外接軟件系統(tǒng)出現(xiàn)了問題導(dǎo)致程序不顯示菜單,等待官方修復(fù)即可。

2、網(wǎng)絡(luò)問題是自身設(shè)備連接的網(wǎng)絡(luò)出現(xiàn)較大波動(dòng),導(dǎo)致vb.net外接程序不顯示菜單,更換網(wǎng)絡(luò)重新打開即可。

本文標(biāo)題:vb.net菜單 vb net
鏈接地址:http://jinyejixie.com/article44/dddhihe.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供外貿(mào)建站、App開發(fā)、Google做網(wǎng)站、網(wǎng)站導(dǎo)航移動(dòng)網(wǎng)站建設(shè)

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來源: 創(chuàng)新互聯(lián)

營銷型網(wǎng)站建設(shè)
甘谷县| 莆田市| 沿河| 清涧县| 富蕴县| 交城县| 成都市| 正阳县| 繁峙县| 延寿县| 云南省| 阳江市| 安国市| 濮阳县| 崇信县| 永定县| 墨竹工卡县| 洛南县| 闽侯县| 边坝县| 常熟市| 象州县| 萨迦县| 玉树县| 锡林浩特市| 凯里市| 宁强县| 台南县| 左权县| 托里县| 雷波县| 蕲春县| 平潭县| 新营市| 弥勒县| 蕉岭县| 新野县| 云霄县| 玛多县| 卓尼县| 赣州市|