[CB] TFORM application skills

xiaoxiao2021-03-06  16

First, let the window always in front

The form's FormStyle property is set to the fsstayontop value.

Second, dynamically call form form

By default, the form generated by the File / New Form is generated in the process of adding a project file with "Auto Create" features. That is, as long as the program is running, the form exists in memory, regardless of whether it is called. Forms with this feature are generally applicable to the case where the form properties are fixed, often called. The advantage is that the speed is fast, and the disadvantage is to take up memory. In the actual programming, a large number of forms of similar dialog function will meet, they are used to display status or input information, and only need to call it in the program, complete their function, no resident memory. At this point, you can move the corresponding form in the "Auto - Create Forms" by selecting Project / Options / Forms, such as Form1, with the ">" box, and call the window in the program. The body is added to the following statement:

TFORM1 * MyForm = New TFORM1 (THIS);

MyForm-> showModal ();

DELETE myForm;

The form FORM1 is only transferred in memory when it is called, and after the call is complete, it is cleared with delete. This reduces the occupancy of the program to memory resources.

Third, the method of traversing the form control

To access or modify the control on the form, the method is simple, with TEDIT as an example:

Edit1-> Text = "";

Edit2-> Text = ""

However, if there is ten controls like Edit1 on the form, you need to initialize the same initialization, and use the above method one by one, you will not bother! So it is necessary to master the method of trailing form controls. Before introducing this method, let's take a look at the form Form's Components and Controls properties. See Table 1.

Table I

Property Type Description

ComponentCount INT currently the total number of controls on Form

Components Tcompont * currently point to array of all controls on Form

ControlCount Int currently has the total number of controls on a sub-area on the Form

Controls tcontrol * Current Form points to array of all controls on a sub-area

Take the figure as an example (figure) description, FORM1's ComponentCount = 6, while panel1's controlcount = 4.,

among them:

Array object

Components [0] panel1

Components [1] label1

Components [2] Edit1

Components [3] label2

Components [4] Edit2

Components [5] Button1

Array object

Controls [0] label1

Controls [1] edit1

Controls [2] label2

Controls [3] Edit2

The following code completed the initialization initialization of all TEDIT controls on Panel1. The reader can be changed slightly to traverse other controls. There is a small trick here, and we put the controls that need to be initialized on a panel1, distinguish between controls that do not need to initialize, so that it is easy to program.

Ansistring namestring = "tedit";

For (int i = 1; i controlcount; i )

{

IF (Panel1-> Controls [I] -> ClassNameis (NameString)) {

TEDIT * P = Dynamic_cast (Panel1-> Controls [i]);

P-> Text = "";

}

}

Fourth, irregular window

1. In the window definition, add HRGN HWNDRGN;

2. On the TForm :: OnCreate () message function, join the following code:

HWndRGN = :: CreateelllipticRGN (0,0, width, height);

:: setWindowRgn (HWndRGN, True);

3. Set the properties of TFORM to no title, no border.

4. Compile the application to see an elliptical window.

Five, MDI Form

1.Application-> Createform (__ classid (tjcginput),

& JJCGINPUT);

It is not necessary to use the statement that uses the FORM to display it.

2.Form's OnClose event must be released with the following statement:

Void

__fastcall tmdichild :: formclose (Tobject * Sender, Tclosection & Action)

{

Action = CAFREE;

}

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

New Post(0)