简体   繁体   English

在 C# 中编程时在 Visual Studio IDE 中创建控制事件

[英]Creating control events in the Visual Studio IDE when programming in C#

I have been developing VB.Net winform apps using Visual Studio for several years and I am now just trying to get my head around C#.多年来,我一直在使用 Visual Studio 开发 VB.Net winform 应用程序,现在我只是想了解 C#。 When I am using Visual Studio (currently VS 2017) to develop VB.Net winform apps I have three dropdowns at the top of the IDE that allows me to select the project, control and then events for the selected control.当我使用 Visual Studio(当前为 VS 2017)开发 VB.Net winform 应用程序时,我在 IDE 顶部有三个下拉列表,允许我选择 select 项目、控件,然后是所选控件的事件。 So if I want to handle, for example, the MouseDown event of a TextBox I simply select the MouseDown event in the dropdown and Visual Studio creates the event handler for me.因此,例如,如果我想处理 TextBox 的 MouseDown 事件,我只需 select 下拉菜单中的 MouseDown 事件,Visual Studio 就会为我创建事件处理程序。

In C#, if I double click the control in the Design view it will automatically create the event handler for the default event, but what about all of the other events?在 C# 中,如果我在设计视图中双击控件,它将自动为默认事件创建事件处理程序,但是所有其他事件呢? Is there a C# equivalent way to VB.Net to generate the handler automatically or do I always have to create the event handlers manually?是否有与 VB.Net 等效的 C# 方法来自动生成处理程序,还是我总是必须手动创建事件处理程序?

Thanks谢谢

Just switch to the event tab on your control property page and double-click your event and VS creates exact THIS handler for you.只需切换到控件属性页面上的事件选项卡并双击您的事件,VS 就会为您创建准确的 THIS 处理程序。

可视化

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

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