Mega Code Archive

 
Categories / Delphi / Graphic
 

How to detect if you double clicked on an icon in a statusbar

Title: How to detect if you double clicked on an icon in a statusbar ? Question: How do I make my program show a messagebox, perform a procedure,... when I doubleclick on an Icon I've put in my statusbar. (e.g. The "E"-icon in the status bar of MS Internet Explorer.) I browsed a lot of delphi sites without finding the solution to this actually simple problem. So I just solved it on my own. Partial credits to somebody who's nick starts with a "V" or ends with it, sorry forget it, in da #delphi channel for giving me an idea 'bout doing this !!! Answer: // Code of the sample program I wrote, check it out. // Calculations for determining the values of some variables of //course depend on the way you want your icon displayed, in what // panel, blablabla // it should be simple ... C-YA I'm sure there is a shorter way // of doing this // If you find out be sure to mail me at regnum@uptomail. unit Unit1; interface uses Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,ComCtrls, StdCtrls, ImgList; type TForm1 = class(TForm) StatusBar1: TStatusBar; Edit1: TEdit; Label1: TLabel; Label2: TLabel; Edit2: TEdit; Label3: TLabel; Edit3: TEdit; ImageList1: TImageList; Label4: TLabel; Edit4: TEdit; Label5: TLabel; Edit5: TEdit; procedure FormResize(Sender: TObject); procedure StatusBar1MouseMove(Sender: TObject; Shift: TShiftState; X,Y: Integer); procedure FormCreate(Sender: TObject); procedure StatusBar1DrawPanel(StatusBar: TStatusBar; Panel: TStatusPanel; const Rect: TRect); procedure StatusBar1DblClick(Sender: TObject); procedure StatusBar1MouseDown(Sender: TObject; Button: TMouseButton;Shift: TShiftState; X, Y: Integer); private Beginpos : Integer; XMouse : Integer; XMDown : Integer; property Icon_Beginpos: Integer read Beginpos write Beginpos; property XValue : Integer read XMouse write XMouse; property XClicked : Integer read XMDown write XMDown; { Private declarations } public { Public declarations } end; var Form1: TForm1; implementation {$R *.DFM} procedure TForm1.FormResize(Sender: TObject); begin StatusBar1.Panels[1].Width := Form1.Width - 150; Icon_Beginpos := 100 + StatusBar1.Panels[1].Width; Edit2.Text := IntToStr(Icon_Beginpos); Edit3.Text := IntToStr(Icon_Beginpos + 3); Edit4.Text := IntToStr(Icon_Beginpos + 18); end; procedure TForm1.StatusBar1MouseMove(Sender: TObject; Shift: TShiftState; X, Y: Integer); begin XValue := x; Edit1.Text := IntToStr(XValue); end; procedure TForm1.FormCreate(Sender: TObject); begin Icon_Beginpos := Form1.Width - 50; Edit2.Text := IntToStr(Icon_Beginpos); end; procedure TForm1.StatusBar1DrawPanel(StatusBar: TStatusBar; Panel: TStatusPanel; const Rect: TRect); begin with StatusBar1.Canvas do begin FillRect(Rect); Font.Color := clYellow; ImageList1.Draw(StatusBar1.Canvas,Rect.Left,Rect.Top,Panel.Index); TextOut(Rect.left + 30, Rect.top + 2, ''); end; end; procedure TForm1.StatusBar1DblClick(Sender: TObject); begin If (XClicked = Beginpos + 3) And (XClicked Begin Application.MessageBox('You Just Double Clicked On The Icon In The Fourth Panel Of The StatusBar !','Information',MB_OK); End; end; procedure TForm1.StatusBar1MouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer); begin XClicked := X; Edit5.Text := IntToStr(XClicked); end; end.