Vc. NET, using Windows.Forms

Source: Internet
Author: User
Tags header list of attributes resource visual studio

Friends who are familiar with the Virsual basic development approach, when using Visual C + +, must have complained: "Why can't I design my own form, and why can't I animate my control?" Can this be called visual (visual)? You see others borland C + + ... "It's true that making a control-rich main form is a heavy task in the past, but it has improved in Visual Studio.NET." In this article, the author will be with you to enjoy the expectations of the relaxed and happy.

Remember the past use VC + + to create a form of the process, it means that a relatively large number of code describes a form class (or application Class) objects, each property is set to correspond to a row of assignment statements. If you are using the Windows API, you need to write the main event loop yourself. As for the icon, bitmap What is also to be called as a resource. Trying to add a control is a bit of a hassle. First, you need to have an MFC encyclopedia, and follow it to add instances of various control classes, intercepting the various Windows messages it uses ... These are the VC + + Production window program, the author did not learn the reason.

This two days to Tinker Vc++.net, only to find out that VC + + can also use the window editor. I'm going to take you along and use it to create a window. Let's start with the classic "Hello,world".

We should create a project of the type Windows Form application (. NET) (Windows window application). Here it is named HelloWorld.



Click OK to confirm that we see. NET has automatically created a main form Form1 for us. Can see the left file list, is still the traditional source files, header files and resources, a little bit of change is the Form1 header file, the author will be detailed later, in fact, we have to do the work is encapsulated in this header file. Present in front of us is no longer the traditional code editing interface of VC + +, but a window editing interface.



Reader's development environment if you are using Visual c++6.0 interface style, you will not see the most important control bar (TOOLBOX), you want to open it in the menu item View-〉 Toolbox (ToolBox). We see an exciting control, you can do it on the top of the drawing control to cool a few, and then we continue. Pull out a button and a label, I think it should be no stranger to you. Right-click any of them, select the last item in the menu to call the list of attributes (which should appear below the list of files), and you can edit their properties without having to write a statement. Try to change the icon for our program, do not bother to call the resources, it is easy to do not?



Keeping a good naming habit, I named them both Btnsay and lblshow. Start adding code, double-click Btnsay, enter the code interface, the cursor will automatically jump to the button click event, the other things can be no matter, just add the code here

This->lblshow->text = "Hello,the world!";

I think it's a lot to do (a bit like VB, isn't it?) After all, is C + +, have to compile. Press CTRL+F5 to compile the link to run, as shown in figure:



Real C + + programmers will then think about how the code is encapsulated by the organization. Let's take a look at the organization of the document first. This is still used in the form of resources to use icons, menus, and so on, so here are the same *.rc and resource.h as ever. The main body of the project is form1.h/cpp file pairs, the main program is also inside. But the main program seems to be an empty shell, the real form object information is in the Form1.h. It now shows us a visual design posture, we right-click it, in the pop-up dialog box to select the second



Finally unveiled its mystery, and saw the code hidden behind. (It's a bit of a mystery, but you already saw it when you wrote the code.) This makes me also very surprised, in the header file actually can have the execution code! There is one more thing to say, just now you can not find where to modify the name of the Form1 object? It can be changed in the list of properties in the code interface. I renamed it frmmain.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.