简体   繁体   English

工具条 WinForms.Net Core 的问题

[英]Problem with Toolstrip WinForms .Net Core

I'm making a Winforms application in.Net Core to learn some basic stuff.我正在.Net Core 中制作一个 Winforms 应用程序来学习一些基本的东西。 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..现在我想添加一个带有工具条按钮的工具条来创建一个新文件和一个工具条按钮来将文本保存到文件中,等等。

So I add the toolstrip from toolbox and drag it to my form1.cs[design].所以我从工具箱中添加工具条并将其拖到我的 form1.cs[design] 中。 Then I right click on the toolstrip and click "Insert standard items".然后我右键单击工具条并单击“插入标准项目”。 The buttons are being added to the toolstrip.按钮被添加到工具条中。

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.所以我必须将go 放入designer.cs 中添加点击事件。 For example:例如:

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

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 Framework 中使用 WinForms 应用程序进行了尝试,我只需双击工具条按钮即可添加事件处理程序。

Do I have to take a different approach in.Net Core?我必须在.Net Core 中采取不同的方法吗? Is this not yet fully supported in.Net Core and should I just use.Net Framework for Winforms?这在 .Net Core 中还没有完全支持吗,我应该只使用 .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.我读到.Net Core 中并非所有 Winforms in.Net Framework 的功能都得到支持,但 Toolstrip 应该可以工作。

Thanks in advance提前致谢

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.从 Visual Studio 2019 16.8.0 Preview 6.0(以及 VS2019 16.7.6)开始,在设计器中双击 ToolStripButton 将启动 ToolStrip_ItemClicked 事件的代码。 In that event you can check the ToolStripItemClickedEventArgs.ClickedItem to see what was pressed.在这种情况下,您可以检查 ToolStripItemClickedEventArgs.ClickedItem 以查看按下的内容。

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

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.如果要获取单个 ToolStripButton 的 Click 事件,可以在属性 window 中的 select 它,单击事件按钮,然后将其插入那里。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM