Autor Beitrag
Knedcox
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 79



BeitragVerfasst: Fr 19.08.05 14:42 
Hab im Forum einen Thread gefunden, der auf diese Seite verweist: www.swissdelphicente...showcode.php?id=1100. Weiß aber leider nicht, welche von den ganzen Proceduren einen Button farbig macht.

Kann mir das jemand leicht verständlich schreiben? Merci schon mal im Voraus.
F34r0fTh3D4rk
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 5285
Erhaltene Danke: 29

Win Vista (32), Win 7 (64)
Eclipse, SciTE, Lazarus
BeitragVerfasst: Fr 19.08.05 15:06 
Zitat:

{
You cannot change the color of a standard TButton,
since the windows button control always paints itself with the
button color defined in the control panel.
But you can derive derive a new component from TButton and handle
the and drawing behaviour there.

Die Farbe eines Standard TButtons kann nicht verändert werden, sie
ist abhängig von den Systemeinstellungen.
Durch Ableiten des TButtons kann der Button aber Farbe annehmen.
}
Knedcox Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 79



BeitragVerfasst: Fr 19.08.05 15:26 
Ja, das hab ich auch gelesen. Hat mir nur nicht weitergeholfen... Es steht ja da, dass ein Button Farbe annehmen kann. Nur wie?!
hallo
ontopic starontopic starontopic starontopic starhalf ontopic starofftopic starofftopic starofftopic star
Beiträge: 450

WIN XP, SuSE 9.3
D3 Prof, D6 Pers, 2005 Pers
BeitragVerfasst: Fr 19.08.05 15:28 
Du machst dir einfach selber eine Komponente. Dazu kannst du z.B. das TPanel hernehmen. Dann kannst du z.B. ein Shape mit deiner Farbe drüberlegen oder sowas machen.
Sowas wie onclick ist schnell programmiert!

Gruß vom 20.WJT
hallo

_________________
Der beste je Programmierte Trojaner: Windows XP
Wäre es nicht adequat, den Usus heterogener Termini zu minimieren?
CenBells
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 1547

Win 7
Delphi XE5 Pro
BeitragVerfasst: Fr 19.08.05 15:28 
hi,

der code, den du gefunden hast, ist eine komponente.
Im prinzip kannst du das ganze zeug in eine unit speichern und über komponente -> installieren die datei in ein package deiner wahl installieren. Dann hast du den button als eine visuelle komponente in der Komponenten palette.

Gruß
Ken

_________________
Eine Klasse beschreibt die Struktur und das Verhalten einer Menge gleichartiger Objekte.
Dargor
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 59

Win2k SP4, WinXP Pro SP1
D6 Pers
BeitragVerfasst: Fr 19.08.05 15:48 
Ich weiß nicht mehr genau, wo ich es her hab (Torry oder SwissDelphiCenter oder ???), aber ich habe das hier mal gefunden:
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:
74:
75:
76:
77:
78:
79:
80:
81:
82:
83:
84:
85:
86:
87:
88:
89:
90:
91:
92:
93:
94:
95:
96:
97:
98:
99:
100:
101:
102:
103:
104:
105:
106:
107:
108:
109:
110:
111:
112:
113:
114:
115:
116:
117:
118:
119:
120:
121:
122:
123:
124:
125:
126:
127:
128:
129:
130:
131:
132:
133:
134:
135:
136:
137:
138:
139:
140:
141:
142:
143:
144:
145:
146:
147:
148:
149:
150:
151:
152:
153:
154:
155:
156:
157:
158:
159:
160:
161:
162:
163:
164:
165:
166:
167:
168:
169:
170:
171:
172:
173:
174:
175:
176:
177:
178:
179:
180:
181:
182:
183:
184:
185:
186:
187:
unit ColorButton;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  StdCtrls, Buttons, ExtCtrls;

