Autor Beitrag
Ironhead
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 57

Win XP,Kanotix 5

BeitragVerfasst: Mo 29.05.06 12:10 
Hallo an alle,

Ich möchte in meinem Programm gerne eine Möglichkeit einbauen, die dem User elaubt die Farben des Programms individuell zu ändern und zu speichern.

Wenn jemand eine Idee hat wie ich dies Bewerkstelligen könnte, würde ich mich sehr freuen.
elundril
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 3747
Erhaltene Danke: 123

Windows Vista, Ubuntu
Delphi 7 PE "Codename: Aurora", Eclipse Ganymede
BeitragVerfasst: Mo 29.05.06 12:15 
mit einer combobox;
dort schreibst du farben hinein, jenachdem welche farbe der Benutzer auswählt änderst du die Farbe vom Objekt:
z.b:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
procedure BtnAplly.Click (sender:Tobject);
begin
  {z.b: vom Form}Form1.color:={z.b.:der Benutzer hat rot gewählt}clred;
end;

_________________
This Signature-Space is intentionally left blank.
Bei Beschwerden, bitte den Beschwerdebutton (gekennzeichnet mit PN) verwenden.
Blackheart666
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 2195

XP
D3Prof, D6Pers.
BeitragVerfasst: Mo 29.05.06 12:15 
ColorDialog & Ini Datei.
JayEff
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 2971

