1
В режиме загрузки я заполняю меню всеми возможными цветами, чтобы пользователь мог выбрать цвет. Однако, когда они выбирают цвет, forecolor моего ярлыка не изменяется.VB.NET 2008 - Анонимная функция
Private Sub MainForm_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
' When the form loads, we want to populate the color menu item with all the possible colors that we could change the label to.
For Each currentColor As KnownColor In [Enum].GetValues(GetType(KnownColor))
' Declare the knowColor again - we must do this to be able to do anonymous delegates in VB.NET
Dim actualCurrentColor As KnownColor = currentColor
' Get the name for this color
Dim colorName As String = [Enum].GetName(GetType(KnownColor), actualCurrentColor)
' Create a new menu item for this color
Dim newMenuItem As ToolStripMenuItem = New ToolStripMenuItem(colorName)
' Add a handler to this menu item so when it is clicked, we change the heading color
AddHandler newMenuItem.Click, Function(s As System.Object, events As System.EventArgs) (HeadingLabel.ForeColor = Color.FromKnownColor(actualCurrentColor))
' Add the menu item to the colors menu
ColorToolStripMenuItem.DropDownItems.Add(newMenuItem)
Next
End Sub
Что я делаю неправильно? Благодаря
Спасибо, я понимаю, что выпадающее меню было довольно плохой практикой, но это было скорее «Почему это не работает?» Я бы не сделал что-то подобное в программе RL. – 2010-05-18 03:42:38