| Autor |
Beitrag |
XFiled
Ehemaliges Mitglied
Erhaltene Danke: 1
|
Verfasst: Sa 02.08.03 15:27
Hallo zusammen,
ich bastel mir gerade eine Label-Komponente, die statt einer Farbe ein Bitmap "übergezogen" bekommt. Mein Problem ist nun, daß ich zwar weiß wie ich es für TextOut bewerkställigen kann, aber sobald ich auf DrawText umsteige (DrawText besitzt u.a. Alignment, Layout, andere Flags...) greift diese Lösung nicht mehr.
Weiß jemand wie ich ein Bitmap auf ein Label zeichnen kann, OHNE daß ich TextOut verwenden muß oder Formatierungseigenschaften verliere?
Vielen Dank für Eure Hilfe...
Grüße
XFiled
P.S.: Bisher hatte ich folgende Lösung von Mik Tran.
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 Destination: TBitmap; Source: TBitmap; R: TRect; begin Destination := TBitmap.Create; with Destination, Destination.Canvas do begin Font.Assign(Label1.Font); Monochrome := True; Width := Label1.Width; Height := Label1.Height; Textout(0, 0, Label1.Caption); end;
Source := TBitmap.Create; with Source, Source.Canvas do begin Width := Label1.Width; Height := Label1.Height; R := Rect(0, 0, Width, Height); CopyRect(R, Label1.Canvas, Bounds(0, 0, Width, Height)); CopyMode := cmSrcInvert; StretchDraw(R, Image1.Picture.Bitmap); CopyMode := cmSrcAnd; Draw(0, 0, Destination); CopyMode := cmSrcInvert; StretchDraw(R, Image1.Picture.Bitmap); end; Label1.Canvas.Draw(0, 0, Source); Source.Free; Destination.Free; |
|
|
Motzi
      
Beiträge: 2931
XP Prof, Vista Business
D6, D2k5-D2k7 je Prof
|
Verfasst: Sa 02.08.03 16:56
DrawText benötig ein Handle auf einen DeviceContext (HDC) -> bei einem Canvas-Objekt ist das einfach Canvas.Handle... reicht das als Anstoß? 
_________________ gringo pussy cats - eef i see you i will pull your tail out by eets roots!
|
|
XFiled
Ehemaliges Mitglied
Erhaltene Danke: 1
|
Verfasst: Mo 04.08.03 20:24
Hallo Motzi,
nein, tut mir leid... leider hat es noch nicht 'klick' gemacht. Könntest Du mir das vielleicht näher erklären? Wie hilft mir denn das Handle bei meinem Problem?
Grüße
XFiled
|
|
Motzi
      
Beiträge: 2931
XP Prof, Vista Business
D6, D2k5-D2k7 je Prof
|
Verfasst: Mo 04.08.03 23:42
TextOut ist eine Methode des Canvas-Objekt. DrawText ist eine API-Funktion...
Delphi-Quelltext 1:
| DrawText(Canvas.Handle, PChar(<string>), Length(<string>), <rect>, <flags>); |
Vielleicht hilft dir das ein bisschen weiter...
_________________ gringo pussy cats - eef i see you i will pull your tail out by eets roots!
|
|
XFiled
Ehemaliges Mitglied
Erhaltene Danke: 1
|
Verfasst: Di 05.08.03 15:19
Ne, also ich hab Tomaten auf den Augen. Ich versteh nicht wie ich was worauf anwenden soll und weshalb überhaupt? Ich glaube ich finde nie eine Lösung!
Grüße
XFiled
|
|
Aya
      
Beiträge: 1964
Erhaltene Danke: 15
MacOSX 10.6.7
Xcode / C++
|
Verfasst: Di 05.08.03 15:33
Hi,
Eventuell erklärst du nochmal ganz genau was du mit DrawText nicht hinbekommst, was nicht klappt.
Au'revoir,
Aya~
_________________ Aya
I aim for my endless dreams and I know they will come true!
|
|
XFiled
Ehemaliges Mitglied
Erhaltene Danke: 1
|
Verfasst: Di 12.08.03 12:39
Hallo zusammen,
was ich gemacht habe ist leicht aus obigem Quelltext zu entnehmen.
ABER: diese Lösung unterstützt weder Alignment, noch Layout, noch WordWrap, noch sonst eine Formatierung.
Nun habe ich mir folgendes gedacht: DrawText aus der DoDrawText-Methode zeichnet Text auf den Canvas unter Berücksichtigung aller Formatierungen.
Frage: Wie kann ich BEVOR es endgültig auf den Bildschrim geschrieben wird abfangen, mein Bitmap draufpappen, und zurückgeben..?
Grüße
XFiled
|
|
Tana´Ri
      
Beiträge: 230
|
Verfasst: Di 12.08.03 13:00
Titel: Override
überschreib in Paint procedure
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:
| procedure TCustomLabel.Paint; const Alignments: array[TAlignment] of Word = (DT_LEFT, DT_RIGHT, DT_CENTER); WordWraps: array[Boolean] of Word = (0, DT_WORDBREAK); var Rect, CalcRect: TRect; DrawStyle: Longint; begin with Canvas do begin if not Transparent then begin Brush.Color := Self.Color; Brush.Style := bsSolid; FillRect(ClientRect); end; Brush.Style := bsClear; Rect := ClientRect;
Brush.BitMap.loadformFile( ... ); DrawStyle := DT_EXPANDTABS or WordWraps[FWordWrap] or Alignments[FAlignment]; if FLayout <> tlTop then begin CalcRect := Rect; DoDrawText(CalcRect, DrawStyle or DT_CALCRECT); if FLayout = tlBottom then OffsetRect(Rect, 0, Height - CalcRect.Bottom) else OffsetRect(Rect, 0, (Height - CalcRect.Bottom) div 2); end; DoDrawText(Rect, DrawStyle); end; end; |
habs zwar nicht getestet muesste aber vom elementaren verständnis her stimmen
Moderiert von Tino: Delphi-Tags hinzugefügt.
_________________ mfg
Tana´Ri
|
|
XFiled
Ehemaliges Mitglied
Erhaltene Danke: 1
|
Verfasst: Di 09.09.03 19:32
Hallo,
ich glaube, ich habe mich missverständlich ausgedrückt: ich möchte NICHT den Hintergrund mit einem Bitmap versehen, sondern das Label SELBST soll antelle der Farbe Font.Color eben ein Bitmap anzeigen.
Bis auf meine oben vorgestellete Lösung scheint es keine bessere zu geben... Leider ist diese nicht optimal! Noch nicht einmal ansatzweise..
Dennoch Danke!
XFiled
P.S.: Sollte jemanden noch einfallen wie dieses Problem zu bewältigen ist, ich freue mich über jede Hilfe.
|
|
XFiled
Ehemaliges Mitglied
Erhaltene Danke: 1
|
Verfasst: Fr 12.09.03 17:15
Hallo zusammen,
Problem gelöst! Nochmals Danke an alle Helferlein...
Grüße
XFiled
|
|