Windows Vista Ultimate
D7 Enterprise
BeitragVerfasst: Mo 29.05.06 12:21 
Nun. Die Farben von Buttons kannst du nicht so einfach ändern. Wohl aber die von so gut wie jeder anderen Komponente, (Component.Color gibts fast immer ..)
Ich würde zum Speichern und Laden eine Inidatei verwenden, zum Ändern der Farben kannst du einen TColorDialog nehmen, und um eine TColor als String zu speichern und auch wieder zu laden würde ich folgendes machen:
Wandle deine Farbe in eine HTML Farbe um (#FFFFFF z.B.) und speichere sie in der TIniFile als String. Zum laden umgekehrt. Ich hab beide Funktionen schon mal geproggt...:
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:
Function getR(color: TColor): byte;
Asm
and eax, $000000FF
End;

Function getG(color: TColor): byte;
Asm
shr eax, 8
and eax, $000000FF
End;

Function getB(color: TColor): byte;
Asm
shr eax, 16
and eax, $000000FF
End;

Function ResolveHTMLColor(color: String): TColor;
Var
    r, g, b: byte;
Begin
    color := StringReplace(color, '#', '', []);
    r := StrToInt('$' + copy(color, 1, 2));
    g := StrToInt('$' + copy(color, 3, 2));
    b := StrToInt('$' + copy(color, 5, 2));
    Result := RGB(r, g, b);
End;

Function getHTMLColor(color: TColor): String;
Var
    r, g, b: byte;
    rs, gs, bs: String;
Begin
    r := getR(color);
    g := getG(color);
    b := getB(color);
    rs := IntToStr(r);
    gs := IntToStr(g);
    bs := IntToStr(b);
    Result := '#' + rs + gs + bs;
End;


Viel Spaß & Erfolg... ^^

//edit: Warum machen immer alle so winzig kleine mini Beiträge?? Schreibt mal ordentlich was für euer Geld! :D

_________________
>+++[>+++[>++++++++<-]<-]<++++[>++++[>>>+++++++<<<-]<-]<<++
[>++[>++[>>++++<<-]<-]<-]>>>>>++++++++++++++++++.+++++++.>++.-.<<.>>--.<+++++..<+.
Ironhead Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 57

Win XP,Kanotix 5

BeitragVerfasst: Mo 29.05.06 12:22 
Eh, Danke das hat mir sehr weitergeholfen.

Danke dir , das funzt Prima
Ivo@CoMRoK
ontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic starofftopic star
Beiträge: 258

Win XP
D3 Prof., D7 Pe.
BeitragVerfasst: Mo 29.05.06 12:54 
Also ich weiß ja nich ob ich einfach zu blöd bin aber bei mir funzt des net. :shock:
Hier mal der Source:
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:
Function TForm1.getR(color: TColor): byte;
Asm
and eax, $000000FF
End;

Function TForm1.getG(color: TColor): byte;
Asm
shr eax, 8
and eax, $000000FF
End;

Function TForm1.getB(color: TColor): byte;
Asm
shr eax, 16
and eax, $000000FF
End;

Function TForm1.ResolveHTMLColor(color: String): TColor;
Var
    r, g, b: byte;
Begin
    color := StringReplace(color, '#', '', []);
    r := StrToInt('$' + copy(color, 1, 2));
    g := StrToInt('$' + copy(color, 3, 2));
    b := StrToInt('$' + copy(color, 5, 2));
    Result := RGB(r, g, b);
End;

Function TForm1.getHTMLColor(color: TColor): String;
Var
    r, g, b: byte;
    rs, gs, bs: String;
Begin
    r := getR(color);
    g := getG(color);
    b := getB(color);
    rs := IntToStr(r);
    gs := IntToStr(g);
    bs := IntToStr(b);
    Result := '#' + rs + gs + bs;
End;

procedure TForm1.FormCreate(Sender: TObject);
begin
  Edit1.Text := GetHTMLColor(ColorBox1.Selected);
end;

procedure TForm1.ColorBox1Change(Sender: TObject);
begin
  Edit1.Text := GetHTMLColor(ColorBox1.Selected);
end;


Ich hab des OnCreate mal rein um zu schaun ob sich bei ner andern Farbe was ändert aber macht immer das selbe nämlich: #6430142. :(

_________________
Fällt der Bauer tot vom Traktor, stand am Waldrand ein Reaktor.
Ein altes indianisches Sprichwort besagt:Es kann gefährlich sein gelben Schnee zu essen.
LH_Freak
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 385

Win XP
D7 PE, D2k5 Trial
BeitragVerfasst: Mo 29.05.06 13:01 
Ich bin mir net sicher, aber mach mal das Edit1.Text := GetHTMLColor(ColorBox1.Selected); bei OnCreate weg. Ich glaub da ist das Edit noch nicht erstellt und deswegen gibt es den fehler...
Born-to-Frag
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 1094

Win XP SP2, Win 2000 SP4
Delphi 7, 2k5
BeitragVerfasst: Mo 29.05.06 13:02 
Und warum muss man das denn in HEX umwandeln :shock:

Warum nicht einfach IntToStr(DeineFarbe); ? Funzt genauso gut..

_________________
Theorie ist wenn man alles weiß, aber nichts funktioniert. Praxis ist wenn alles funktioniert, aber niemand weiß warum.
Microsoft vereint Theorie und Praxis: Nichts funktioniert und niemand weiß warum.
Born-to-Frag
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 1094

Win XP SP2, Win 2000 SP4
Delphi 7, 2k5
BeitragVerfasst: Mo 29.05.06 13:03 
user profile iconLH_Freak hat folgendes geschrieben:
Ich bin mir net sicher, aber mach mal das Edit1.Text := GetHTMLColor(ColorBox1.Selected); bei OnCreate weg. Ich glaub da ist das Edit noch nicht erstellt und deswegen gibt es den fehler...


Dann würde er aber ne AV bekommen

_________________
Theorie ist wenn man alles weiß, aber nichts funktioniert. Praxis ist wenn alles funktioniert, aber niemand weiß warum.
Microsoft vereint Theorie und Praxis: Nichts funktioniert und niemand weiß warum.
Ironhead Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 57

Win XP,Kanotix 5

BeitragVerfasst: Mo 29.05.06 14:06 
Hab da noch mal ne Frage,

Wie kann ich die Einstellung der Farbe die ich im ColorDialog mache übernehmen, das sich nach den Cklick auf Ok die Farbe des gewünschten Objekts auch ändert
Born-to-Frag
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 1094

Win XP SP2, Win 2000 SP4
Delphi 7, 2k5
BeitragVerfasst: Mo 29.05.06 14:09 
ausblenden Delphi-Quelltext
1:
Form1.Color := ColorDings.Selected;					


Dürfte gehn ;)

_________________
Theorie ist wenn man alles weiß, aber nichts funktioniert. Praxis ist wenn alles funktioniert, aber niemand weiß warum.
Microsoft vereint Theorie und Praxis: Nichts funktioniert und niemand weiß warum.