home *** CD-ROM | disk | FTP | other *** search
/ PC Open 19 / pcopen19.iso / Zipped / CALMIR21.ZIP / SOURCE.ZIP / VCL / LABELSEL.PAS < prev    next >
Encoding:
Pascal/Delphi Source File  |  1998-02-20  |  2.2 KB  |  85 lines

  1. {*********************************************************}
  2. {                                                         }
  3. {    Calmira Visual Component Library 2.1                 }
  4. {    by Li-Hsin Huang,                                    }
  5. {    released into the public domain January 1998         }
  6. {                                                         }
  7. {*********************************************************}
  8.  
  9. unit LabelSel;
  10.  
  11. { TLabelSelect is an edit box descendant that places itself
  12.   over TLabel controls so that users can select the label
  13.   text and copy it.  Only one TLabelSelect is required per
  14.   form, which uses fewer window handles if you have manu labels.
  15.  
  16.   It is also useful for label captions that are too long to
  17.   fit the width of the window -- TLabelSelect scrolls so they
  18.   can see the rest of the text.
  19.  
  20.   To use this control :
  21.  
  22.   1. Drop one somewhere on your form.
  23.   2. Select all relevant labels.
  24.   3. If required, set the label's AutoSize property to False.
  25.   4. Assign each label's OnMouseDown event to the same handler:
  26.      if Button = mbLeft the LabelSelect1.Overlay(Sender as TLabel);
  27. }
  28.  
  29. interface
  30.  
  31. uses
  32.   SysUtils, WinTypes, WinProcs, Messages, Classes, Graphics, Controls,
  33.   Forms, Dialogs, StdCtrls;
  34.  
  35. type
  36.   TLabelSelect = class(TEdit)
  37.   private
  38.     { Private declarations }
  39.   protected
  40.     { Protected declarations }
  41.   public
  42.     { Public declarations }
  43.     constructor Create(AOwner : TComponent); override;
  44.     procedure Overlay(L : TLabel);
  45.   published
  46.     { Published declarations }
  47.   end;
  48.  
  49. procedure Register;
  50.  
  51. implementation
  52.  
  53. constructor TLabelSelect.Create(AOwner : TComponent);
  54. begin
  55.   inherited Create(AOwner);
  56.   ParentCtl3D := False;
  57.   ParentShowHint := False;
  58.   Ctl3D := False;
  59.   Color := clSilver;
  60.   AutoSelect := False;
  61.   BorderStyle := bsNone;
  62.   ReadOnly := True;
  63.   ShowHint := True;
  64.   Visible := False;
  65. end;
  66.  
  67. procedure TLabelSelect.Overlay(L : TLabel);
  68. begin
  69.   Visible := False;
  70.   if Parent <> L.Parent then Parent := L.Parent;
  71.   BoundsRect := L.BoundsRect;
  72.   Font := L.Font;
  73.   Text := L.Caption;
  74.   Hint := L.Hint;
  75.   Visible := True;
  76.   SetFocus;
  77. end;
  78.  
  79. procedure Register;
  80. begin
  81.   RegisterComponents('Calmira', [TLabelSelect]);
  82. end;
  83.  
  84. end.
  85.