C ++ Builder first-study and answer (1)

zhaozj2021-02-16  54

C Builder first-study and answer

(Copyright requirements: This article must not be reproduced in addition to 9CBS authorization or the author

I have always wanted to write things for BCB beginners to get started quickly, and I wrote a few "chat BCB" to learn how to solve the difficult point in BCB. I didn't expect it to be ill. I don't want to write, but what do these things can do? Still use another method to reread my thinking, have been a little busy recently, the article that has not been written, I will finish it as soon as possible, as for "in-depth QR", I think I will definitely use another The method of writing, let you see all the clothes of this delicate clothes, don't sort it to this point, I don't dare to take it out, please forgive me!

This paper is divided into "foundation entry", "rapid improvement" and "successful programmer".

Part 1: Basic entry

Vendor

1) Q: What is the implementation of Windows is implemented on the form of a form, how does C Builder deal with the form?

A: Some of the functionality of the form is implemented through the properties of the form, and the properties of the form are large, and only the more important properties are described here.

1. ActiveControl Specifies a component on the form to enter the focus. The following statement becomes the Label1 component on the form into an input focus: ActiveControl = label1. At the same time, the application can only have an input focus.

2. Bordericons is used to set which system icons appear on the title bar. It is a collection that can be set to the following: Maximize button (BIMAXIMIZE), a Biminimize, a Bihelp, and a BiheStemmenu.

3. The icon property is used to specify the icon displayed when the form minimizes.

4. When the keypreview property is True, the indicating that the keystroke event is transmitted to the form, and then transmitted to the component with input focus, which is equivalent to the form of an event that is originally a component. The default value is false, and the indicator key event is only sent to the component currently available in the input focus.

5. The MENU attribute is used to specify the main menu of the form.

6. Visible properties are used to determine if the form is visible.

There are also some runtime attributes that can only be accessed by programming when running in the program. This property is mainly:

The Active property is used to determine if the form gets the input focus. ActiveMdichild This function will return the current active sub-form. The DROPTARGET property is used to specify whether the form is an object of drag and drop operations. The Parent property is used to set a window control containing the form, usually another form. If the form does not contain its control, then its Parent property is NIL.

2) Q: The Windows form has a lot of styles, such as dialogs, pops up. What should I do if I want to control the boundary style of the form?

A: Attribute BorderStyle can specify the appearance and behavior of the form boundary. It has six possible values.

BSDialog indicates a standard dialog boundaries that are non-variable. BSSINGLE represents a single-line boundary of the size. BSnone indicates that the size is constant, there is no boundary. Bssizeable represents a standard changeable form. BSTOOLWINDOW is similar to Bssingle, but the title is smaller and use the toolbar window. Bssizetoolwin is similar to Bssizeable, but the title is smaller, do the toolbar window.

It should be noted that for MDI subforms, BSDIALOG or BSNONE will not work.

3) Q: What is the difference between ActiveControl and setfocus ()? A: ActiveControl is to give the focus to the component, which is an attribute. And setfocus () is a way to operate the action, it is a method. Writing format is different. For example, we want to get the same button1 to get focus, you can write two ways:

ActiveControl = Button1 or Button1 = setfocus ()

The role is the same, but it is generally used to use the first way.

4) Q: What is the role of the property formstyle?

A: The property formStyle can determine the type of the form, which has four attribute values.

FSNORMAL indicates that the form is neither the MDI parent window nor the MDI sub-window, only possible to a single document SDI window or dialog. This attribute value is the default. fsmdichild means that this form is an MDI sub-window. FSMDIFORM means that this form is an MDI parent window. FSSTAYONTOP indicates that the form is always maintained above the other forms of the project, unless otherworm's FormStyle attributes are also set to FSSTAYONTOP.

It is important to note that do not modify the formstyle attribute of the form during the program run.

5) Q: What is the role of property position?

A: The property Position can determine the size and location of the form that appears on the screen when the program is running, which has five possible values.

1. Podesigned indicates that the form is displayed when designing the size and location properties specified using the design. Size properties refer to Height and Width, location attribute refers to Left and TOP. This attribute value is the default.

2. Podefault indicates that the location and size displayed on the screen is determined by Windows. When you run an application, the form will move slightly to the right.

