• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

VB.NET ToolStripDropDownItem类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了VB.NET中System.Windows.Forms.ToolStripDropDownItem的典型用法代码示例。如果您正苦于以下问题:VB.NET ToolStripDropDownItem类的具体用法?VB.NET ToolStripDropDownItem怎么用?VB.NET ToolStripDropDownItem使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



在下文中一共展示了ToolStripDropDownItem类的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的VB.NET代码示例。

示例1: Form1

' 导入命名空间
Imports System.Collections.Generic
Imports System.ComponentModel
Imports System.Drawing
Imports System.Windows.Forms

Public Class Form1
   Inherits Form
   Private toolStrip1 As ToolStrip
   Private statusStrip1 As StatusStrip
   Private toolStripStatusLabel1 As ToolStripStatusLabel
   Private contextMenuStrip1 As ContextMenuStrip
   Private menuItem1ToolStripMenuItem As ToolStripMenuItem
   Private menuItem2ToolStripMenuItem As ToolStripMenuItem
   Private subItemToolStripMenuItem As ToolStripMenuItem
   Private subItem2ToolStripMenuItem As ToolStripMenuItem
   Private WithEvents showButton As Button
   Private WithEvents hideButton As Button
   Private components As System.ComponentModel.IContainer = Nothing
   
   
   Public Sub New()
      InitializeComponent()
      Me.InitializeToolStripDropDownItems()
    End Sub
   
   ' This utility method creates and initializes three 
   ' ToolStripDropDownItem controls and adds them 
   ' to the form's ToolStrip control.
   Private Sub InitializeToolStripDropDownItems()
      Dim b As New ToolStripDropDownButton("DropDownButton")
      b.DropDown = Me.contextMenuStrip1
      AddHandler b.DropDownClosed, AddressOf toolStripDropDownItem_DropDownClosed
      AddHandler b.DropDownItemClicked, AddressOf toolStripDropDownItem_DropDownItemClicked
      AddHandler b.DropDownOpened, AddressOf toolStripDropDownItem_DropDownOpened
      
      Dim m As New ToolStripMenuItem("MenuItem")
      m.DropDown = Me.contextMenuStrip1
      AddHandler m.DropDownClosed, AddressOf toolStripDropDownItem_DropDownClosed
      AddHandler m.DropDownItemClicked, AddressOf toolStripDropDownItem_DropDownItemClicked
      AddHandler m.DropDownOpened, AddressOf toolStripDropDownItem_DropDownOpened
      
      Dim sb As New ToolStripSplitButton("SplitButton")
      sb.DropDown = Me.contextMenuStrip1
      AddHandler sb.DropDownClosed, AddressOf toolStripDropDownItem_DropDownClosed
      AddHandler sb.DropDownItemClicked, AddressOf toolStripDropDownItem_DropDownItemClicked
      AddHandler sb.DropDownOpened, AddressOf toolStripDropDownItem_DropDownOpened
      
      Me.toolStrip1.Items.AddRange(New ToolStripItem() {b, m, sb})
   End Sub 

   ' This method handles the DropDownOpened event from a 
   ' ToolStripDropDownItem. It displays the value of the 
   ' item's Text property in the form's StatusStrip control.
    Private Sub toolStripDropDownItem_DropDownOpened(ByVal sender As Object, ByVal e As EventArgs)

        Dim item As ToolStripDropDownItem = CType(sender, ToolStripDropDownItem)

        Dim msg As String = String.Format("Item opened: {0}", item.Text)
        Me.toolStripStatusLabel1.Text = msg

    End Sub

   ' This method handles the DropDownItemClicked event from a 
   ' ToolStripDropDownItem. It displays the value of the clicked
   ' item's Text property in the form's StatusStrip control.
    Private Sub toolStripDropDownItem_DropDownItemClicked( _
    ByVal sender As Object, _
    ByVal e As ToolStripItemClickedEventArgs)

        Dim msg As String = String.Format("Item clicked: {0}", e.ClickedItem.Text)
        Me.toolStripStatusLabel1.Text = msg

    End Sub

   ' This method handles the DropDownClosed event from a 
   ' ToolStripDropDownItem. It displays the value of the 
   ' item's Text property in the form's StatusStrip control.
    Private Sub toolStripDropDownItem_DropDownClosed(ByVal sender As Object, ByVal e As EventArgs)

        Dim item As ToolStripDropDownItem = CType(sender, ToolStripDropDownItem)

        Dim msg As String = String.Format("Item closed: {0}", item.Text)
        Me.toolStripStatusLabel1.Text = msg

    End Sub

   ' This method shows the drop-down for the first item
   ' in the form's ToolStrip.
    Private Sub showButton_Click( _
    ByVal sender As Object, _
    ByVal e As EventArgs) _
    Handles showButton.Click

        Dim item As ToolStripDropDownItem = CType(Me.toolStrip1.Items(0), ToolStripDropDownItem)

        If item.HasDropDownItems Then
            item.ShowDropDown()
        End If

    End Sub

   ' This method hides the drop-down for the first item
   ' in the form's ToolStrip.
    Private Sub hideButton_Click( _
    ByVal sender As Object, _
    ByVal e As EventArgs) _
    Handles hideButton.Click

        Dim item As ToolStripDropDownItem = CType(Me.toolStrip1.Items(0), ToolStripDropDownItem)

        item.HideDropDown()
    End Sub

   Protected Overrides Sub Dispose(disposing As Boolean)
      If disposing AndAlso (components IsNot Nothing) Then
         components.Dispose()
      End If
      MyBase.Dispose(disposing)
    End Sub
   
   #Region "Windows Form Designer generated code"
   
   
   Private Sub InitializeComponent()
      Me.components = New System.ComponentModel.Container()
      Me.toolStrip1 = New System.Windows.Forms.ToolStrip()
      Me.statusStrip1 = New System.Windows.Forms.StatusStrip()
      Me.toolStripStatusLabel1 = New System.Windows.Forms.ToolStripStatusLabel()
      Me.contextMenuStrip1 = New System.Windows.Forms.ContextMenuStrip(Me.components)
      Me.menuItem1ToolStripMenuItem = New System.Windows.Forms.ToolStripMenuItem()
      Me.menuItem2ToolStripMenuItem = New System.Windows.Forms.ToolStripMenuItem()
      Me.subItemToolStripMenuItem = New System.Windows.Forms.ToolStripMenuItem()
      Me.subItem2ToolStripMenuItem = New System.Windows.Forms.ToolStripMenuItem()
      Me.showButton = New System.Windows.Forms.Button()
      Me.hideButton = New System.Windows.Forms.Button()
      Me.statusStrip1.SuspendLayout()
      Me.contextMenuStrip1.SuspendLayout()
      Me.SuspendLayout()
      ' 
      ' toolStrip1
      ' 
      Me.toolStrip1.Location = New System.Drawing.Point(0, 0)
      Me.toolStrip1.Name = "toolStrip1"
      Me.toolStrip1.Size = New System.Drawing.Size(292, 25)
      Me.toolStrip1.TabIndex = 0
      Me.toolStrip1.Text = "toolStrip1"
      ' 
      ' statusStrip1
      ' 
      Me.statusStrip1.Items.AddRange(New System.Windows.Forms.ToolStripItem() {Me.toolStripStatusLabel1})
      Me.statusStrip1.Location = New System.Drawing.Point(0, 251)
      Me.statusStrip1.Name = "statusStrip1"
      Me.statusStrip1.Size = New System.Drawing.Size(292, 22)
      Me.statusStrip1.TabIndex = 1
      Me.statusStrip1.Text = "statusStrip1"
      ' 
      ' toolStripStatusLabel1
      ' 
      Me.toolStripStatusLabel1.Name = "toolStripStatusLabel1"
      Me.toolStripStatusLabel1.Size = New System.Drawing.Size(38, 17)
      Me.toolStripStatusLabel1.Text = "Ready"
      ' 
      ' contextMenuStrip1
      ' 
      Me.contextMenuStrip1.Items.AddRange(New System.Windows.Forms.ToolStripItem() {Me.menuItem1ToolStripMenuItem, Me.menuItem2ToolStripMenuItem})
      Me.contextMenuStrip1.Name = "contextMenuStrip1"
      Me.contextMenuStrip1.RightToLeft = System.Windows.Forms.RightToLeft.No
      Me.contextMenuStrip1.Size = New System.Drawing.Size(146, 48)
      ' 
      ' menuItem1ToolStripMenuItem
      ' 
      Me.menuItem1ToolStripMenuItem.DropDownItems.AddRange(New System.Windows.Forms.ToolStripItem() {Me.subItemToolStripMenuItem})
      Me.menuItem1ToolStripMenuItem.Name = "menuItem1ToolStripMenuItem"
      Me.menuItem1ToolStripMenuItem.Size = New System.Drawing.Size(145, 22)
      Me.menuItem1ToolStripMenuItem.Text = "Menu Item1"
      ' 
      ' menuItem2ToolStripMenuItem
      ' 
      Me.menuItem2ToolStripMenuItem.DropDownItems.AddRange(New System.Windows.Forms.ToolStripItem() {Me.subItem2ToolStripMenuItem})
      Me.menuItem2ToolStripMenuItem.Name = "menuItem2ToolStripMenuItem"
      Me.menuItem2ToolStripMenuItem.Size = New System.Drawing.Size(145, 22)
      Me.menuItem2ToolStripMenuItem.Text = "Menu Item 2"
      ' 
      ' subItemToolStripMenuItem
      ' 
      Me.subItemToolStripMenuItem.Name = "subItemToolStripMenuItem"
      Me.subItemToolStripMenuItem.Size = New System.Drawing.Size(152, 22)
      Me.subItemToolStripMenuItem.Text = "Sub Item"
      ' 
      ' subItem2ToolStripMenuItem
      ' 
      Me.subItem2ToolStripMenuItem.Name = "subItem2ToolStripMenuItem"
      Me.subItem2ToolStripMenuItem.Size = New System.Drawing.Size(152, 22)
      Me.subItem2ToolStripMenuItem.Text = "Sub Item2"
      ' 
      ' showButton
      ' 
      Me.showButton.Location = New System.Drawing.Point(12, 180)
      Me.showButton.Name = "showButton"
      Me.showButton.Size = New System.Drawing.Size(75, 23)
      Me.showButton.TabIndex = 2
      Me.showButton.Text = "Show"
      Me.showButton.UseVisualStyleBackColor = True
      ' 
      ' hideButton
      ' 
      Me.hideButton.Location = New System.Drawing.Point(12, 209)
      Me.hideButton.Name = "hideButton"
      Me.hideButton.Size = New System.Drawing.Size(75, 23)
      Me.hideButton.TabIndex = 3
      Me.hideButton.Text = "Hide"
      Me.hideButton.UseVisualStyleBackColor = True
      ' 
      ' Form1
      ' 
      Me.AutoScaleDimensions = New System.Drawing.SizeF(6F, 13F)
      Me.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font
      Me.ClientSize = New System.Drawing.Size(292, 273)
      Me.Controls.Add(statusStrip1)
      Me.Controls.Add(hideButton)
      Me.Controls.Add(toolStrip1)
      Me.Controls.Add(showButton)
      Me.Name = "Form1"
      Me.Text = "Form1"
      Me.statusStrip1.ResumeLayout(False)
      Me.statusStrip1.PerformLayout()
      Me.contextMenuStrip1.ResumeLayout(False)
      Me.ResumeLayout(False)
      Me.PerformLayout()
    End Sub
   
   #End Region
End Class


Public Class Program

    ' The main entry point for the application.
    <STAThread()> _
    Shared Sub Main()
        Application.EnableVisualStyles()
        Application.SetCompatibleTextRenderingDefault(False)
        Application.Run(New Form1())
    End Sub
End Class
开发者ID:VB.NET开发者,项目名称:System.Windows.Forms,代码行数:246,代码来源:ToolStripDropDownItem



注:本文中的System.Windows.Forms.ToolStripDropDownItem类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
VB.NET ToolStripDropDownMenu类代码示例发布时间:2022-05-24
下一篇:
VB.NET ToolStripContentPanel类代码示例发布时间:2022-05-24
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap