Articles   Members Online:
-Article/Tip Search
-News Group Search over 21 Million news group articles.
-Delphi/Pascal
-CBuilder/C++
-C#Builder/C#
-JBuilder/Java
-Kylix
Member Area
-Home
-Account Center
-Top 10 NEW!!
-Submit Article/Tip
-Forums Upgraded!!
-My Articles
-Edit Information
-Login/Logout
-Become a Member
-Why sign up!
-Newsletter
-Chat Online!
-Indexes NEW!!
Employment
-Build your resume
-Find a job
-Post a job
-Resume Search
Contacts
-Contacts
-Feedbacks
-Link to us
-Privacy/Disclaimer
Embarcadero
Visit Embarcadero
Embarcadero Community
JEDI
Links
How to display information and events in pictures. Turn on/off line numbers in source code. Switch to Orginial background IDE or DSP color Comment or reply to this aritlce/tip for discussion. Bookmark this article to my favorite article(s). Print this article
Hotspot component 29-Mar-05
Category
CLX
Language
Kylix All Versions
Views
289
User Rating
No Votes
# Votes
0
Replies
0
Publisher:
Kleiner, Max
Reference URL:
Max Kleiner
			How can we build a transparent control, like a hotspot? It is transparent, has its 
own hint property and you can even click on it.
To do what you want, just create a descendant of TCustomControl and publish a few
protected properties and events. Especially the masked property is CLX specific. 
To create a transparent control, all you need to do is descend from TCustomControl, 
publish the Masked property (or hard-code it to True at runtime),
and override the Paint() virtual method. Paint() allows you to essentially create a 
design time frame representing the area you want transparent with an overlayed 
bitmap or image. Set an image and select a hotspot to trigger another event.. 
Example: Display a train layout and when you select a part display information 
about that train. Or you'll have to find some easter eggs in a bunny bitmap ;) 

You can call the component at run- or at designtime: 
1   
2   procedure TThreadSortForm.initHotspot;
3   var myhotspot3: THotspot;
4   begin
5   myhotspot3:= THotspot.Create(owner);
6   with myhotspot3 do begin
7     parent:= self;
8     left:= 46;
9     top:=288;
10    width:= 50;
11    height:= 50;
12    hint:=('this is building STARTRAIN');
13    masked:= true;
14    OnMouseEnter:= Hotspot1MouseEnter;
15  end;
16  end;


The method changeCursor in the event OnMouseEnter() changes the cursor after the
constructor, cause the masked property would hide the new cursor at mouse move
time! So FCursor is for further use. 
17  
18  unit hotspot; 
19  // march of 2005 CLX version
20  // cause of masked property no special cursor is available
21  // works best with onmouseEnter ;)
22  
23  interface
24  
25  uses QControls, Classes, QGraphics, SysUtils,
26   QStdCtrls, QTypes, QForms;
27  
28  
29  type
30  THotspot = class(TCustomControl)
31   private
32     FFirstPaint: Boolean;
33     FCursor: TCursor;
34   protected
35     procedure Paint; override;
36   published
37     constructor Create(AOwner: TComponent); override;
38     destructor Destroy; override;
39     procedure changeCursor(howlong_msec: integer);
40     property OnClick;
41     property OnMouseDown;
42     property OnMouseUp;
43     property OnMouseMove;
44     property OnMouseEnter;
45     property OnMouseLeave;
46     property Masked;
47  end;
48  
49  procedure register;
50  
51  implementation
52  
53  procedure THotspot.Paint;
54  begin
55   inherited Paint;
56   if (csDesigning in ComponentState) then
57    if FFirstPaint then begin
58      FFirstPaint:= False;
59      Width:= Width + 1;
60      masked:= false;
61    end else
62    //just the formframe of design time
63    with Canvas do begin
64      Pen.Style:= psDot;
65      Pen.Width:= 1;
66      Pen.Color:= clBlack;
67      Pen.Mode:= pmNotXor;
68      Brush.Style:= bsClear;
69      //brush.Style:= bsSolid;
70      Rectangle(0,0,Width,Height);
71      Rectangle(1,1,Width-1,Height-1);
72    end;
73  end;
74  
75  //old style in windows
76  {procedure THotspot.CreateParams(var Params: TCreateParams);
77  begin
78   inherited CreateParams(Params);
79   Params.ExStyle := Params.ExStyle or ws_ex_Transparent;
80  end;}
81  
82  constructor THotspot.Create(AOwner: TComponent);
83  begin
84   inherited Create(AOwner);
85   Width:= 100;
86   Height:= 100;
87   FFirstPaint:= True;
88   Cursor:= crHandPoint;
89   FCursor:= crDefault;
90   //transparentmode
91   //controlstyle:= controlstyle -[csOpaque];
92   showhint:= true;
93   masked:= true;
94  end;
95  
96  
97  procedure THotspot.changeCursor(howlong_msec: integer);
98  var save_cursor: TCursor;
99  begin
100  save_cursor:= screen.Cursor;
101  try
102    screen.Cursor:= crHandPoint;
103    //howlong in milliseconds
104    sleep(howlong_msec);
105  finally
106    screen.Cursor:= save_cursor;
107  end;
108 end;
109 
110 destructor THotspot.Destroy;
111 begin
112  inherited Destroy;
113 end;
114 
115 
116 procedure register;
117 begin
118  RegisterComponents('PascalScript', [THotspot]);
119 end;
120 
121 end.
122 
123 //STARTRAIN
124 // start train
125 // start rain
126 // star train


			
Vote: How useful do you find this Article/Tip?
Bad Excellent
1 2 3 4 5 6 7 8 9 10

 

Advertisement
Share this page
Advertisement
Download from Google

Copyright © Mendozi Enterprises LLC