type
  TDrawButtonEvent = procedure(Control: TWinControl;
    Rect: TRect; State: TOwnerDrawState) of object;

  TColorButton = class(TButton)
  private
    FCanvas: TCanvas;
    IsFocused: Boolean;
    FOnDrawButton: TDrawButtonEvent;
  protected
    procedure CreateParams(var Params: TCreateParams); override;
    procedure SetButtonStyle(ADefault: Boolean); override;
    procedure CMEnabledChanged(var Message: TMessage); message CM_ENABLEDCHANGED;
    procedure CMFontChanged(var Message: TMessage); message CM_FONTCHANGED;
    procedure CNMeasureItem(var Message: TWMMeasureItem); message CN_MEASUREITEM;
    procedure CNDrawItem(var Message: TWMDrawItem); message CN_DRAWITEM;
    procedure WMLButtonDblClk(var Message: TWMLButtonDblClk); message WM_LBUTTONDBLCLK;
    procedure DrawButton(Rect: TRect; State: UINT);
  public
    constructor Create(AOwner: TComponent); override;
    destructor Destroy; override;
    property Canvas: TCanvas read FCanvas;
  published
    property OnDrawButton: TDrawButtonEvent read FOnDrawButton write FOnDrawButton;
    property Color;
  end;

procedure Register;

implementation

procedure Register;
begin
  RegisterComponents('Samples', [TColorButton]);
end;

constructor TColorButton.Create(AOwner: TComponent);
begin
  inherited Create(AOwner);
  FCanvas := TCanvas.Create;
end;

destructor TColorButton.Destroy;
begin
  inherited Destroy;
  FCanvas.Free;
end;

procedure TColorButton.CreateParams(var Params: TCreateParams);
begin
  inherited CreateParams(Params);
  with Params do Style := Style or BS_OWNERDRAW;
end;

procedure TColorButton.SetButtonStyle(ADefault: Boolean);
begin
  if ADefault <> IsFocused then
  begin
    IsFocused := ADefault;
    Refresh;
  end;
end;

procedure TColorButton.CNMeasureItem(var Message: TWMMeasureItem);
begin
  with Message.MeasureItemStruct^ do
  begin
    itemWidth  := Width;
    itemHeight := Height;
  end;
end;

procedure TColorButton.CNDrawItem(var Message: TWMDrawItem);
var
  SaveIndex: Integer;
begin
  with Message.DrawItemStruct^ do
  begin
    SaveIndex := SaveDC(hDC);
    FCanvas.Lock;
    try
      FCanvas.Handle := hDC;
      FCanvas.Font := Font;
      FCanvas.Brush := Brush;
      DrawButton(rcItem, itemState);
    finally
      FCanvas.Handle := 0;
      FCanvas.Unlock;
      RestoreDC(hDC, SaveIndex);
    end;
  end;
  Message.Result := 1;
end;

procedure TColorButton.CMEnabledChanged(var Message: TMessage);
begin
  inherited;
  Invalidate;
end;

procedure TColorButton.CMFontChanged(var Message: TMessage);
begin
  inherited;
  Invalidate;
end;

procedure TColorButton.WMLButtonDblClk(var Message: TWMLButtonDblClk);
begin
  Perform(WM_LBUTTONDOWN, Message.Keys, Longint(Message.Pos));
end;

procedure TColorButton.DrawButton(Rect: TRect; State: UINT);
var
  Flags, OldMode: Longint;
  IsDown, IsDefault, IsDisabled: Boolean;
  OldColor: TColor;
  OrgRect: TRect;
