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 draw lines and a bitmap on a TStatusPanel 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
26-Aug-02
Category
VCL-General
Language
Delphi 2.x
Views
154
User Rating
No Votes
# Votes
0
Replies
0
Publisher:
DSP, Administrator
Reference URL:
DKB
			Author: Tomas Rutkauskas

How to draw lines and a bitmap on a TStatusPanel

Answer:

Example of drawing lines and BMP on StatusBar.Panels[1]. Assumes StatusBar is 
placed on form. Right click on StatusBar to invoke panels editor. Add three panels 
to StatusBar. Set Style for StatusBar.Panels[1] to psOwnerDraw. Add OnDrawPanel 
event shown below to StatusBar to draw bitmap on Panels[1].

1   unit ScreenStatusBarBMP;
2   
3   interface
4   
5   uses
6     Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs, 
7   ComCtrls, ExtCtrls;
8   
9   type
10    TForm1 = class(TForm)
11      StatusBar: TStatusBar;
12      procedure FormCreate(Sender: TObject);
13      procedure StatusBarDrawPanel(StatusBar: TStatusBar; Panel: TStatusPanel; const 
14  Rect: TRect);
15    private
16      { Private declarations }
17    public
18      { Public declarations }
19    end;
20  
21  var
22    Form1: TForm1;
23  
24  implementation
25  
26  {$R *.DFM}
27  
28  procedure TForm1.FormCreate(Sender: TObject);
29  begin
30    StatusBar.Panels[0].Text := 'Zero';
31    StatusBar.Panels[1].Text := 'One'; {ignored since psOwnerDraw style}
32    StatusBar.Panels[2].Text := 'Two'
33  end;
34  
35  procedure TForm1.StatusBarDrawPanel(StatusBar: TStatusBar; Panel: TStatusPanel;
36    const Rect: TRect);
37  var
38    Bitmap: TBitmap;
39  begin
40    if Panel.Index = 1 then {not necessary if only one panel is owner drawn}
41    begin
42      {Draw red "X" in StatusPanel}
43      StatusBar.Canvas.Pen.Color := clRed;
44      StatusBar.Canvas.MoveTo(0, 0);
45      StatusBar.Canvas.LineTo(Rect.Right - 1, Rect.Bottom - 1);
46      StatusBar.Canvas.MoveTo(Rect.Left, Rect.Bottom - 1);
47      StatusBar.Canvas.LineTo(Rect.Right - 1, Rect.Top);
48      {Read Bitmap from file and display in middle of panel; In real app could get 
49  bitmap
50      from resource file.}
51      Bitmap := TBitmap.Create;
52      try
53        Bitmap.LoadFromFile('C:\Program Files\Common Files\Images\Buttons\Alarm.BMP');
54        {Draw bitmap centered in panel}
55        StatusBar.Canvas.Draw((Rect.Left + Rect.Right - Bitmap.Width) div 2,
56          (Rect.Top + Rect.Bottom - Bitmap.Height) div 2, Bitmap);
57      finally
58        Bitmap.Free
59      end;
60    end;
61  end;
62  
63  end.


			
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