[英]C# How to make one item from Menustrip be default selected? How to display the selected items from Menustrip Selected to a textbox
I am working on C# WFA. 我正在使用C#WFA。 I have one menustrip which has one item called: Settings, under this I have three items: ID, Number, and Time. 我有一个菜单条,其中有一个名为:Settings,在此菜单下,我有三个项目:ID,Number和Time。 Under Number item there has 5 items again which man can choose. 在“号码”项下,又有5个项可供男人选择。 Now I want to make it like this: first make one of the items under Number is default chosen, Secondly, I want to have one more textbox in the GUI, which will show which item is selected under number. 现在,我要这样:首先选择Number下的一项为默认选择,其次,我想在GUI中再有一个文本框,其中将显示在number下选择了哪一项。
For example: 例如:
Settings
---ID
---Number
----NUMBER1
----Number 2
----Number 3
---Time
So I want to set the Number 2 as the default chosen item, how can I do that? 所以我想将数字2设置为默认选择的项目,我该怎么做? I want to display the selected Number item in textbox when one is selected, How can I do that? 我想在选中一个数字项时在文本框中显示该数字项,该怎么办?
Thanks a lot! 非常感谢!
BR Emma 艾玛(BR Emma)
For Select NUMBER 2 as BY Default you have to add single line in your code, 对于默认选择NUMBER 2,您必须在代码中添加一行,
this.NUMBER2ToolStripMenuItem.Select(); this.NUMBER2ToolStripMenuItem.Select();
This code for getting text of selected items... 此代码用于获取所选项目的文本...
' your method would look something like this '您的方法看起来像这样
Private Sub MenuItem2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) 私有子MenuItem2_Click(ByVal发送者为System.Object,ByVal e为System.EventArgs)
Dim mnuItem As MenuItem = DirectCast(sender, MenuItem) 昏暗的mnuItem作为MenuItem = DirectCast(发送方,MenuItem)
MessageBox.Show(mnuItem.Text) MessageBox.Show(mnuItem.Text)
End Sub ' 结束Sub'
' and just so you know, it would be attached to the event like so '而且您知道,它将像这样附加到事件中
AddHandler MenuItem2.Click, AddressOf MenuItem2_Click AddHandler MenuItem2.Click,AddressOf MenuItem2_Click
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.