VS2010/MFC dialog box: Adding Controls for a dialog box

Source: Internet
Author: User
Tags delete key

Adding Controls to a dialog box

Creating a dialog resource requires creating a dialog template, modifying dialog box properties, adding various controls to a dialog box, and so on, in the previous talk, creating a dialog box template and modifying dialog properties, and this section continues with how to add controls for a dialog box.

In the previous lecture, a project called "addition" was created to generate an application that implements the addition operation. There are several necessary factors to achieve the addition calculation: being Addend, Addend, and. Be addend and addend need input, and need output display. Then these factors all need the corresponding control to enter or display, below the chicken peck rice step by step explain how to add these controls.

1. Add a static text box (static) for the dialog box to display the string-"Summand".

The resource template that was generated in the previous lecture is automatically added with a title of "Todo:place dialog controls here." The static text box, we can modify its title to continue to use, you can also delete it. To explain the process of adding a static text box from scratch, delete it and continue adding a new static text box.

When you delete a control, you can click to select it with the left mouse button, and a dashed box appears around the control when you select it, and then press the DELETE key to delete it. Open the dialog template created in the previous lecture in the resource view of the addition project Idd_addition_dialog, and the automatically added static text box can be removed using this method.

Before adding a new static text box, check to see if the Toolbox view is displayed, or click View->toolbox on the menu bar if it is not displayed. Toolbox views such as:

Some common controls are listed in Toolbox, one of which is static Text, which is the control we want to add. In toolbox, the static text on the left mouse button is not released, and dragged to the Idd_addition_dialog dialog template, a dashed box appears on the template, we find the right place to release the left mouse button down it.

When you select a control with the left mouse button, a dashed box appears around the border, and the position of several black dots on the dotted box becomes a two-headed arrow shape, so you can press the left mouse button and drag to change the size of the control. We can change the size of the newly added static text box control to better display the caption. Of course, the entire dialog box template can also change size in this way.

You should then modify the text of the static text box. Right-click on the static text box, select "Properties" in the right-click menu, property panel will be displayed, modify the Caption property on the panel is "Summand", the ID is modified to idc_summand_static. At this point the template is as follows:

2. Add an edit Control to the dialog box to enter Summand.

The process of adding an edit box is similar to a static text box, in Toolbox, by selecting the edit control to drag onto the dialog template and aligning it horizontally with the previous static text box (for aesthetics), and then resizing it to fit the input of the summand.

Right-click on the edit box and still select "Properties" in the right-click menu to display the property panel and modify its ID to idc_summand_edit. At this point the template is as follows:

3. Add a static text box titled "Addend" in the 1 method to display the string-"Addend". and change its ID to idc_addend_static.

4. Add an edit box with ID Idc_addend_edit in the 2 method to enter Addend.

5. Add a static text box titled "and" in the 1 method to display the text--"and". and modify its ID to idc_sum_static.

6. Add an edit box with ID Idc_sum_edit in the 2 method to display the final sums.

7. A similar Add button control to a dialog template that triggers an addition calculation after being clicked. modify its title to "calculate" with ID Idc_add_button.

To this, the dialog box template

8. Remove the OK button. Open the Properties panel of the Cancel button, change the caption to exit, and align it horizontally with the Calculate button.

9. Depending on the layout of the control, adjust the size of the entire dialog box template appropriately, making it appropriate for the layout of the control and pleasing to the interface.

This adds up the controls we need to use in this example in the dialog box template. The final effect is as follows:

At this point, our dialog resources are basically created. The interface effect after the application is running is already clear. The following will explain how to implement the addition calculation function in the dialog box class, and can interact with the interface well.

VS2010/MFC dialog box: Adding Controls for a dialog box

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.