Autor Beitrag
del1312
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 190



BeitragVerfasst: So 01.06.03 17:52 
Hallo kann mir bitte jemand kurz mal den Aufbau erklären wie ich mit einer ComboBox arbeite? Ich möchte z. B für ein Memo die Schriftfarbe per Combobox zur Auswahl stellen. Wie genau geh ich da vor?

Danke für Eure Hilfe!!!
mfg
ecspooky
Tweafis
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 647

WinXP + fbsd
Delphi 5 Prof
BeitragVerfasst: So 01.06.03 17:55 
Du machst entweder ne Combobox mit entsprechenden Einträgen und dann OnClick ne zuweisung oder holst dir ne ColorCombobox bei torry (müsste es geben) was eigentlich deinem Problem entspricht.

_________________
.: Es wird der Tag kommen, an dem wir es nicht mehr ändern können :.
Tomac
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 113

Win XP
D6 Ent
BeitragVerfasst: So 01.06.03 19:51 
In Delphi 6 gibt es eine Colorbox, da geht das ganz einfach:

ausblenden Delphi-Quelltext
1:
memo1.color:=colorbox1.Selected;					


mfG
Tomac
Tweafis
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 647

WinXP + fbsd
Delphi 5 Prof
BeitragVerfasst: So 01.06.03 19:53 
Hab kein Delphi6, wusst ich net

_________________
.: Es wird der Tag kommen, an dem wir es nicht mehr ändern können :.
del1312 Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 190



BeitragVerfasst: So 01.06.03 23:18 
Hm hilft mir leider nicht unbedingt weiter, bin noch newbie und bräuchte doch mehr anleitung :oops:
Tomac
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 113

Win XP
D6 Ent
BeitragVerfasst: Mo 02.06.03 08:51 
Du könntest es ja so machen (vielleicht ein bisschen umständlich, aber es funktioniert):

Zuerst schreibst du in deine Combobox (Items) alle möglichen Farben rein (also Schwraz, Weiß, Rot, Gelb,... und dann schreibst du das in den SourceCode:

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:
{...}
var col: TColor;
{...}

procedure TForm1.getcolor(Sender: Tobject);
begin
with TCombobox(Sender) do begin
  case itemindex of
0: col:= clBlack;
1: col:= clWhite;
2: col:= clRed;
3: col:= clYellow;
4: col:= clBlue;
5: col:= clGreen;
6: col:= clPurple;
7: col:= clFuchsia;
8: col:= clGray;
9: col:= clSilver;
10: col:= clLime;
11: col:= clOlive;
12: col:= clTeal;
13: col:= clAqua;
14: col:= clNavy;
15: col:= clSkyBlue;
16: col:= clMaroon;
end;
end;
end;

procedure TForm1.ComboBox1Click(Sender: TObject);
begin
getcolor(Combobox1);
memo1.color:=col;
end;


Habs jetzt nicht getestet, müsste aber so hinhauen.

mfG
Tomac
del1312 Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 190



BeitragVerfasst: Fr 06.06.03 07:24 
@Tomac: Danke für deinen Code hab es ausprobiert bekomme aber immer die Fehlermeldung:
Unsicherer Code '@ opertator' Haste ne Idee was das sein könnte?

mfg
ecspooky
Luckie
Ehemaliges Mitglied
Erhaltene Danke: 1



BeitragVerfasst: Fr 06.06.03 08:31 
@Tomac: Schon mal was von Funktionen gehört? :roll:

ausblenden 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:
function GetColor(idx: Integer): TColor;
begin
    case idx of
      0 : result := clBlack;
      1 : result := clWhite;
      2 : result := clRed;
      3 : result := clYellow;
      4 : result := clBlue;
      5 : result := clGreen;
      6 : result := clPurple;
      7 : result := clFuchsia;
      8 : result := clGray;
      9 : result := clSilver;
      10 : result := clLime;
      11 : result := clOlive;
      12 : result := clTeal;
      13 : result := clAqua;
      14 : result := clNavy;
      15 : result := clSkyBlue;
      16 : result := clMaroon;
    end;
  end;
end;

procedure TForm1.ComboBox1Click(Sender : TObject);
begin  
  memo1.color := getcolor(Combobox1.ItemIndex);
end;
Tomac
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 113

Win XP
D6 Ent
BeitragVerfasst: Fr 06.06.03 15:05 
OK, hast ja recht. Habs aber auch nur so hingeschrieben und nicht selbst ausprobiert, sonst wäre ich wohl auch draufgekommen.


Edit: Mit der Prozedur gehts aber auch bei mir.
Tino
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Veteran
Beiträge: 9839
Erhaltene Danke: 45

Windows 8.1
Delphi XE4
BeitragVerfasst: Di 10.06.03 09:47 
Tomac hat folgendes geschrieben:
Edit: Mit der Prozedur gehts aber auch bei mir.

Das stimmt schon... allerdings ist es mehr als unüblich dafür eine Procedure und eine global definierte Variable zu benutzen.

Gruß
Tino