38) Q: You can describe the scrolling event of the scroll bar, what is the difference?
A: Event onchange and onscorll are different. As long as the value of property Position changes, no matter whether this value is caused by the user's operational scroll bar, the ONCHANGE event will be generated by the program. The Onscorll event only happens when the user operates scroll bar. When the user operates the scroll bar, the onscorll event will occur first, and the ONCHANGE event will occur.
Below we look at a program to deepen the understanding of the scroll bar.
Place a horizontal scroll strollbar1 and a vertical scroll scrollbar2 on the form, and a MEMO component that records the scroll bar event. When the user operates a scroll bar, an event occurs in the MEMO component.
Select the MEMO component to set its ScrollBars property to SSVertical.
Select the horizontal scroll bar assembly, double-click the Value domain of OnScroll, and the system will generate an event processing template to enter such a code.
Void __fastcall tform1 :: scrollbar1scroll (TOBJECT * SENDER,
Tscrollcode Scrollcode, Int & Scrollpos
{
Ansistring Temp;
IF (sender == scrollbar2)
Temp = "Vertical Rolling Bar";
Else
Temp = "horizontal scroll bar";
Switch (scrollcode)
{
Case SCLINEUP: Temp = "SCLINEUP"; BREAK;
Case Sclinedown: Temp = "SCLINEDOWN"; BREAK;
Case SCPageUp: Temp = "SCPAGEUP"; BREAK;
Case SCPAGEDOWN: TEMP = "SCPAGEDOWN"; BREAK;
Case SCPSITION: TEMP = "SCPSITION"; Break;
Case Sctrack: Temp = "Sctrack"; Break;
Case Sctop: Temp = "SCTOP"; Break;
Case SCBOTTOM: TEMP = "SCBOTTOM"; BREAK;
Case Scendscroll: Temp = "Scendscroll"; Break;
DEFAULT:
TEMP = "unknown"; Break;
}
Memo1-> Lines-> Append (Temp "Events");
}
The first statement declares a variable of an ANSISSTRING type to store the string to be displayed.
The second statement determines the object of the transmitting event. If it is a vertical scroll bar, the TEMP initializes the "vertical scroll bar", otherwise it will initialize "horizontal scroll bar".
The third statement displays the corresponding event according to the value of ScrollCode.
The last statement adds the string to the display to the end of the text box.
Select the vertical scroll bar assembly in the form, select the Events tab, click on onScroll VALUE field, select the ScrollBar1Scroll event handler from the drop-down list box. Thus, the vertical scroll bar and the horizontal scroll bar will share an event handler.
Select the horizontal scroll bar assembly, select the Events tab, double-click the onchange domain, then enter:
Memo1-> lines-> append ("ONCHANGE event" of horizontal scroll bar); it will display information changed horizontal scroll after the text box.
Similarly, add the following code to the ONCHANGE event of the vertical scroll bar:
Memo1-> lines-> append ("ONCHANGE Events of Vertical Vertical Bar";
The detailed code is as follows:
/ / -------------------------------------------------------------------------------------------- ---------------------------
#include
#pragma HDRSTOP
#include "unit1.h"
/ / -------------------------------------------------------------------------------------------- ---------------------------
#pragma package (smart_init)
#pragma resource "* .dfm"
TFORM1 * FORM1;
/ / -------------------------------------------------------------------------------------------- ---------------------------
__fastcall tform1 :: tform1 (tComponent * Owner)
: TFORM (OWNER)
{
}
/ / -------------------------------------------------------------------------------------------- ---------------------------
Void __fastcall tform1 :: scrollbar1scroll (TOBJECT * SENDER,
Tscrollcode Scrollcode, Int & Scrollpos
{
Ansistring Temp;
IF (sender == scrollbar2)
Temp = "Vertical Rolling Bar";
Else
Temp = "horizontal scroll bar";
Switch (scrollcode)
{
Case SCLINEUP: Temp = "SCLINEUP"; BREAK;
Case Sclinedown: Temp = "SCLINEDOWN"; BREAK;
Case SCPageUp: Temp = "SCPAGEUP"; BREAK;
Case SCPAGEDOWN: TEMP = "SCPAGEDOWN"; BREAK;
Case SCPSITION: TEMP = "SCPSITION"; Break;
Case Sctrack: Temp = "Sctrack"; Break;
Case Sctop: Temp = "SCTOP"; Break;
Case SCBOTTOM: TEMP = "SCBOTTOM"; BREAK;
Case Scendscroll: Temp = "Scendscroll"; Break;
DEFAULT:
TEMP = "unknown"; Break;
}
Memo1-> Lines-> Append (Temp "Events");
}
/ / -------------------------------------------------------------------------------------------- ---------------------------
Void __fastcall tform1 :: scrollbar1change (TOBJECT * SENDER)
{
Memo1-> lines-> append ("ONCHANGE Events of Horizontal Scroll Bar";
/ / -------------------------------------------------------------------------------------------- ---------------------------
Void __fastcall tform1 :: scrollbar2change (TOBJECT * SENDER)
{
Memo1-> lines-> append ("ONCHANGE Events of Vertical Vertical Bar";
}
/ / -------------------------------------------------------------------------------------------- ---------------------------
Now, compile and run this program, click on the scroll bar, you can see the event generation of the scroll bar.
Which event is prioritized? Can you see it? You will have two attribute values generated by the onscroll's same event to be separated by ONCHANGE without solving it? When do you want to generate a Scendscroll value J?
In fact, if we want to understand the order between events generated by other components, we can also be implemented in the same way.
39) Q: TRACKBARs have those major properties?
A: The track strip is similar to the scroll bar, and it also has a slider similar to the rolling block, which can be moved with a mouse or use the arrow keys. Some properties of the track strip are identical to the scroll bar, such as max, min, and position. But it still has some special properties.
1. The LINSIZE property is used to specify the distance of the slide block of the track strip when the user presses the arrow key.
2. The PageSize property is used to specify the distance from the sliding block on the track strip when the user presses PGUP and PGDN.
3. The Frequency property is used to set the unit of the track bar. If MAX-MIN is equal to 100, this property is equal to 10, then the track strip is divided into 10 aliquots.
4. The orientation property is used to determine the placement direction of the track strip. It has two values, and TBhorizontal represents horizontal placement, and TBvertical is placed vertically. By default, it is placed horizontally.
5. SELSTART This property is used to set the starting point for the selection.
6. Selend This property is used to set the end point.
7. Tickmarks This property is used to set the location of the track bar ruler. It has three values that represent three different sliding blocks, respectively:
TMBOTTOMRIGHT indicates that the ruler is displayed on the right when the ruler is placed in the vertical placement.
TMTopleft indicates that the ruler is displayed on the left when the ruler is placed on the vertical placement.
TMBOTH indicates that there is a ruler on both sides of the track trace.
8. TickStyle This property is used to determine the style of the track bar ruler. It has three values, which represent three different scale patterns:
TSAUTO indicates the scale of the automatic display of the ruler.
Tsmanual means that you need to use the SetTick process to set the display mark in a certain location.
Tsnone indicates that the ruler does not display the scale.
40) Q: What are the commonly used events in the track strip?
A: When the user operates the track strip with a mouse or keyboard, an onchange event will be generated. However, pay attention to changing the value of the property Position in the program does not generate an onchange event, which is different from the scroll bar.
41) How does ProGressBar use?
A: Its attribute is similar to those of the above components, like Max, Min, orientation, Position with the above meaning of the above. Where Position is the key to this component, it is used to set or return the current location of the fill small square of the process strip, and this location should be the location limit when the end is completed. Smooth: Boolean type, default is false. The filling of this time is performed, if set to TRUE, the padding is smoothed.
Stepby: It declares: void _fastCall Stepby (int Detla); this function is used to fill the process strip, and change the property value of the Position. Its increase amount is specified by the parameter Detla.
Stepit: It is: Void _fastCall Stepit (Void); this function is used to fill the process strip forward, and change the property value of the Position. Its filling step is specified by the Step property.
Step: This property is used to set the amount of Position location when the Stepit function is called. The default is 10.
42) Q: What is the use of the UPDOWN control?
A: This control is a pair of up and down arrow buttons, which will automatically increase or decrease a value when pressing the button. It usually has an accessory component, specified by the Associate property of the Updown control. If this component is an edit box, the edit box automatically displays the value of the properties of the Updown control.
The Updown control also has some of the properties of scroll bars and track bar, such as max, min, position, orientation, and their meaning is basically the same, but the Updown control also has some special properties.
When AlignButton is UDLEFT, it means that the Updown control is placed on the left side of the accessory component, which indicates that the Updown control is placed on the right side of the accessory component.
Associate is used to specify the associated subsidiary component.
The arrowkey property, when the property is TRUE, press the up and down direction key as the up and down arrows pressed by pressing the UPDOWN control. The default is TRUE.
Thousands attribute, when the property is True, if the Position exceeds 1000, then it will automatically add a thousand points to the value displayed. The default is TRUE.
Wrap attributes, when the property is TRUE, if the value of the position is greater than max, then automatically returns to the value specified by the min property. The default is false.
43) Q: What are the common events of the UPDOWN control?
A: The Updown control has two commonly used events: ONCHANGING and ONCLICK. When the user is pressing the up and down arrows, an onchanging event will occur; an OnClick event occurs when the user presses the up and down arrows.
Let's take a look at an example:
Place two EDIT controls on the form, and two Updown controls, values Udhorizontal and udvertage each of the two Updown controls.
The value of the MAX of the second Updown control is 5000, the position value is 100, and their associate attribute is associated with the two edit boxes, respectively. Enter the following code in the corresponding event:
Void_fastcall tform1 :: updown1changeing (Tobject * Sender, Bool & AllowChange)
{
Edit1-> Text = updown1-> position;
}
// Note that the parameter allowchange can be used to specify whether the value of the POSITION property is allowed. Void _fastcall tform1 :: updown2click (Tobject * Sender, tubtntype button)
{
Edit2-> Text = updown2-> position;
}
// Note that the parameter button indicates which button is pressed: btnext is the arrow or the right arrow; btprew is the lower arrow or the left arrow.
44) Q: What is the HotKey component on the right side of Updown?
A: Hotkey Hotkey is used to dynamically specify shortcuts for a component or menu during program operation. In its properties, you only have to remember the HotKey property, this property is used to return the user specified shortcut.
code show as below:
/ / -------------------------------------------------------------------------------------------- ---------------------------
#include
#pragma HDRSTOP
#include "unit1.h"
/ / -------------------------------------------------------------------------------------------- ---------------------------
#pragma package (smart_init)
#pragma resource "* .dfm"
TFORM1 * FORM1;
/ / -------------------------------------------------------------------------------------------- ---------------------------
__fastcall tform1 :: tform1 (tComponent * Owner)
: TFORM (OWNER)
{
}
/ / -------------------------------------------------------------------------------------------- ---------------------------
Void __fastcall tform1 :: x1click (TOBJECT * SENDER)
{
CLOSE ();
}
/ / -------------------------------------------------------------------------------------------- ---------------------------
Void __fastcall tform1 :: hotkey1change (TOBJECT * Sender)
{
X1-> shortcut = HotKey1-> Hotkey; // x1 is the menu name, pay attention to some books introduce with the OneNter event, but I feel wrong, don't prevent you, use Onenter, you will not get any associated J
}
/ / -------------------------------------------------------------------------------------------- ---------------------------
Why use a button1 here? If there is no other component in your program, you will feel the function of the shortcut key, because the focus will stop on the HotKey component, just want to transfer the focus, then try the effect with the shortcut key
(to be continued)