在程序中添加菜单项 [英] Add menu items in program
问题描述
我编写了一个程序,用于从文件中读取菜单项。但我有问题
当我点击一个菜单项我希望它标记为已选中但我不能
访问该项目的菜单对象以查看女巫对象是选择。
这是从数组中读取项目并创建
menutitem的子过程。当选择了一个
项目时,数组会保存更多信息以供程序使用。
Dim finisharray(,)As String''设置在表格子。
Dim FilRow()字符串
Dim n As Integer
对于n = 0到5
FilRow =拆分(finisharray(n,1)," =")
如果FilRow( 0)=""然后退出
Dim windowMenu As ToolStripMenuItem = MenuStrip1.Items(1)
Dim windowNewMenu As New ToolStripMenuItem(Trim(FilRow(1) ),Nothing,New
EventHandler(AddressOf windowNewMenu_Click))
windowMenu.DropDownItems.Add(windowNewMenu)
CType(windowMenu.DropDown,ToolStripDropDownMenu).ShowImageMargin = False
CType(windowMenu.DropDown,ToolStripDropDownMenu).ShowCheckMargin = True
如果My.Settings.SelFlash<""然后
如果My.Settings.SelFlash = LCase(Trim(FilRow(1)))那么
windowNewMenu.Checked = True
结束如果
否则
My.Settings.SelFlash = LCase(修剪(FilRow(1) )))
windowNewMenu.Checked = True
结束如果
下一页>
I writing a program where I read menu items from a file. But I have problem
when I click an menu item i want it to mark that one as checked but I cant
access the menu object of that item to see witch object was selected.
This is the sub procedure that read the items from an Array and create the
menutitem. The array hold more information to use in program when one of the
items is selected.
Dim finisharray(,) As String '' is set up under the form sub.
Dim FilRow() As String
Dim n As Integer
For n = 0 To 5
FilRow = Split(finisharray(n, 1), "=")
If FilRow(0) = "" Then Exit For
Dim windowMenu As ToolStripMenuItem = MenuStrip1.Items(1)
Dim windowNewMenu As New ToolStripMenuItem(Trim(FilRow(1)), Nothing, New
EventHandler(AddressOf windowNewMenu_Click))
windowMenu.DropDownItems.Add(windowNewMenu)
CType(windowMenu.DropDown, ToolStripDropDownMenu).ShowImageMargin = False
CType(windowMenu.DropDown, ToolStripDropDownMenu).ShowCheckMargin = True
If My.Settings.SelFlash <"" Then
If My.Settings.SelFlash = LCase(Trim(FilRow(1))) Then
windowNewMenu.Checked = True
End If
Else
My.Settings.SelFlash = LCase(Trim(FilRow(1)))
windowNewMenu.Checked = True
End If
Next
推荐答案
顺便说一句,我正在使用VB 2005
" PetterL" < pe ********** @ hotmail.comwrote in message
news:%2 **************** @ TK2MSFTNGP03。 phx.gbl ...
By the way I''m using VB 2005
"PetterL" <pe**********@hotmail.comwrote in message
news:%2****************@TK2MSFTNGP03.phx.gbl...
>我编写了一个程序,我从文件中读取菜单项。但是我有问题
当我点击一个菜单项时我希望它标记为已选中但我无法访问该项目的菜单对象以查看女巫对象被选中。
这是从一个数组中读取项目并创建
menetitem的子过程。当一个项目选择了一个
时,该数组会保存更多信息以用于程序。
Dim finisharray(,)As String''设置在表格子。
Dim FilRow()字符串
Dim n As Integer
对于n = 0到5
FilRow =拆分(finisharray(n,1)," =")
如果FilRow( 0)=""然后退出
Dim windowMenu As ToolStripMenuItem = MenuStrip1.Items(1)
Dim windowNewMenu As New ToolStripMenuItem(Trim(FilRow(1) ),Nothing,New
EventHandler(AddressOf windowNewMenu_Click))
windowMenu.DropDownItems.Add(windowNewMenu)
CType(windowMenu.DropDown,ToolStripDropDownMenu).ShowImageMargin = False
CType(windowMenu.DropDown,ToolStripDropDownMenu).ShowCheckMargin = True
如果My.Settings.SelFlash<""然后
如果My.Settings.SelFlash = LCase(Trim(FilRow(1)))那么
windowNewMenu.Checked = True
结束如果
否则
My.Settings.SelFlash = LCase(修剪(FilRow(1) )))
windowNewMenu.Checked = True
结束如果
下一页>
PetterL写道:
PetterL wrote:
顺便说一句我是使用VB 2005
" PetterL" < pe ********** @ hotmail.comwrote in message
news:%2 **************** @ TK2MSFTNGP03。 phx.gbl ...
By the way I''m using VB 2005
"PetterL" <pe**********@hotmail.comwrote in message
news:%2****************@TK2MSFTNGP03.phx.gbl...
>我编写了一个程序,我从文件中读取菜单项。但是我有问题
当我点击一个菜单项时我希望它标记为已选中但我无法访问该项目的菜单对象以查看女巫对象被选中。
Dim finisharray(,)As String''设置在子表单下。
Dim FilRow()As String
Dim n As Integer
对于n = 0到5
FilRow = Split(finisharray( n,1),=")
如果FilRow(0)=""然后退出
Dim windowMenu As ToolStripMenuItem = MenuStrip1.Items(1)
Dim windowNewMenu As New ToolStripMenuItem(Trim(FilRow(1)),Nothing,New
EventHandler(AddressOf windowNewMenu_Click))
windowMenu.DropDownItems.Add(windowNewMenu)
CType(windowMenu.DropDown,ToolStripDropDownMenu).ShowImageMargin = False
> CType(windowMenu.DropDown,ToolStripDropDownMenu).ShowCheckMargin = True
如果My.Settings.SelFlash<""然后
如果My.Settings.SelFlash = LCase(修剪(FilRow(1)))那么
windowNewMenu.Checked = True
结束如果
其他
My.Settings.SelFlash = LCase(修剪(FilRow(1)))
windowNewMenu.Checked = True
结束如果
下一页
>I writing a program where I read menu items from a file. But I have problem
when I click an menu item i want it to mark that one as checked but I cant
access the menu object of that item to see witch object was selected.
This is the sub procedure that read the items from an Array and create
the menutitem. The array hold more information to use in program when one
of the items is selected.
Dim finisharray(,) As String '' is set up under the form sub.
Dim FilRow() As String
Dim n As Integer
For n = 0 To 5
FilRow = Split(finisharray(n, 1), "=")
If FilRow(0) = "" Then Exit For
Dim windowMenu As ToolStripMenuItem = MenuStrip1.Items(1)
Dim windowNewMenu As New ToolStripMenuItem(Trim(FilRow(1)), Nothing, New
EventHandler(AddressOf windowNewMenu_Click))
windowMenu.DropDownItems.Add(windowNewMenu)
CType(windowMenu.DropDown, ToolStripDropDownMenu).ShowImageMargin = False
CType(windowMenu.DropDown, ToolStripDropDownMenu).ShowCheckMargin = True
If My.Settings.SelFlash <"" Then
If My.Settings.SelFlash = LCase(Trim(FilRow(1))) Then
windowNewMenu.Checked = True
End If
Else
My.Settings.SelFlash = LCase(Trim(FilRow(1)))
windowNewMenu.Checked = True
End If
Next
在windowNewMenu_Click中,sender参数应为单击了
ToolStripMenuItem。您应该可以设置
选中的属性或切换它。
类似于:
public sub windowNewMenu_Click(发件人为对象,e为System.EventArgs)
dim tsmi为ToolStripMenuItem = ctype(sender,ToolStripMenuItem)
tsmi.checked = true
end sub
LS
In windowNewMenu_Click the sender parameter should be the
ToolStripMenuItem that was clicked. You should be able to set the
checked property or toggle it.
Something like:
public sub windowNewMenu_Click(sender as object, e As System.EventArgs)
dim tsmi as ToolStripMenuItem=ctype(sender,ToolStripMenuItem)
tsmi.checked=true
end sub
LS
如何取消选中所有以前的项目应该只检查一次。
" Lloyd Sheen" < a@b.cwrote in message
news:uY ************** @ TK2MSFTNGP03.phx.gbl ...
How do I uncheck all previous item(s) should only be one checked at time.
"Lloyd Sheen" <a@b.cwrote in message
news:uY**************@TK2MSFTNGP03.phx.gbl...
PetterL写道:
PetterL wrote:
>顺便说一下,我正在使用VB 2005
PetterL < pe ********** @ hotmail.comwrote in message
新闻:%2 **************** @ TK2MSFTNGP03.phx.gbl。 ..
> By the way I''m using VB 2005
"PetterL" <pe**********@hotmail.comwrote in message
news:%2****************@TK2MSFTNGP03.phx.gbl...
>>我编写的程序用于从文件中读取菜单项。但是当我点击一个菜单项时我有问题,我希望它将其标记为已检查
但是我无法访问该项目的菜单对象以查看该对象被选中。
Dim finisharray(,)As String''设置在子表单下。
Dim FilRow()As String
Dim n As Integer
对于n = 0到5
FilRow = Split(finisharray( n,1),=")
如果FilRow(0)=""然后退出
Dim windowMenu As ToolStripMenuItem = MenuStrip1.Items(1)
Dim windowNewMenu As New ToolStripMenuItem(Trim(FilRow(1)),Nothing,New
EventHandler(AddressOf windowNewMenu_Click))
windowMenu.DropDownItems.Add(windowNewMenu)
CType(windowMenu.DropDown,ToolStripDropDownMenu).ShowImageMargin =
False
CType(windowMenu.DropDown,ToolStripDropDownMenu).ShowCheckMargin = True
如果My.Settings.SelFlash<""然后
如果My.Settings.SelFlash = LCase(修剪(FilRow(1)))那么
windowNewMenu.Checked = True
结束如果
其他
My.Settings.SelFlash = LCase(修剪(FilRow(1)))
windowNewMenu.Checked = True
结束如果
下一页
>>I writing a program where I read menu items from a file. But I have
problem when I click an menu item i want it to mark that one as checked
but I cant access the menu object of that item to see witch object was
selected.
This is the sub procedure that read the items from an Array and create
the menutitem. The array hold more information to use in program when
one of the items is selected.
Dim finisharray(,) As String '' is set up under the form sub.
Dim FilRow() As String
Dim n As Integer
For n = 0 To 5
FilRow = Split(finisharray(n, 1), "=")
If FilRow(0) = "" Then Exit For
Dim windowMenu As ToolStripMenuItem = MenuStrip1.Items(1)
Dim windowNewMenu As New ToolStripMenuItem(Trim(FilRow(1)), Nothing, New
EventHandler(AddressOf windowNewMenu_Click))
windowMenu.DropDownItems.Add(windowNewMenu)
CType(windowMenu.DropDown, ToolStripDropDownMenu).ShowImageMargin =
False
CType(windowMenu.DropDown, ToolStripDropDownMenu).ShowCheckMargin = True
If My.Settings.SelFlash <"" Then
If My.Settings.SelFlash = LCase(Trim(FilRow(1))) Then
windowNewMenu.Checked = True
End If
Else
My.Settings.SelFlash = LCase(Trim(FilRow(1)))
windowNewMenu.Checked = True
End If
Next
在windowNewMenu_Click中,sender参数应为单击了
ToolStripMenuItem。您应该能够设置已检查的
属性或切换它。
类似于:
public sub windowNewMenu_Click(发件人为对象,e为System.EventArgs)
dim tsmi为ToolStripMenuItem = ctype(sender,ToolStripMenuItem)
tsmi.checked = true
end sub
LS
In windowNewMenu_Click the sender parameter should be the
ToolStripMenuItem that was clicked. You should be able to set the checked
property or toggle it.
Something like:
public sub windowNewMenu_Click(sender as object, e As System.EventArgs)
dim tsmi as ToolStripMenuItem=ctype(sender,ToolStripMenuItem)
tsmi.checked=true
end sub
LS
这篇关于在程序中添加菜单项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!