home *** CD-ROM | disk | FTP | other *** search
/ PC Plus SuperCD (UK) 2000 March / pcp161b.iso / handson / archive / Issue157 / delphi / copydelp.exe / properties / propunit.pas < prev   
Encoding:
Pascal/Delphi Source File  |  1999-07-12  |  4.3 KB  |  168 lines

  1. unit propunit;
  2.  
  3. interface
  4.  
  5. uses
  6.   Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  7.   StdCtrls, ExtCtrls;
  8.  
  9. type
  10.   TForm1 = class(TForm)
  11.     PWEdit: TEdit;
  12.     PWBtn: TButton;
  13.     RadioGroup1: TRadioGroup;
  14.     NCRBtn: TRadioButton;
  15.     LCRBtn: TRadioButton;
  16.     UCRBtn: TRadioButton;
  17.     GroupBox1: TGroupBox;
  18.     ColorDialog1: TColorDialog;
  19.     FGColourBtn: TButton;
  20.     BGColourBtn: TButton;
  21.     FontDialog1: TFontDialog;
  22.     FontBtn: TButton;
  23.     CheckBox1: TCheckBox;
  24.     ShortHintBtn: TButton;
  25.     LongHintBtn: TButton;
  26.     HintLbl: TLabel;
  27.     FancyHintBtn: TButton;
  28.     procedure RadioGroup1Click(Sender: TObject);
  29.     procedure RadioButtonCaseChangeClick(Sender: TObject);
  30.     procedure FormCreate(Sender: TObject);
  31.     procedure FGColourBtnClick(Sender: TObject);
  32.     procedure BGColourBtnClick(Sender: TObject);
  33.     procedure FontBtnClick(Sender: TObject);
  34.     procedure CheckBox1Click(Sender: TObject);
  35.     procedure ShortHintBtnClick(Sender: TObject);
  36.     procedure LongHintBtnClick(Sender: TObject);
  37.     procedure PWBtnClick(Sender: TObject);
  38.  
  39.   private
  40.     { Private declarations }
  41.   public
  42.     { Public declarations }
  43.     procedure ShowHint( Sender : TObject );
  44.     procedure FancyHint(var HintStr: string; var CanShow: Boolean;
  45.       var HintInfo: THintInfo );
  46.  
  47.  
  48.   end;
  49.  
  50. var
  51.   Form1: TForm1;
  52.  
  53. implementation
  54.  
  55. {$R *.DFM}
  56. procedure TForm1.FormCreate(Sender: TObject);
  57. // on Form Create, set various properties
  58. begin
  59. // set defaults for PWEdit
  60.    with PWEdit do // =============== Set a few TEDIT Properties ======
  61.    begin
  62.       PasswordChar := #0;    // #0 = no passwordchar
  63.       CharCase := ecNormal;
  64.       MaxLength := 10;
  65.       Autosize := false;
  66.    end;
  67. // Set check items on form
  68.    RadioGroup1.ItemIndex := 0;
  69.    NCRBtn.checked := true;
  70. // === HINTS ===
  71. // i) PWBtn
  72.    PWBtn.Hint := 'Click to show password | You know it makes sense!';
  73.    PWBtn.ShowHint := true;
  74. // ii) Application
  75.    Application.HintColor := clYellow;
  76.    Application.HintPause := 1000;
  77.    Application.HintHidePause := 8000;
  78. // make ShowHint method the OnHint event-handler
  79.    Application.OnHint := ShowHint;
  80. // make FancyHint method the OnShowHint event-handler
  81.    Application.OnShowHint := FancyHint;
  82. // iii) LongHintBtn
  83.    LongHintBtn.Hint := 'This'+#13#10+ 'is a'+#13#10+'multi-line'+#13#10+'hint | This is the long Hint Button';
  84. end;
  85.  
  86. procedure TForm1.RadioGroup1Click(Sender: TObject);
  87. // toggle passwordchar
  88. begin
  89.    if RadioGroup1.ItemIndex = 0 then
  90.       PWEdit.PasswordChar := #0
  91.    else PWEdit.PasswordChar := '*';
  92. end;
  93.  
  94. procedure TForm1.RadioButtonCaseChangeClick(Sender: TObject);
  95. // toggle case
  96. begin
  97.    if UCRBtn.Checked then PWEdit.CharCase := ecUpperCase
  98.    else if LCRBtn.Checked then PWEdit.CharCase := ecLowerCase
  99.    else PWEdit.CharCase := ecNormal;
  100. end;
  101.  
  102. procedure TForm1.FGColourBtnClick(Sender: TObject);
  103. // pick a text colour
  104. begin
  105.    if ColorDialog1.Execute then
  106.       PWEdit.Font.Color := ColorDialog1.Color;
  107. end;
  108.  
  109. procedure TForm1.BGColourBtnClick(Sender: TObject);
  110. // pick a background colour
  111. begin
  112.    if ColorDialog1.Execute then
  113.       PWEdit.Color := ColorDialog1.Color;
  114. end;
  115.  
  116. procedure TForm1.FontBtnClick(Sender: TObject);
  117. // pick a font
  118. begin
  119.   if FontDialog1.Execute then
  120.     PWEdit.Font := FontDialog1.Font;
  121. end;
  122.  
  123. procedure TForm1.CheckBox1Click(Sender: TObject);
  124. // Toggle Edit field's AutoSize property
  125. begin
  126.   PWEdit.AutoSize := CheckBox1.Checked;
  127. end;
  128.  
  129. procedure TForm1.ShowHint( Sender : TObject );
  130. // The OnHint event-handler
  131. begin
  132. // Display the Applications's Hint property in the form caption
  133.   Caption := Application.Hint;
  134. end;
  135.  
  136. procedure TForm1.FancyHint(var HintStr: string; var CanShow: Boolean;
  137.    var HintInfo: THintInfo);
  138. begin
  139.   if HintInfo.HintControl = FancyHintBtn then
  140.   begin
  141.     with HintInfo do
  142.     begin
  143.       HintColor := clFuchsia;
  144.       HintMaxWidth := 30;
  145.       Dec(HintPos.Y, FancyHintBtn.Height * 2 );
  146.       Inc(HintPos.X, FancyHintBtn.Width );
  147.     end;
  148.   end;
  149. end;
  150.  
  151. procedure TForm1.ShortHintBtnClick(Sender: TObject);
  152. begin
  153.    HintLbl.Caption := GetShortHint(PWEdit.Hint);
  154. end;
  155.  
  156. procedure TForm1.LongHintBtnClick(Sender: TObject);
  157. begin
  158.    HintLbl.Caption := GetLongHint(PWEdit.Hint);
  159. end;
  160.  
  161. procedure TForm1.PWBtnClick(Sender: TObject);
  162. begin
  163.   RadioGroup1.ItemIndex := 0;
  164. end;
  165.  
  166. end.
  167.  
  168.