In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article introduces the knowledge of "how to use the event processor of C#". In the operation of actual cases, many people will encounter such a dilemma, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!
Preface to event handlers for C#Windows application development: usually windows applications have similar characteristics: controls, menus, toolbars, status bars, and so on. Every time we start a new windows application, we start with the same thing: building a project, adding controls and event handlers. If we have a template, then we can save a lot of time.
In the process of introducing how to build a template, it will involve a lot of basic knowledge of Microsoft. Net framework class library. If you are not using an integrated development environment, then the templates introduced in this article will be very useful to you, and if you use an integrated development environment like visual studio.net, you can also understand how controls work, which is also very useful to you.
Event handlers for C#Windows application development
Adding event handlers in windows programming is the most important task. The event handler ensures that the program interacts with the user while performing other important functions. In c # you can add event handlers to control and menu events to capture the events you want to handle. The following code designs an event handler for the click event of the Button control:
Button.Click + = new System.EventHandler (this.button_Click)
The button_Click event handler for event handlers developed by C#Windows applications must be handled:
Private void button_Click (Object sender, System.EventArgs e) {MessageBox.Show ("Thank you.", "The Event Information");}
The MenuItem object of an event handler developed by a C#Windows application can be instantiated while assigning an event handler:
FileNewMenuItem = new MenuItem (& New, new System.EventHandler (this.fileNewMenuItem_Click), Shortcut.CtrlN); fileOpenMenuItem = new MenuItem (& Open, new System.EventHandler (this.fileOpenMenuItem_Click), Shortcut.CtrlO); fileSaveMenuItem = new MenuItem (& Save, new System.EventHandler (this.fileSaveMenuItem_Click), Shortcut.CtrlS); fileSaveAsMenuItem = new MenuItem ("Save & As", new System.EventHandler (this.fileSaveAsMenuItem_Click)); fileMenuWithSubmenu = new MenuItem ("& WithSubmenu") SubmenuMenuItem = new MenuItem ("Su&bmenu", new System.EventHandler (this.submenuMenuItem_Click)); fileExitMenuItem = new MenuItem ("E&xit", new System.EventHandler (this.fileExitMenuItem_Click))
Problem with event handlers for C#Windows application development: you cannot assign an event handler to the tool button, but you can assign an event handler to the toolbar:
ToolBar.ButtonClick + = new ToolBarButtonClickEventHandler (this.toolBar_ButtonClick); protected void toolBar_ButtonClick (Object sender, ToolBarButtonClickEventArgs e) {/ / Evaluate the Button property to determine which button was clicked. Switch (toolBar.Buttons.IndexOf (e.Button)) {case 1: MessageBox.Show ("Second button.", "The Event Information"); break; case 2: MessageBox.Show ("third button", "The Event Information"); break; case 3: MessageBox.Show ("fourth button.", "The Event Information"); break;}}
Understanding of the event handler for C#Windows application development: in the example, an event handler is also designed for the close event of the form. By overloading the OnClosing method, you can receive the user clicking on the X button of the form, so you can cancel the close event:
Protected override void OnClosing (CancelEventArgs e) {MessageBox.Show ("Exit now.", "The Event Information");} "how to use the event handler of C#" ends here. Thank you for reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.