E
Eric Sabine
Basically, the following code creates a menuItem array and tries to use it
twice. In the following piece of code, only the line that appears second
gets used. The first becomes ignored presumably when the second is run.
Me.mnuFile.MenuItems.AddRange(myMenu)
Me.ContextMenu1.MenuItems.AddRange(myMenu)
Below I've included just enough code to see it as an example. Can someone
explain to me why this happens?
Eric
Public Class Form1
Inherits System.Windows.Forms.Form
Private myMenu() As MenuItem
Private components As System.ComponentModel.IContainer
Friend WithEvents MainMenu1 As System.Windows.Forms.MainMenu
Friend WithEvents ContextMenu1 As System.Windows.Forms.ContextMenu
Friend WithEvents TextBox1 As System.Windows.Forms.TextBox
Friend WithEvents mnuFile As System.Windows.Forms.MenuItem
Public Sub New()
MyBase.New()
InitializeComponent()
Dim mic() As MenuItem
mic = New MenuItem(2) {}
mic(0) = New MenuItem("a")
mic(0).Index = 1
mic(1) = New MenuItem("b")
mic(1).Index = 2
mic(2) = New MenuItem("c")
mic(2).Index = 3
myMenu = mic
Me.mnuFile.MenuItems.AddRange(myMenu)
Me.ContextMenu1.MenuItems.AddRange(myMenu)
End Sub
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
Private Sub InitializeComponent()
Me.MainMenu1 = New System.Windows.Forms.MainMenu
Me.ContextMenu1 = New System.Windows.Forms.ContextMenu
Me.TextBox1 = New System.Windows.Forms.TextBox
Me.mnuFile = New System.Windows.Forms.MenuItem
Me.SuspendLayout()
Me.MainMenu1.MenuItems.AddRange(New System.Windows.Forms.MenuItem()
{Me.mnuFile})
Me.TextBox1.ContextMenu = Me.ContextMenu1
Me.TextBox1.Location = New System.Drawing.Point(56, 64)
Me.TextBox1.Name = "TextBox1"
Me.TextBox1.TabIndex = 0
Me.TextBox1.Text = ""
Me.mnuFile.Index = 0
Me.mnuFile.Text = "File"
Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
Me.ClientSize = New System.Drawing.Size(292, 273)
Me.Controls.Add(Me.TextBox1)
Me.Menu = Me.MainMenu1
Me.Name = "Form1"
Me.Text = "Form1"
Me.ResumeLayout(False)
End Sub
End Class
twice. In the following piece of code, only the line that appears second
gets used. The first becomes ignored presumably when the second is run.
Me.mnuFile.MenuItems.AddRange(myMenu)
Me.ContextMenu1.MenuItems.AddRange(myMenu)
Below I've included just enough code to see it as an example. Can someone
explain to me why this happens?
Eric
Public Class Form1
Inherits System.Windows.Forms.Form
Private myMenu() As MenuItem
Private components As System.ComponentModel.IContainer
Friend WithEvents MainMenu1 As System.Windows.Forms.MainMenu
Friend WithEvents ContextMenu1 As System.Windows.Forms.ContextMenu
Friend WithEvents TextBox1 As System.Windows.Forms.TextBox
Friend WithEvents mnuFile As System.Windows.Forms.MenuItem
Public Sub New()
MyBase.New()
InitializeComponent()
Dim mic() As MenuItem
mic = New MenuItem(2) {}
mic(0) = New MenuItem("a")
mic(0).Index = 1
mic(1) = New MenuItem("b")
mic(1).Index = 2
mic(2) = New MenuItem("c")
mic(2).Index = 3
myMenu = mic
Me.mnuFile.MenuItems.AddRange(myMenu)
Me.ContextMenu1.MenuItems.AddRange(myMenu)
End Sub
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
Private Sub InitializeComponent()
Me.MainMenu1 = New System.Windows.Forms.MainMenu
Me.ContextMenu1 = New System.Windows.Forms.ContextMenu
Me.TextBox1 = New System.Windows.Forms.TextBox
Me.mnuFile = New System.Windows.Forms.MenuItem
Me.SuspendLayout()
Me.MainMenu1.MenuItems.AddRange(New System.Windows.Forms.MenuItem()
{Me.mnuFile})
Me.TextBox1.ContextMenu = Me.ContextMenu1
Me.TextBox1.Location = New System.Drawing.Point(56, 64)
Me.TextBox1.Name = "TextBox1"
Me.TextBox1.TabIndex = 0
Me.TextBox1.Text = ""
Me.mnuFile.Index = 0
Me.mnuFile.Text = "File"
Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
Me.ClientSize = New System.Drawing.Size(292, 273)
Me.Controls.Add(Me.TextBox1)
Me.Menu = Me.MainMenu1
Me.Name = "Form1"
Me.Text = "Form1"
Me.ResumeLayout(False)
End Sub
End Class