Autor Beitrag
SvenZ
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 18



BeitragVerfasst: Di 08.06.10 14:22 
Hallo,
wie es das Thema schon sagt:
wie kann ich einzelne Panels einer StatusBar einfärben?
Es gibt da wohl keine Property (StatusBar1.Panels[1].Color := ...)?

_________________
mit freundlichen Grüßen
Sven
ThunderDragon
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 26

Windows 7 Professional 32Bit
Delphi 2009 Enterprise
BeitragVerfasst: Di 08.06.10 15:17 
SvenZ Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 18



BeitragVerfasst: Mi 09.06.10 10:24 
hab mir aus dem gegoogelten Beispiel jetzt folgendes Programm gemacht:
ausblenden volle Höhe Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, ComCtrls, StdCtrls;

type
  TForm1 = class(TForm)
    StatusBar1: TStatusBar;
    btn_IncStatus: TButton;
    btn_DecStatus: TButton;
    procedure btn_IncStatusClick(Sender: TObject);
    procedure btn_DecStatusClick(Sender: TObject);

  private
    status : integer;
    procedure FormCreate(Sender: TObject);
    procedure StatusBar1DrawPanel(StatusBar: TStatusBar; Panel: TStatusPanel;
    const Rect: TRect);
  end;


var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.FormCreate(Sender: TObject);
begin
  StatusBar1.Panels[1].Style := psOwnerDraw; // Panel 2 selber zeichnen
  status := 1;
end;

procedure TForm1.StatusBar1DrawPanel(StatusBar: TStatusBar; Panel: TStatusPanel;
  const Rect: TRect);
const
  status_color : Array[1..3] of TColor = (clGreen,clYellow,clred);
begin
  if Panel = StatusBar1.Panels[1] then // zweites Panel
  begin
    with StatusBar.Canvas do
    begin
      Brush.Color := status_color[status]; // Farbe aus dem Array
      FillRect(Rect); // Mit der Farbe füllen
      TextOut(rect.Left + 2, rect.Top + 2, panel.Text); // Textausgeben
    end;
  end;
end;

procedure TForm1.btn_IncStatusClick(Sender: TObject);
begin
  if (status < 3) then
  begin
    Inc(Status);
  end;
  StatusBar1.Repaint;

end;

procedure TForm1.btn_DecStatusClick(Sender: TObject);
begin
  if (status > 1) then
  begin
    Dec(Status);
  end;
  StatusBar1.Repaint;

end;
end.


jetzt weiß ich aber nicht weiter.
Die procedure muß ja nun beim OnDrawPanel Ereignis gezündet werden. Per Doppelclick auf die OnPanelDraw Zeile im Objektinspektor wurde da auch was eingefügt. Aber wie geht das nun mit der Parameterübergabe?
Ich krieg jetzt jedenfalls ne Fehlermeldung (ungültiger Eigenschaftswert).

_________________
mit freundlichen Grüßen
Sven
ThunderDragon
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 26

Windows 7 Professional 32Bit
Delphi 2009 Enterprise
BeitragVerfasst: Mi 09.06.10 11:57 
Dein Code läuft bei mir.


Bei welcher Zeile spuckt er denn den Fehler aus?
Und welche Parameter willst du übergeben? Die Parameter der StatusBar1DrawPanel Methode werden dir aus der Komponente übergeben
SvenZ Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 18



BeitragVerfasst: Mi 09.06.10 13:20 
Fehlermeldung siehe Anhang, kommt sofoert bei Programmstart, wahrscheinlich bei FormCreate.
Kanns was mit der StatusBar ansich zu tun haben?
Ich habe nur eine nackte StatusBar im Formular, ohne Panels, Text und so.
Anbei auch mein komplettes Projekt.
Einloggen, um Attachments anzusehen!
_________________
mit freundlichen Grüßen
Sven
bummi
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 1248
Erhaltene Danke: 187

XP - Server 2008R2
D2 - Delphi XE
BeitragVerfasst: Mi 09.06.10 13:32 
procedure FormCreate(Sender: TObject);
procedure StatusBar1DrawPanel(StatusBar: TStatusBar; Panel: TStatusPanel;
const Rect: TRect);

gehören nicht in den private Bereich sondern in die Klassendefinitionen direkt
dort wo auch

procedure btn_DecStatusClick(Sender: TObject);
procedure btn_IncStatusClick(Sender: TObject);

stehen
SvenZ Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 18



BeitragVerfasst: Mi 09.06.10 13:38 
siehe da, geht.
Und nochwas ist mir gekommen:
Das zu färbende Panel muß auch schon im Entwurf da sein. Ich dachte erst, das wird komplett zur Laufzeit erzeugt.
Danke!

---Moderiert von user profile iconNarses: Beiträge zusammengefasst---

... und mit welcher Property färbe ich die Textfarbe?

_________________
mit freundlichen Grüßen
Sven
bummi
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 1248
Erhaltene Danke: 187

XP - Server 2008R2
D2 - Delphi XE
BeitragVerfasst: Mi 09.06.10 14:43 
Font.Color := clYellow;