工具条 WinForms .Net Core 的问题 [英] Problem with Toolstrip WinForms .Net Core

查看:25
本文介绍了工具条 WinForms .Net Core 的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在 .Net Core 中制作一个 Winforms 应用程序来学习一些基本的东西.这是一个简单的应用程序,我可以将文本框中的一些文本写入文件(基本上类似于记事本).

I'm making a Winforms application in .Net Core to learn some basic stuff. It's a simple application where I write some text from a textbox to a file (basically like notepad).

现在我想添加一个带有工具条按钮的工具条来创建一个新文件和一个工具条按钮来将文本保存到文件中,等等.

Now I wanted to add a toolstrip with a toolstripbutton to make a new file and a toolstripbutton to save the text to the file, etc..

所以我从工具箱中添加工具条并将其拖到我的 form1.cs[design] 中.然后我右键单击工具条并单击插入标准项目".按钮正在添加到工具条中.

So I add the toolstrip from toolbox and drag it to my form1.cs[design]. Then I right click on the toolstrip and click "Insert standard items". The buttons are being added to the toolstrip.

现在我的问题是我想向按钮添加一个点击事件,但我不能单独双击工具条按钮.所以我必须进入designer.cs来添加click事件.例如:

Now my problem is I want to add a click event to the buttons but I can't double click the toolstripbuttons individually. So I have to go into the designer.cs to add the click event. For example:

this.newToolStripButton.Click += new System.EventHandler(this.btnNewFile_Click);

我刚刚在 .Net Framework 中使用 WinForms 应用程序进行了尝试,然后我只需双击工具条按钮即可添加事件处理程序.

I just tried it with a WinForms app in .Net Framework and there I can just double click the toolstripbuttons to add an eventhandler.

我是否必须在 .Net Core 中采用不同的方法?这在 .Net Core 中是否还没有完全支持,我应该只使用 .Net Framework for Winforms 吗?我了解到并非 .Net Framework 中 Winforms 的所有功能都在 .Net Core 中得到支持,但 Toolstrip 应该可以工作.

Do I have to take a different approach in .Net Core? Is this not yet fully supported in .Net Core and should I just use .Net Framework for Winforms? I read that not all of the functionalities from Winforms in .Net Framework are yet supported in .Net Core, but Toolstrip should work.

提前致谢

推荐答案

从 Visual Studio 2019 16.8.0 Preview 6.0(以及 VS2019 16.7.6)开始,双击设计器中的 ToolStripButton 将启动 ToolStrip_ItemClicked 的代码事件.在这种情况下,您可以检查 ToolStripItemClickedEventArgs.ClickedItem 以查看按下了什么.

As of Visual Studio 2019 16.8.0 Preview 6.0 (and also VS2019 16.7.6), double-clicking a ToolStripButton in the designer will launch code for the ToolStrip_ItemClicked event. In that event you can check the ToolStripItemClickedEventArgs.ClickedItem to see what was pressed.

private void toolStrip2_ItemClicked(object sender, ToolStripItemClickedEventArgs e)
        {
            ToolStripButton tsb = (ToolStripButton)e.ClickedItem;
        }

如果您想访问单个 ToolStripButton 的 Click 事件,您可以在属性"窗口中选择它,单击事件"按钮,然后将其插入.

If you want to get to the Click event for an individual ToolStripButton, you can select it in the Properties window, click the Events button, and insert it there.

这篇关于工具条 WinForms .Net Core 的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