2. Text input components
11) Q: What should I do if I want to implement text input? What should I do in C Builder?
Answer: C Builder Common text input components to implement, commonly used text input components include Edit, Maskedit, Memo, and Richedit. Their main difference is that Edit and Maskedit are used to enter a single line of text, while MEMO and Richedit can enter multiple lines of text. In addition, the Label component can also be used for text display.
Edit and Maskedit are a window control that allows you to get an input focus. The edit box should be used when the user needs to enter a single line of text. It is usually used with tag components.
.
12) Q: What are the most common attributes that edit boxes (Edit)?
A: Several properties for editing boxes are as follows:
The Text property is a string type of data that determines the text string that appears in the edit box. In the programming, we often get the text string in the edit box through the Text property.
MaxLength is an Integer type data that specifies the maximum number of characters that the edit box can accommodate. Default is 0, indicating that the length is not limited.
The edit box can also be used for password input. The specific method is to set the PasswordChar property to any character other than # 0. At this time, no matter what character you entered in the edit box, only the character contained in PasswordChar is displayed. We often set the passwordchar as an asterisk *, which only shows an asterisk when the user enters the password. If entering # 0 means the edit box is normally displayed. PasswordChar is a character type of data.
If you want to restrict the right to write on the edit box. You can use properties readonly, read only when Readonly's value is TRUE.
13) Q: What is the role of label control (Label)?
A: The common attribute of the label has Caption and FocusControl.
The CAPTION property is a string type, used to specify the title of the label, that is, the display content of the label.
The FocusControl property is a window control class that specifies a window control connected to the label. This allows this control to be used to get the input focus using shortcuts.
The label is a typical non-window control that cannot get an input focus, so it is often used to give some components without a Caption property. The label can also provide shortcuts to these components at the same time, allowing users to get input focus by shortcuts.
14) Q: How do you use CAPTION and FOCUSCONTROL in Label?
A: Let's take an example (this example will be used in Section 19):
First, you need to specify a shortcut key when entering the title, which can be used in front of a letter to add a consecutive character & Click the CAPTION property input bar, enter the & n name, where the letter N is specified as a shortcut. It should be noted that Chinese cannot be specified as a shortcut, only 26 English letters can be.
Then, connect the label's FocusControl property to the edit box Edit1, select the FocusControl property, select EDIT1 in all window controls from the Forms listed in the Properties field. This way the user presses Alt N, the input focus will be transferred to the edit box Edit1.
15) Q: I have encountered some programs. When I have finished the text in the editor, press Enter key, the program starts, how should C Builder implement?
A: Of course you can. When we press the Enter key, an OnkeyPress event is generated. So if you want to handle this event in the program, you have to write an onkeyPress event handler. There are three events being an edit box common event: onchange event, anones and oneXIT. The ONCHANGE event is triggered whenever the text in the edit box changes. When the edit box gets the input focus, the OneNter event is triggered, and the OneXIT event will be generated when the focus is lost.
16) Q: Simply talk about the important properties of MEMO components?
A: Memo has a lot of properties with Edit, and only the important properties of the MEMO component are only.
The Lines property is an object of a TStrings class, which consists of multiple strings, each of which is an element in Lines. Each line of text of the MEMO component is a string in Lines.
In the design phase, if you want to add some display content to the MEMO component, you can select Properties Lines in the Object Editor, click the Optional button on the Value column, and you will open a string editing window.
Enter text in this editor. All content displayed in the editor will appear in the MEMO component.
MEMO component properties:
Alignment is used to determine how the text is displayed in the MEMO component. WordWrap determines whether the text arrives at the right boundary When the Want Row Wantreturn determines whether the user can insert the carriage return in the text. WantTabs determines if the user can insert Tab characters in the text.
Property ScrollBar is a common property that determines the behavior of scrolling components scroll bar. ScrollBar has four possible values:
Ssnone indicates no scroll bar; SSHORIZONAL represents only horizontal scroll bars; SSVertical means that only vertical strips; SSBoth represents both horizontal scroll bars and vertical scroll bars.
When the content displayed is more, SSBoth should be selected so that users can be used to see all content.
17) Q: What should I do if I want to modify the display content of the MEMO component during the program operation?
A: This requires some properties and methods of the TSTRINGS class. For example, add a sentence to the MEMO component "I am here", you can use the method add to complete.
LINES-> Add ("I am coming");
To look for a row in MEMO, you can use the form of lines-> strings [n], but pay attention to the string of Lines starting from 0, so when the line number is corresponding to the actual line number in MEMO, the line number needs to be reduced. .
18) Q: What should I do if I want to achieve the cutting, copying and paste?
A: The MEMO component provides three ways to complete cut, copy, and paste. CutToClipboard is used to cut text selected in the MEMO component to the clipboard.
CopyToClipboard is used to copy text selected in the MEMO component to the clipboard.
The PastefromClipboard is used to paste the contents of the shear plate to the position where the cursor is located in the MEMO component.
19) Q: Can I spend a few controls, can I integrate them to compile a procedure?
A: Ok, use the components that have just been put to write a user name entry and display.
This program will be implemented when entering text in the edit box and pressing the Enter key, the text is added to the MEMO component. Therefore, it is necessary to add an event processing process to the edit box component.
The ONKEYPRESS event is generated when the user presses the Enter, so the processing of this event should be written.
Select the component edit1,
Select the Events tab on the object viewer,
Double-click EDIT1 event onkeypress, C Builder automatically generates this event handler's code template. Write the following code inside: void __fastcall tform1 :: edit1keypress (TOBJECT * Sender, Char & Key)
{
Ansistring Temp ("User Name:");
IF ((Key == 0xD) &&! edit1-> text.isempty ())
Memo1-> lines-> add (temp edit1-> text);
}
Or is a better understanding of the following formats, they are the same.
Void __fastcall tform1 :: edit1keypress (TOBJECT * Sender, Char & Key)
{
Ansistring Temp = "User Name:";
IF ((Key == VK_RETURN) && Edit1-> Text! = "")
Memo1-> lines-> add (temp edit1-> text);
}
When the user enters the text and press the Enter key, the third statement merges TEMP and the user entered the end of the MEMO control text.
Now, click the Run button on the speed bar, run this program, enter a user name in the Edit box, and press Enter. The user's name is automatically added to the end of the text box.
Use the mouse to click on the MEMO control, move the focus to it, then press the Alt N accelerator key, you can see that the tag control moves the focus into the edit box.
20) Q: There is a component Richedit in the BCB almost a write-board, learning her, pay attention to those attributes?
A: As long as you can set the default character format defattribute, set the character format selattribute and set paragra to set paragraphs three attributes, because her other properties are almost almost.
The default character format defattribute, setting the character format selattribute is the TtextAttributes object, which is used to control the character format, its color, height, name, size, style, pitch isotheby, and font TFONT objects, and of course there are some Improving at least useful properties such as Charset, ConsistentAttributes, protected, and more.
Setting paragraground is a TParattributes object that sets the alignment of paragraphs, the first line indent the firstindent, left harvested to LEFTINDENT, right indent RightIndent, Numbering, Tab Tab, etc.
The alignment of paragraphs Alignment is TaleftJustify left alignment, Tacenter is aligned with TATIGHTJUSTIFY.
Number Numbering, is used to set the number, take the nsnone to indicate that there is no number, and the NSBULET is used to indicate the number of hanging indenges.
The tab Tab is used to set the location where a certain epitope is located. It is: _Property int Tab [Byte Index]. The first surface is tab [0], and it is pushed.
Note: All routines in this article are compiled under BCB6 and WinXP.
(to be continued)