Autor Beitrag
Benjie
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 55

Win 98 SE / Win XP / xubuntu Linux / Mac OS 9.2
D6 Enterprise
BeitragVerfasst: So 09.03.08 19:26 
Hallo Leute,

Ich möchte den Text in einem Label so umrunden, dass es aussieht wie auf dem Bild im Anhang (Ausschnitt aus dem Finder von OS X Leopard). Man beachte das mittlere Icon: es ist nicht einfach ein roundrect, sondern mehr, aber ich hab k.A. wie man das hinkriegt. Ich hab schon selber (fast) alles probiert und auch das Forum wie ein wilder durchforstet, aber nix gefunden. Wäre echt froh, wenn einer Rat wüsste...

Grietz, Benjie
Einloggen, um Attachments anzusehen!
Yogu
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 2598
Erhaltene Danke: 156

Ubuntu 13.04, Win 7
C# (VS 2013)
BeitragVerfasst: So 09.03.08 19:51 
Hallo user profile iconBenjie,

ich habe zwar auf die Schnelle keine optimale Lösung, aber mit eckigen Innenecken kannst du es so machen:

Zeichne ein RoundRect unter die erste Zeile, und mache es Eckengröße / 2 Pixel weiter nach unten. Die zweite Zeile muss dann Eckengröße / 2 Pixel nach oben ragen. Das klappt sowohl für gleich lange Zeilen wie auch für unterschiedliche Höhen.

Grüße,
Yogu
Benjie Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 55

Win 98 SE / Win XP / xubuntu Linux / Mac OS 9.2
D6 Enterprise
BeitragVerfasst: So 09.03.08 19:58 
Danke yogu. das klappt ganz gut. Kannst du mir vielleicht sage, wie ich die beiden füllen soll? Und soll ich sie auf das canvas des labels zeichnen?
Yogu
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 2598
Erhaltene Danke: 156

Ubuntu 13.04, Win 7
C# (VS 2013)
BeitragVerfasst: So 09.03.08 20:17 
user profile iconBenjie hat folgendes geschrieben:
das klappt ganz gut.

Gut.

user profile iconBenjie hat folgendes geschrieben:
Kannst du mir vielleicht sage, wie ich die beiden füllen soll?

Hä? Ich dachte, du hättest es schon? Natürlich mit Canvas.RoundRect. Und mit deiner Lieblingsfarbe. ;)

user profile iconBenjie hat folgendes geschrieben:
Und soll ich sie auf das canvas des labels zeichnen?

Dafür würde ich eine PaintBox verwenden. Du findest sie in der Registerkarte "System". Im Ereignis OnPaint kannst du dann den Rahmen zeichnen und den Text darauf schreiben. Die Größe musst du selber ändern, und den Text selber umbrechen. Aber das dürfte nicht allzu schwierig sein.
Benjie Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 55

Win 98 SE / Win XP / xubuntu Linux / Mac OS 9.2
D6 Enterprise
BeitragVerfasst: So 09.03.08 22:01 
Vielen Dank! Ja sorry, natürlich hatte ich sie schon gezeichnet, aber nicht gefüllt. Ich hatte ganz vergessen, dass ich das mit

ausblenden Delphi-Quelltext
1:
2:
  paintbox1.Canvas.Pen.Color:=claqua;
  paintbox1.Canvas.brush.Color:=claqua;


machen kann. Danke noch mal für die schnelle Hilfe.

Gruss, Benjie
Benjie Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 55

Win 98 SE / Win XP / xubuntu Linux / Mac OS 9.2
D6 Enterprise
BeitragVerfasst: Mo 07.04.08 20:05 
Titel: Problem gelöst
Also. Ich habe jetzt einen Code, der so ziemlich das macht, was ich wollte. Ich habe ihn selber geschrieben und das Resultat ist auch nicht allzu schön aber mir reichts.
Im Falle, dass jemand interessiert ist, oder den Code sogar mal gebrauchen kann, poste ich ihn mal hier:

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:
procedure TForm1.PaintBox1Paint(Sender: TObject);
var aRect : TRect;
    captionstring:string;
    i,k,maxwidth,Text_Rect_Distance,Main_Second_Rect_Distance:integer;
    lines:TStringlist;
    iconimage:ticon;
