"C # entry and improvement" (3)

zhaozj2021-02-08  252

Chapter II Developed the First Windows Application with C #

Ready to start, start VS7: The following image appears: VS7 IDE as shown below: 1. Creating a new project As shown in the figure, select New-> Project to open the New Project dialog box in the File menu of the development environment For Visual C # Projects, select Windows Application in the template, enter the project name at 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 Zone: It is our toolbox, including support for databases, components, form controls, etc., we can choose and add to Form. If you can't find Toolbox, you can select Toolbox in the menu view to open it. . B Zone: It is our design work area (including the design of the interface, code), which shows the main window we have just created: Form1. C Zone: It is equivalent to the Workspace in VC 6: Solution Explorer can be seen as the previous fileview, resourceView and ClassView everyone must be very familiar, see 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. D Zone: Yes Attribute Window: Similar to the property window in the resource editor in VC6 / VB6, for components on the screen, such as buttons, list boxes you can directly modify their properties directly: such as text, background color, etc. Our next task is to make a dialog 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 it in the form, modify text in the Properties dialog, and we add a button in Win Forms, and its text is set 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}

The dialog has been completed, let's add menu to the primary window, when you choose about the menu, let's pop up the "Dialogue", let us continue, add menu to the main window, in SolutionView Double-click Form1.cs to open Form1, select MainMenu in Toolbox-> Win Forms, and "Picture in Form1, we can enter the menu bar in" TypeHere ", as shown: Double click on the words, the system will add us The menu strip processing code, we can add the code that opens "About Void Button1_Click (Object Sender, System.Eventargs E) {Aboutdlg DLG = New Aboutdlg (); // Establish a Aboutdlg Object Dlg.ShowDialog (); // Display dialog box}

Ok, our program is written, let's press F5 to see the effect! Conclusion: This chapter introduces how to write a Windows program, very simple, this is C #, see this here I think you will feel a bit a little, I used to learn VB / Delphi people may be surprised: How to be like VB / Delphi!

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

New Post(0)