begin
  OrgRect := Rect;
  Flags := DFCS_BUTTONPUSH or DFCS_ADJUSTRECT;
  IsDown := State and ODS_SELECTED <> 0;
  IsDefault := State and ODS_FOCUS <> 0;
  IsDisabled := State and ODS_DISABLED <> 0;

  if IsDown then Flags := Flags or DFCS_PUSHED;
  if IsDisabled then Flags := Flags or DFCS_INACTIVE;

  if IsFocused or IsDefault then
  begin
    FCanvas.Pen.Color := clWindowFrame;
    FCanvas.Pen.Width := 1;
    FCanvas.Brush.Style := bsClear;
    FCanvas.Rectangle(Rect.Left, Rect.Top, Rect.Right, Rect.Bottom);
    InflateRect(Rect, - 1, - 1);
  end;

  if IsDown then
  begin
    FCanvas.Pen.Color := clBtnShadow;
    FCanvas.Pen.Width := 1;
    FCanvas.Brush.Color := clBtnFace;
    FCanvas.Rectangle(Rect.Left, Rect.Top, Rect.Right, Rect.Bottom);
    InflateRect(Rect, - 1, - 1);
  end
  else
    DrawFrameControl(FCanvas.Handle, Rect, DFC_BUTTON, Flags);

  if IsDown then OffsetRect(Rect, 1, 1);

  OldColor := FCanvas.Brush.Color;
  FCanvas.Brush.Color := Color;
  FCanvas.FillRect(Rect);
  FCanvas.Brush.Color := OldColor;
  OldMode := SetBkMode(FCanvas.Handle, TRANSPARENT);
  FCanvas.Font.Color := clBtnText;
  if IsDisabled then
    DrawState(FCanvas.Handle, FCanvas.Brush.Handle, nil, Integer(Caption), 0,
    ((Rect.Right - Rect.Left) - FCanvas.TextWidth(Caption)) div 2,
    ((Rect.Bottom - Rect.Top) - FCanvas.TextHeight(Caption)) div 2,
      0, 0, DST_TEXT or DSS_DISABLED)
  else
    DrawText(FCanvas.Handle, PChar(Caption), - 1, Rect,
      DT_SINGLELINE or DT_CENTER or DT_VCENTER);
  SetBkMode(FCanvas.Handle, OldMode);

  if Assigned(FOnDrawButton) then
    FOnDrawButton(Self, Rect, TOwnerDrawState(LongRec(State).Lo));

  if IsFocused and IsDefault then
  begin
    Rect := OrgRect;
    InflateRect(Rect, - 4, - 4);
    FCanvas.Pen.Color := clWindowFrame;
    FCanvas.Brush.Color := clBtnFace;
    DrawFocusRect(FCanvas.Handle, Rect);
  end;
end;

end.
F34r0fTh3D4rk
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 5285
Erhaltene Danke: 29

Win Vista (32), Win 7 (64)
Eclipse, SciTE, Lazarus
BeitragVerfasst: Fr 19.08.05 16:03 
das ist genau das :lol:
Knedcox Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 79



BeitragVerfasst: Sa 20.08.05 14:37 
Jetzt hab ich die neue Komponente installiert, find sie aber nirgendwo um sie anzuwenden. Ich hab wirklich überall in den zur Verfügung stehenden Komponenten nachgesehen, aber sie ist einfach nicht dabei. Was soll ich tun?
AXMD
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 4006
Erhaltene Danke: 7

Windows 10 64 bit
C# (Visual Studio 2019 Express)
BeitragVerfasst: Sa 20.08.05 14:40 
Das liegt vielleicht daran, dass in der Unit keine Register- bzw. RegisterComponentsprozedur drin ist :lol:

AXMD
Knedcox Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 79



BeitragVerfasst: Sa 20.08.05 14:43 
Das heißt ein für einen blutigen Anfänger das er was genau machen soll?
AXMD
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 4006
Erhaltene Danke: 7

Windows 10 64 bit
C# (Visual Studio 2019 Express)
BeitragVerfasst: Sa 20.08.05 14:47 
ausblenden Delphi-Quelltext
1:
2:
3:
4:
procedure Register;
begin
  RegisterComponents('Zeugs', [TColorButton]);
end;


Das unten (in die Unit) einfügen und einen Prototypen davon in den Interface-Teil. Dann nochmal installieren.

AXMD

PS. Sollte so funktionieren; aber keine Garantie, da kein Delphi bei der Hand
Dargor
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 59

