Developing the first Windows application with C #

zhaozj2021-02-08  258

First developed in C # C # WINDOWS application one of the authors study notes: Wenling City in Zhejiang Province Wang Jun bureau

Reader level: primary, intermediate preface: C # is a modern programming language, which is included in Visual Studio .NET 7.0. It simplifies the complexity of C , maintaining flexibility, which is easy to get started for people who have learned C . Visual Studio .NET 7.0 Beta1 has been released when writing this article, which is a simple development attempt to this version. Sample code download 18K 1. Create project As shown in the figure, select New-> Project in the File menu for the integrated development environment Open New Project dialog box We choose the engine type to Visual C # Projects, select Windows Application in the template, at the NAME Enter the project Name: Hellowindows, enter the saved path in the location. After confirming, the system automatically generates a program framework. Now let's simply familiarize yourself with this development environment. This is our development environment! A district is our toolbox, including support for databases, components, form controls, etc., we can choose and add to Form, if you can't find Toolbox, select Toolbox in the menu view to open it. The B area is our design work area (including the design of the interface, code), which shows the main window we have just created: Form1. The C area is equivalent to the Workspace in VC6: Solution Explorer can be seen as the previous fileview, resourceView and classview everyone must be very familiar, see the form1.cs in Solution Explorer? This is the corresponding C # file corresponding to the Form1. You can interface design to Form1, right-click Form1.cs Select View Code in the pop-up menu to view the corresponding code. The D area is an attribute window: Similar to the property window we are in the resource editor in the VC6, but more powerful, for components on the screen, such as buttons, list boxes you can directly modify their properties directly: text, background color, etc. . Our next task is to make the dialog box and add a menu to open this dialog. Second, add a new form: About dialog box selection menu Project-> add windows form, select the category to local project items in the pop-up dialog box, select the template for Windows Form, enter the file name in Name: Aboutdlg.cs, confirm . New Form appears in the workspace, we modify the text as "About" in the Properties dialog in the D area, select BackColor as light blue, you can also try other properties change. Next, let's open Toolbox, select Label in WIN FORMS, then draw in the form, and modify text in the Properties dialog box "Welcome to" VC Knowledge Base! Http://www.vckbase.com ", we Add a button in Win Forms to modify Text to "confirm". At this point, we design the interface of the dialog, but how do we close the dialog when the user presses the confirmation button? We double-click the "Confirm" button so that the system will automatically add the button processing code for the button, where we add a close () function to close, as shown below:

Protected void button1_click (object sender, system.eventargs e) {close (); // This is our increased sentence} About dialogs have been completed, we will do it to add menu for the main window, when selecting menu About, we will pop up "about dialog box", let us continue ... Third, add menu to the main window Add Menu in SolutionView to open Form1, select MainMenu in Toolbox-> Win Forms, and in Form1 In the "TypeHere" stamp, we can enter the menu bar, as shown: Double-click on the words, the system will add the handling code for us, we can add the code that opens "About Dialog" : Protected void button1_click (Object sender, system.eventargs e) {Aboutdlg DLG = New Aboutdlg (); /// assigning the AboutDLG object DLG.ShowDialog (); /// Show dialog box} Ok, our program is written Let's press F5 to see the effect! Postscript: The function of C # is far more than this. The purpose of this article is to make the development of VC6 to the Windows application development as soon as possible, only when the brick is pushed.

Www.vckbase.com

转载请注明原文地址:https://www.9cbs.com/read-1610.html

New Post(0)