>Public Class frmMenuEjecucion > Inherits System.Windows.Forms.Form > >#Region " Código generado por el Diseñador de Windows Forms " > > Public Sub New() > MyBase.New() > > 'El Diseñador de Windows Forms requiere esta llamada. > InitializeComponent() > > 'Agregar cualquier inicialización después de la llamada a InitializeComponent() > > End Sub > > 'Form reemplaza a Dispose para limpiar la lista de componentes. > Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean) > If disposing Then > If Not (components Is Nothing) Then > components.Dispose() > End If > End If > MyBase.Dispose(disposing) > End Sub > > 'Requerido por el Diseñador de Windows Forms > Private components As System.ComponentModel.IContainer > > 'NOTA: el Diseñador de Windows Forms requiere el siguiente procedimiento > 'Puede modificarse utilizando el Diseñador de Windows Forms. > 'No lo modifique con el editor de código. > Friend WithEvents btnAgrega As System.Windows.Forms.Button > Friend WithEvents btnNuevo As System.Windows.Forms.Button > Friend WithEvents btnClonar As System.Windows.Forms.Button > Friend WithEvents btnElimina As System.Windows.Forms.Button > <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent() > Me.btnAgrega = New System.Windows.Forms.Button > Me.btnNuevo = New System.Windows.Forms.Button > Me.btnElimina = New System.Windows.Forms.Button > Me.btnClonar = New System.Windows.Forms.Button > Me.SuspendLayout() > ' > 'btnAgrega > ' > Me.btnAgrega.Location = New System.Drawing.Point(40, 216) > Me.btnAgrega.Name = "btnAgrega" > Me.btnAgrega.Size = New System.Drawing.Size(120, 23) > Me.btnAgrega.TabIndex = 0 > Me.btnAgrega.Text = "&Agrega Menu" > ' > 'btnNuevo > ' > Me.btnNuevo.Location = New System.Drawing.Point(208, 216) > Me.btnNuevo.Name = "btnNuevo" > Me.btnNuevo.Size = New System.Drawing.Size(120, 23) > Me.btnNuevo.TabIndex = 1 > Me.btnNuevo.Text = "&Nuevo Elemento" > ' > 'btnElimina > ' > Me.btnElimina.Location = New System.Drawing.Point(376, 216) > Me.btnElimina.Name = "btnElimina" > Me.btnElimina.Size = New System.Drawing.Size(120, 23) > Me.btnElimina.TabIndex = 2 > Me.btnElimina.Text = "&Elimina Elemento" > ' > 'btnClonar > ' > Me.btnClonar.Location = New System.Drawing.Point(208, 134) > Me.btnClonar.Name = "btnClonar" > Me.btnClonar.Size = New System.Drawing.Size(120, 23) > Me.btnClonar.TabIndex = 3 > Me.btnClonar.Text = "&Copia Menu" > Me.btnClonar.UseVisualStyleBackColor = True > ' > 'frmMenuEjecucion > ' > Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13) > Me.ClientSize = New System.Drawing.Size(520, 273) > Me.Controls.Add(Me.btnClonar) > Me.Controls.Add(Me.btnElimina) > Me.Controls.Add(Me.btnNuevo) > Me.Controls.Add(Me.btnAgrega) > Me.Name = "frmMenuEjecucion" > Me.Text = "Demo Menú" > Me.ResumeLayout(False) > > End Sub > >#End Region > > Private Sub btnAgrega_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAgrega.Click > 'Definiendo nuevo menu > Dim NuevoMenu As New MainMenu() > 'Definiendo elementos del MainMenu > Dim ElementoUno As New MenuItem("&Archivo") > Dim ElementoDos As New MenuItem("A&yuda") > > 'Asignando subelementos a las opciones del MainMenu > Dim Opcion1 As New MenuItem("Salir") > Dim Opcion2 As New MenuItem("Mensaje") > 'Estableciendo el procedimientoa ejecutarse al hacer click > AddHandler Opcion1.Click, AddressOf Me.Opcion1_Click > AddHandler Opcion2.Click, AddressOf Me.Opcion2_Click > > 'Asignando Opcion1 a Elemento Uno > ElementoUno.MenuItems.Add(Opcion1) > > 'Asignando Opcion2 a Elemento Dos > ElementoDos.MenuItems.Add(Opcion2) > > 'Asignando Elementos al MainMenu > NuevoMenu.MenuItems.Add(ElementoUno) > NuevoMenu.MenuItems.Add(ElementoDos) > > 'Asignando NuevoMenu al formulario > Me.Menu = NuevoMenu > > End Sub > > Private Sub btnNuevo_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnNuevo.Click > 'Creando un nuevo elemento > Dim NuevaOpcion As New MenuItem("Abrir") > > 'Asignando MenuItem al NuevoMenu > Me.Menu.MenuItems(0).MenuItems.Add(NuevaOpcion) > > End Sub > > Private Sub btnElimina_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnElimina.Click > Me.Menu.MenuItems(0).MenuItems.RemoveAt(1) > End Sub > > Private Sub Opcion1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) > Me.Close() > End Sub > Private Sub Opcion2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) > MsgBox("Este es un mensaje de prueba") > End Sub > > Private Sub btnClonar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnClonar.Click > Dim MenuContextual As ContextMenu > MenuContextual = New ContextMenu() > MenuContextual.MenuItems.Add(Me.Menu.MenuItems(1).CloneMenu()) > btnClonar.ContextMenu = MenuContextual > End Sub >End Class > >