简体   繁体   English

C#如何使Menustrip中的一项成为默认选择? 如何显示从“选定的菜单”到文本框中的选定项目

[英]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.

相关问题 在菜单中仅选中一个复选框 - Make only one checkbox to be selected in menuStrip c#-如何从模型中的项目列表中获取特定项目,并在单击按钮时显示所选项目的属性? - c# - How to get a specific item from a list of items in model and display the properties of the selected item on button click? 如何显示所选 WPF ComboBox 项目 C# 中的内容 - How to display content from selected WPF ComboBox item C# 如果选择 combobox 中的最后一项,如何使文本框可见 c# - How to make a textbox visible if last item in a combobox is selected c# 如何在单击时更改选定的 MenuStrip 按钮颜色? - How can I change the selected MenuStrip button color on click? c#如何使从列表框中选择的项目显示在标签中? - c# How to make that selected item from listbox will be shown in label? 如何在C#中将所选项目从一个列表视图移动到另一个列表视图? - How to move selected item from one listview to another in C#? 如何从txt文件C#设置Menustrip图标 - How to set menustrip icon from txt file C# 如何显示“默认”所选项目-组合框C#WPF - How to display “default” selected item - Combobox C# WPF 如何在C#中启用/禁用MenuStrip项和项的下拉集合项 - How to Enable/Disable MenuStrip Items and Item's Drop Down Collection Items In C#
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM