Delphi Standard Control-radio button group

Source: Internet
Author: User

A radio button group (Radiobox) is a combination of radio buttons. When we need to select different radio buttons, we need to use radio button groups in order to make the different groups interfere with each other.

The radio button group has two important attributes: Items and itemindex. Select the Radiobox component on the form double-click the Items property on the object Viewer to open a dialog box, as shown in the following illustration:

Enter each title in the edit window of the dialog box, one line per item.

The ItemIndex property is used to indicate which item in the radio button group is selected. If-1 (the default), an item that is not selected, or 0, the first item is selected, or 1 to indicate that the second item is selected;

We use the radio button group instead of the radio button, and add the font selection feature, based on the text editor we prepared earlier. The program uses two Radiogroup components, the properties are as follows:

Property RadioGroup1 RadioGroup2
Caption Color Font
Items red; blue; green. Aria;symbol the body of a song;
ItemIndex 0 2

Since RadioGroup1 's intemidex is 0, the first item is the initially selected item, or "Red" is selected, so the program should set the text color in Memo1 to red when it initializes, and the RADIOGRUOP2 's initial entry is the third "Arial" (ItemIndex is 2), you should also set the memo text font to Arial when initialized. The initialization statement is placed in the Form1 OnCreate event, which is the initial setting of the memo component when the form is created. The corresponding procedure is as follows:

Procedure Tform1.formcreate (Sender:tobject);
Begin
Memo1. Lines.text:= ' Here is the Radiogroup component sample ';
Memo1. font.color:=clred; Set the initial color of the text to red
Memo1. font.name:= ' song body '//Set text font to Arial
End

The program code to change the font color is as follows:

Procedure Tform1.radiogroup1click (Sender:tobject);
Begin
If Radiogroup1. Itemindex=0 Then
Memo1.font.color:=clred
else if Radiogroup1. Itemindex=1 Then
Memo1.font.color:=clblue
Else
Memo1.font.color:=clgreen;
End

The program code to change the font is as follows:

Procedure Tform1.radiogroup2click (Sender:tobject);
Begin
If Radiogroup2. Itemindex=0 Then
memo1.font.name:= ' Arial '
else if radiogroup2. Itemindex=1 Then
memo1.font.name:= ' Symbol '
else memo1.font.name:= ' song body ';
End

The program interface is shown in the following illustration:

The complete program code is as follows:

Unit Unit1; Interface uses Windows, Messages, Sysutils, Classes, Graphics, Controls, Forms, Dialogs, Stdctrls, Extctrls; Type TFORM1 = Class (Tform) Memo1:tmemo; Button1:tbutton; Savedialog1:tsavedialog; Opendialog1:topendialog; Button2:tbutton; Button3:tbutton; Button4:tbutton; Button5:tbutton; Button6:tbutton; Button7:tbutton; Checkbox1:tcheckbox; Checkbox2:tcheckbox; Checkbox3:tcheckbox; Radiogroup1:tradiogroup; Radiogroup2:tradiogroup; Procedure Button1Click (Sender:tobject); Procedure Formcreate (Sender:tobject); Procedure Button2click (Sender:tobject); Procedure Button5click (Sender:tobject); Procedure Button6click (Sender:tobject); Procedure Button3click (Sender:tobject); Procedure Button4click (Sender:tobject); Procedure Button7click (Sender:tobject); Procedure Checkbox1click (Sender:tobject); Procedure Checkbox2click (Sender:tobject); Procedure Checkbox3click (Sender:tobject); Procedure Radiogroup2click (Sender:tobject); Procedure Radiogroup1click (Sender:tobject); Private {Private declarations} public {public declarations} end; var Form1:tform1; Implementation {$R *. DFM} procedure Tform1.button1click (Sender:tobject); Begin MEMO1. Lines.add (' Add text at end '); End Procedure Tform1.formcreate (Sender:tobject); Begin MEMO1. Lines.text:= ' Here is the Radiogroup component sample '; Memo1. font.color:=clred; The original color of the set text is red Memo1. font.name:= ' song body '//Set text font for the song body end; Procedure Tform1.button2click (Sender:tobject); Begin if memo1.sellength>0 then Memo1.cuttoclipboard; End Procedure Tform1.button5click (Sender:tobject); Begin if Savedialog1. Execute then Memo1. Lines.savetofile (Savedialog1. FileName); End Procedure Tform1.button6click (Sender:tobject); Begin if Opendialog1.execute then Memo1. Lines.loadfromfile (Opendialog1. FileName); End Procedure Tform1.button3click (Sender:tobject); Begin if memo1.sellength>0 then Memo1.copytoclipboard; End Procedure Tform1.button4click (Sender:tobject); Begin if memo1.sellength=0 then Memo1.pastefromclipboard; End Procedure TFORM1.BUTTON7CLIck (Sender:tobject); Begin close; End Procedure Tform1.checkbox1click (Sender:tobject); Begin if CheckBox1. Checked=true then Memo1.font.style:=memo1.font.style+[fsbold] else memo1.font.style:=memo1.font.style-[fsbold]; End Procedure Tform1.checkbox2click (Sender:tobject); Begin if CheckBox2. Checked=true then Memo1.font.style:=memo1.font.style+[fsitalic] else memo1.font.style:=memo1.font.style-[fsitalic] ; End Procedure Tform1.checkbox3click (Sender:tobject); Begin if Checkbox3. Checked=true then Memo1.font.style:=memo1.font.style+[fsunderline] Else memo1.font.style:=memo1.font.style-[ Fsunderline]; End Procedure Tform1.radiogroup2click (Sender:tobject); Begin if Radiogroup2. Itemindex=0 then memo1.font.name:= ' Arial ' else if radiogroup2. Itemindex=1 then memo1.font.name:= ' Symbol ' else memo1.font.name:= ' song body '; End Procedure Tform1.radiogroup1click (Sender:tobject); Begin if Radiogroup1. Itemindex=0 then memo1.font.color:=clred else if Radiogroup1. Itemindex=1 then Memo1.font.color:=clblue ELSE Memo1.font.color:=clgreen; End End.

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.