RAD Studio VCL Reference
|
Occurs when the user changes the text displayed in the edit region.
property OnChange: TNotifyEvent;
__property TNotifyEvent OnChange;
Write an OnChange event handler to take specific action immediately after the user edits the text in the edit region or selects an item from the list. The Text property gives the new value in the edit region.
C++ Examples:
/* This example requires a TPageControl already on the form. Also, you must add pages to the TPageControl by right clicking and selecting New Page. The example code will allow the user to select the ActivePage property through selection of a ComboBox item. During the form create, the Combo Box control is loaded with the names of each of the tabs, as well as the instance pointers to the corresponding tab. When the user selects the Combo Box item, the associated TTabSheet object contained in the Combo Box Objects array is used to set the ActivePage property. Select the Lines property of the TRichEdit to enter a string. Select the string before justifying. */ void __fastcall TForm1::ComboBox1Change(TObject *Sender) { TComboBox *pCB = dynamic_cast<TComboBox *>(Sender); if (pCB) PageControl1->ActivePage = dynamic_cast<TTabSheet *>(pCB->Items->Objects[pCB->ItemIndex]); } void __fastcall TForm1::FormCreate(TObject *Sender) { const TColor colorPalette[12] = { clRed, clGreen, clYellow, clBlue, clWhite, clFuchsia, clTeal, clNavy, clMaroon, clLime, clOlive, clPurple}; for (int i = 0; i < PageControl1->PageCount; i++) { PageControl1->Pages[i]->Brush->Color = colorPalette[i]; ComboBox1->Items->AddObject(PageControl1->Pages[i]->Name, PageControl1->Pages[i]); } ComboBox1->ItemIndex = 0; PageControl1->ActivePage = dynamic_cast<TTabSheet *>(ComboBox1->Items->Objects[ComboBox1->ItemIndex]); }
/* The following example assumes that a drive combo box, a file list box, and a directory list box are on a form. Add this code as the OnChange event handler for the drive combo box and the OnChange event handler for the directory list box. When the user changes the drive using the combo box, the directory list box and file list box will update to reflect the new drive and the current directory on that drive. When the user double clicks on a directory in the file list box will update to reflect the new directory. */ void __fastcall TForm1::DriveComboBox1Change(TObject *Sender) { DirectoryListBox1->Drive = DriveComboBox1->Drive; FileListBox1->Drive = DriveComboBox1->Drive; FileListBox1->Directory = DirectoryListBox1->Directory; } void __fastcall TForm1::DirectoryListBox1Change(TObject *Sender) { FileListBox1->Directory = DirectoryListBox1->Directory; }
Delphi Examples:
{ This example requires a TPageControl already on the form. Also, you must add pages to the TPageControl by right clicking and selecting New Page. The example code will allow the user to select the ActivePage property through selection of a ComboBox item. During the form create, the Combo Box control is loaded with the names of each of the tabs, as well as the instance pointers to the corresponding tab. When the user selects the Combo Box item, the associated TTabSheet object contained in the Combo Box Objects array is used to set the ActivePage property. Select the Lines property of the TRichEdit to enter a string. Select the string before justifying. } procedure TForm1.FormCreate(Sender: TObject); var i: Integer; const colorarray : Array[0..4] of TColor = ( clYellow, clGreen, clBlue, clLime, clFuchsia); begin for i := 0 to PageControl1.PageCount - 1 do begin PageControl1.Pages[i].Brush.Color := colorarray[i]; ComboBox1.Items.AddObject(PageControl1.Pages[i].Name, PageControl1.Pages[i]); end; ComboBox1.ItemIndex := 0; PageControl1.ActivePage := TTabSheet(ComboBox1.Items.Objects[ComboBox1.ItemIndex]); end; procedure TForm1.ComboBox1Change(Sender: TObject); begin if (Sender is TComboBox) then with (Sender as TComboBox) do PageControl1.ActivePage := TTabSheet(Items.Objects[ItemIndex]); end;
{ The following example assumes that a drive combo box, a file list box, and a directory list box are on a form. Add this code as the OnChange event handler for the drive combo box and the OnChange event handler for the directory list box. When the user changes the drive using the combo box, the directory list box and file list box will update to reflect the new drive and the current directory on that drive. When the user double clicks on a directory in the file list box will update to reflect the new directory. } procedure TForm1.DirectoryListBox1Change(Sender: TObject); begin FileListBox1.Directory := DirectoryListBox1.Directory; end; procedure TForm1.DriveComboBox1Change(Sender: TObject); begin DirectoryListBox1.Drive := DriveComboBox1.Drive; FileListBox1.Drive := DriveComboBox1.Drive; FileListBox1.Directory := DirectoryListBox1.Directory; end;
Copyright(C) 2009 Embarcadero Technologies, Inc. All Rights Reserved.
|
What do you think about this topic? Send feedback!
|