Win2k SP4, WinXP Pro SP1
D6 Pers
BeitragVerfasst: Sa 20.08.05 14:53 
Das alles steht doch in den Zeilen 36-43... :gruebel:
AXMD
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 4006
Erhaltene Danke: 7

Windows 10 64 bit
C# (Visual Studio 2019 Express)
BeitragVerfasst: Sa 20.08.05 14:56 
user profile iconDargor hat folgendes geschrieben:
Das alles steht doch in den Zeilen 36-43... :gruebel:


:shock: Jetzt seh ich's erst. Hmmm... dann sollte das Ding aber auf der Seite Samples installiert sein :gruebel:

AXMD
Knedcox Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 79



BeitragVerfasst: Sa 20.08.05 15:05 
Da stehts aber nicht dabei.
Ich erklär noch mal, was ich genau mach...

Ich füg den Text aus dieser einen Internetseite in eine neue Unit. Anschließend geh ich auf Komponente installieren. Dann öffnet sich ein Fenster in dem folgendes steht:

Komponente installieren
Name der Unit: TColorButton (den Namen hab ich eingegeben)
Suchpfad: (Bereits ausgefüllt)
Name des Packages: ...delphi6\Lib\dclusr.dpk
Beschreibung: Borland User Components

Wenn ich das bestätigt habe, kommt ein neues Fenster mit

Die angeforderte Datei existiert nicht. Sie können stattdessen einen der folgenden Dateitypen erstellen:
Neues Formular
Neue Unit
Neue Textdatei


An der Stelle weiß ich schon mal nicht wirklich weiter... Was will der denn von mir?
AXMD
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 4006
Erhaltene Danke: 7

Windows 10 64 bit
C# (Visual Studio 2019 Express)
BeitragVerfasst: Sa 20.08.05 15:07 
Du solltest die Unit in die du den Text kopierst vielleicht vorher speichern -_-

AXMD
Knedcox Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 79



BeitragVerfasst: Sa 20.08.05 15:12 
Läuft dann genau nach dem gleichen Schema ab bis zu dem Punkt "Die angeforderte Datei existiert nicht... bla bla".
AXMD
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 4006
Erhaltene Danke: 7

Windows 10 64 bit
C# (Visual Studio 2019 Express)
BeitragVerfasst: Sa 20.08.05 15:15 
Schonmal in ein anderes Package zu installieren versucht?

AXMD
Knedcox Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 79



BeitragVerfasst: Sa 20.08.05 15:17 
Jetzt hab ich mal der Datei den Namen "Farbbutton" gegeben (wie vorhin), und jetzt öffnet sich ein Fenster mit folgendem Inhalt:

Package - dclusr.dpk

Compilieren - Hinzufügen - Entfernen - Installieren (kann nicht gewählt werden) - Optionen

Darunter steht wie in einem Explorer-Fenster:
Contains Pfad
--> Farbbutton c:\programme\borland\delphi6\Lib
JayEff
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 2971

Windows Vista Ultimate
D7 Enterprise
BeitragVerfasst: Sa 20.08.05 15:21 
Nun du hast wahrscheinlich nicht "In neues Package" angeklickt, aber wenn ich das tue, kommt bei mir:
Fehlermeldung:
[Fataler Fehler] ColorButton.pas(1): Das Programm oder die Unit 'ColorButton.pas' ruft sich selbst wieder auf

_________________
>+++[>+++[>++++++++<-]<-]<++++[>++++[>>>+++++++<<<-]<-]<<++
[>++[>++[>>++++<<-]<-]<-]>>>>>++++++++++++++++++.+++++++.>++.-.<<.>>--.<+++++..<+.


Zuletzt bearbeitet von JayEff am Sa 20.08.05 15:21, insgesamt 1-mal bearbeitet
AXMD
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 4006
Erhaltene Danke: 7

Windows 10 64 bit
C# (Visual Studio 2019 Express)
BeitragVerfasst: Sa 20.08.05 15:21 
Versuch einfach mal installieren :mrgreen:

AXMD