begin
  //Lines helps to divide the text
  lines:=Tstringlist.Create();
  lines.Add('');
  //Set the caption string
  captionstring:='String';
  //Set the color, font and the constants
  with paintbox1 do BEGIN
    Canvas.Pen.Color:=$00D77538;
    Canvas.brush.Color:=$00D77538;
    Font.Name:='Segoe UI';
    font.Color:=clwhite;
    font.Style:=[fsbold];
  end;
  //Maximal width of one text-line (in pixel)
  maxwidth:=105;
  k:=0;
  //Horizontal distance between the text and its rectangular
  Text_Rect_Distance:=10;
  //Vertical distance between the main and the second rectangle
  Main_Second_Rect_Distance:=10;


  //If the text is longer than the maximum width, divide:
  if paintbox1.Canvas.TextWidth(captionstring)>maxwidth then Begin
    for i := 1 to length(captionstring) do Begin
      if paintbox1.Canvas.TextWidth(copy(captionstring,1,i))>maxwidth then BEGIN
        inc(k);
        captionstring:=copy(captionstring,i,length(captionstring));
        lines.Add(copy(captionstring,1,i));
       end else lines[k]:=copy(captionstring,1,i)
    end;

  //if not just write it into the space:
  end else lines[0]:=captionstring;


  //Draw the rounded rectangulars
  for i := 0 to lines.Count-1 do begin
    //Draw the shadow of the main rectangular:
    paintbox1.Canvas.Pen.Color:=clsilver;
    roundrect(paintbox1.Canvas.Handle,(128-paintbox1.Canvas.TextWidth(lines[i])) div 2-Text_Rect_Distance,128+i*15+1,(128+paintbox1.Canvas.TextWidth(lines[i])) div 2+Text_Rect_Distance,148+i*15+1,20,20);
    paintbox1.Canvas.Pen.Color:=$00D77538;

    //Draw the Main-Rectangular:
    roundrect(paintbox1.Canvas.Handle,(128-paintbox1.Canvas.TextWidth(lines[i])) div 2-Text_Rect_Distance,128+i*15,(128+paintbox1.Canvas.TextWidth(lines[i])) div 2+Text_Rect_Distance,148+i*15,20,20);
    if i<>0 then if paintbox1.Canvas.TextWidth(lines[i])-2<=paintbox1.Canvas.TextWidth(lines[i-1]) then roundrect(paintbox1.Canvas.Handle,(128-paintbox1.Canvas.TextWidth(lines[i])) div 2-Text_Rect_Distance,128+(i-1)*15,(128+paintbox1.Canvas.TextWidth(lines[i])) div 2+Text_Rect_Distance,148+i*15,20,20);
  end;

  //Set the rectangular for the text and draw the text
  for i := 0 to lines.Count-1 do begin
    aRect := rect((128-paintbox1.Canvas.TextWidth(lines[i])) div 2,128+i*15+2,(128+paintbox1.Canvas.TextWidth(lines[i])) div 2,148+i*15+2);
    DrawText(paintbox1.Canvas.Handle,pchar(lines[i]),Length(lines[i]),aRect,DT_center);
  end;

  //Draw the icon
  iconimage:=ticon.Create;
  iconimage.LoadFromFile('C:\SampleIcon.ico');
  paintbox1.Canvas.Draw(0,0,iconimage);

  //Set paintbox-size:
  paintbox1.Width:=128;
  paintbox1.Height:=138+20*lines.Count;


  iconimage.Free;
  lines.Free;
end;


Damit wäre das Problem gelöst. :D
Grietz, Benjie
Einloggen, um Attachments anzusehen!