3. PodefaultPosonly represents a form size display form when designing, but the location displayed on the screen is determined by Windows. When you run an application, the form will move slightly to the right. When moving downwards, it will start from the upper left corner of the screen.

4. Podfaultsizeonly indicates the value specified by the form of the form, and the size is determined by Windows.

5. PoschangeCenter represents the size and location properties specified using the design, display the form on the center of the screen.

6) Q: How to maximize or minimize the form?

A: The attribute WindowState is related to the display of the form, which has three possible values.

The WSNORMAL form is neither to maximize the display. This value is the default. The WSMinimized form minimizes the display. The WSMaximized form maximizes the display.

7) Q: What is the role of attributes CLIENTHEIGHT and CLIENTWIDTH?

A: These two attributes are used to define the high and width of the form user area. The actual work area of ​​the so-called user regional form is the form of the form of the form, the menu bar, the toolbar, and the state bar and the form area other than the border. So for newly created forms, its user area is slightly smaller than the size of the form, relatively, the size of the form is determined by the attribute height and width.

8) Q: How to dynamically create a form?

A: We first create a main form mainform, change her CAPTION to "Main Fact", and change the FormStyle property to FSMDIFORM. Create a child form Windows1, change the CAPTION to "Subform", change the FormStyle property to fsmdichild. Select the "Project | Options ..." menu item that will pop up a dialog shown in the figure.

Here we can select the main form by drop-down, list all the windows in the auto-create forms on the left, which is usually dynamically created, you can create a window that you need to create ( Available Forms) Turn to the right through the four buttons in the middle, then OK is OK.

The way the dynamic creation is as follows:

Void _fastcall tform1 :: button1click (TOBJECT * Sender)

{

TFORM2 * FORMS;

Try

{

Form2 = new TFORM2 (Application); // Dynamically create FORM2

FORM2-> ShowModal ();

Delete form2; // Release FORM2

}

Catch (Exception & Exception)

{

DELETE FORM2;

Application-> Showexception (& Exception);

}

}

Be careful that you may not like to use the above form, and write it into the following format:

Void _fastcall tform1 :: button1click (TOBJECT * Sender)

{

TFORM2 * FORMS;

Form2 = new TFORM2 (Application); // Dynamically create FORM2

......

}

You have to remember, whether your child has created whether it is done, you must run DELETE to release the sub-form you just created, and of course you can write the release process in the onClose event function, this function has a parameter. For action, it has four values: Canone is not closed, nothing; cahide is not closed, but hides it; cafree is turning off the form, simultaneous memory; caminimize is the minimum window Body, not close. So we can also release the subform like this.

Void _fastCall TFORM2 :: FormClose (Tobject * Sender, Tclosection & Action)

{

Action = CAFREE;

}

9) Q: Why can't we use Close () Can't close my current sub-form?

A: Close the current active form, many people will use the following methods:

Void _fastcall TFORM1 :: Button2Click (Tobjcet * Sender)

{

Activemdichild-> Close (); // Note that this is in the main form (or in other forms) to turn off the current active sub-form, this is not good, the general closure should be like 10) asked do

}

At this time, the form is not closed, but minimizes, so it is to be turned off with the following code in the ONCLOSE event of the subform.

Void _fastCall TFORM2 :: FormClose (Tobject * Sender, Tclosection & Action)

{

Action = CAFREE;

}

This program doesn't have to say more, and it has said it.

Here is something to explain, that is, when calling Close (), the ONCLOSE event is automatically triggered, and we know that the form is not closed, but minimizes, the value of this at this time is Caminimize. So we have to write the above method to close. 10) Q: What is the difference between show () and ShowModal ()?

A: There is no possibility in our program, such as two windows, with Form1 and Form2, we call Form2 in Form1 should first join:

#include "unit2.h"

Add in places to call:

FORM2-> show (); // or form2-> showModal ();

The difference between the two is that if ShowModal () must be used, it must be turned off to handle the content of other windows, while show () is not available. Of course, you can create a Button1 directly in Form2 to close her, the program content is as follows:

Void _fastcall TFORM2 :: Button1Click (Tobject * Sender)

{

CLOSE ();

}

Before close, you don't need to add FORM2 because this line program is running on Form2, so the default parent component is Form2.

(to be continued)

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

New Post(0)