Ir al contenido


Foto

Caption parcialmente en negritas


  • Por favor identifícate para responder
3 respuestas en este tema

#1 Pratasvenska

Pratasvenska

    Member

  • Miembros
  • PipPip
  • 38 mensajes
  • LocationSuecia

Escrito 25 mayo 2012 - 03:39

Hola amigos,

Quiero que el caption de un label se muestre de la siguiente forma, por ejemplo:

El alumno Juan Perez fue expulsado.

Espero alguien me pueda aconsejar... Por diversas razones no puedo usar multiples labels., tiene que ser todo en una.

Saludos.
  • 0

#2 TiammatMX

TiammatMX

    Advanced Member

  • Miembros
  • PipPipPip
  • 1.750 mensajes
  • LocationUniverso Curvo\Vía Láctea\Sistema Solar\Planeta Tierra\América\México\Ciudad de México\Xochimilco\San Gregorio Atlapulco\Home

Escrito 25 mayo 2012 - 06:02

Con un TRichEdit puedes hacer éste efecto, si lo adaptas al tamaño que cualquier TLabel exhibe. Rellenarlo en tiempo de ejecución es otro cantar, pero de que sucederá lo que necesitas, ni quien lo dude.

Bienvenido.
  • 0

#3 razadi

razadi

    Advanced Member

  • Miembro Platino
  • PipPipPip
  • 681 mensajes
  • LocationMéxico D.F.

Escrito 26 mayo 2012 - 06:12

Segun yo nada mejor que te hagas tus propios componente que puedes ir adaptando conforme los ocupas, hace algun tiempo me hice unas labels que requeria y una de ellas era precisamente que me permitiera poner en medio de una frase algunas caracteristicas como el html y pos me di a la tarea de hacerla y con gusto la comparto para todos los "comuneros" y espero te sirva, saludos



delphi
  1. unit eLabels;
  2.  
  3. interface
  4.  
  5. uses
  6.   Windows, Classes, Controls, SysUtils, Graphics, ImgList, Messages,
  7.   Forms, Math, Types, cSharedCommon, cSharedDraw, cClasses, StdCtrls,
  8.   UxTheme, Themes, DwmApi
  9.  
  10.  
  11. type
  12.  
  13.   TeLinkLabelDisplayMode = (dmNone, dmGlyph, dmImageList);
  14.  
  15.   TeLinkLabel = class(TCustomControl)
  16.   private
  17.     FCaption: WideString;
  18.     FDisplayMode: TeLinkLabelDisplayMode;
  19.     FGlyph: TBitmap;
  20.     FHover: Boolean;
  21.     FImageIndex: TImageIndex;
  22.     FImages: TCustomImageList;
  23.     FTextDistance: Integer;
  24.     FTransparent: Boolean;
  25.     FTransparentColor: TColor;
  26.     FVertSpacing: Integer;
  27.     procedure ApplyTransparentColor(const Value: TColor);
  28.     procedure MakeAutoSize(var NewWidth: Integer; var NewHeight: Integer);
  29.     procedure SetCaption(const Value: WideString);
  30.     procedure SetDisplayMode(const Value: TeLinkLabelDisplayMode);
  31.     procedure SetGlyph(const Value: TBitmap);
  32.     procedure SetImageIndex(const Value: TImageIndex);
  33.     procedure SetImages(const Value: TCustomImageList);
  34.     procedure SetTextDistance(const Value: Integer);
  35.     procedure SetTransparent(const Value: Boolean);
  36.     procedure SetTransparentColor(const Value: TColor);
  37.     procedure SetVertSpacing(const Value: Integer);
  38.   protected
  39.     function CanAutoSize(var NewWidth, NewHeight: Integer): Boolean; override;
  40.     procedure Changed;
  41.     procedure CMEnabledChanged(var Message: TMessage); message CM_ENABLEDCHANGED;
  42.     procedure CMFontChanged(var Message: TMessage); message CM_FONTCHANGED;
  43.   procedure CMMouseEnter(var Message: TMessage); message CM_MOUSEENTER;
  44.     procedure CMMouseLeave(var Message: TMessage); message CM_MOUSELEAVE;
  45.     procedure CMTextChanged(var Message: TMessage); message CM_TEXTCHANGED;
  46.     procedure CreateParams(var Params: TCreateParams); override;
  47.     procedure CreateWnd; override;
  48.     procedure DoEnter; override;
  49.     procedure DoExit; override;
  50.     procedure DoGlyphChange(Sender: TObject);
  51.     procedure MouseDown(Button: TMouseButton; Shift: TShiftState; X, Y: Integer); override;
  52.     procedure Notification(AComponent: TComponent; Operation: TOperation); override;
  53.     procedure Paint; override;
  54.     procedure RefreshText;
  55.     procedure SetName(const Value: TComponentName); override;
  56.     procedure WMEraseBkGnd(var Message: TWMEraseBkGnd); message WM_ERASEBKGND;
  57.     procedure WMKillFocus(var Message: TWMSetFocus); message WM_KILLFOCUS;
  58.     procedure WMWindowPosChanged(var Message: TWMWindowPosChanged); message WM_WINDOWPOSCHANGED; public
  59.   public
  60.     constructor Create(AOwner: TComponent); override;
  61.     destructor Destroy; override;
  62.   published
  63.     property Action;
  64.     property Align;
  65.     property Anchors;
  66.     property AutoSize default True;
  67.     property Caption: WideString read FCaption write SetCaption;
  68.     property Color;
  69.     property Constraints;
  70.     property DisplayMode: TeLinkLabelDisplayMode read FDisplayMode write SetDisplayMode default dmGlyph;
  71.     property DragCursor;
  72.     property DragKind;
  73.     property DragMode;
  74.     property Enabled;
  75.     property Font;
  76.     property Glyph: TBitmap read FGlyph write SetGlyph;
  77.     property ImageIndex: TImageIndex read FImageIndex write SetImageIndex default -1;
  78.     property Images: TCustomImageList read FImages write SetImages;
  79.     property ParentColor;
  80.     property ParentFont;
  81.     property ParentShowHint;
  82.     property PopupMenu;
  83.     property ShowHint;
  84.     property TextDistance: Integer read FTextDistance write SetTextDistance;
  85.     property TabStop;
  86.     property Transparent: Boolean read FTransparent write SetTransparent default False;
  87.     property TransparentColor: TColor read FTransparentColor write SetTransparentColor default clNone;
  88.     property Visible;
  89.     property VertSpacing: Integer read FVertSpacing write SetVertSpacing;
  90.     property OnClick;
  91.     property OnContextPopup;
  92.     property OnDblClick;
  93.     property OnDragDrop;
  94.     property OnDragOver;
  95.     property OnEndDock;
  96.     property OnEndDrag;
  97.     property OnEnter;
  98.     property OnExit;
  99.     property OnMouseDown;
  100.     property OnMouseMove;
  101.     property OnMouseUp;
  102.     property OnStartDock;
  103.     property OnStartDrag;
  104.   end;
  105.  
  106.  
  107.   TeHtmlLabel = class(TCustomControl)
  108.   private
  109.     FCaption: WideString;
  110.     FOnLinkClick: TeHtmlClicEvento;
  111.     FWordWrap: Boolean;
  112.     FShowAccelChar: Boolean;
  113.     FEllipsisPosition: TEllipsisPosition;
  114.     procedure SetCaption(const Value: WideString);
  115.     procedure SetWordWrap(const Value: Boolean);
  116.     procedure SetShowAccelChar(const Value: Boolean);
  117.     procedure SetEllipsisPosition(const Value: TEllipsisPosition);
  118.   protected
  119.     procedure AdjustBounds; dynamic;
  120.     procedure DoDrawText(var Rect: TRect; Flags: Longint); dynamic;
  121.     function GetLabelText: string; virtual;
  122.     function CanAutoSize(var NewWidth, NewHeight: Integer): Boolean; override;
  123.     procedure CMMouseLeave(var Message: TMessage); message CM_MOUSELEAVE;
  124.     procedure MouseDown(Button: TMouseButton; Shift: TShiftState; X, Y: Integer); override;
  125.     procedure MouseMove(Shift: TShiftState; X, Y: Integer); override;
  126.     procedure MouseUp(Button: TMouseButton; Shift: TShiftState; X, Y: Integer); override;
  127.     procedure Paint; override;
  128.     procedure WMEraseBkGnd(var Message: TWMEraseBkGnd); message WM_ERASEBKGND;
  129.     property EllipsisPosition: TEllipsisPosition read FEllipsisPosition write SetEllipsisPosition default epNone;
  130.     property ShowAccelChar: Boolean read FShowAccelChar write SetShowAccelChar default False;
  131.   public
  132.     constructor Create(AOwner: TComponent); override;
  133.     destructor Destroy; override;
  134.   published
  135.     property Action;
  136.     property Align;
  137.     property Anchors;
  138.     property AutoSize default False;
  139.     property Caption: WideString read FCaption write SetCaption;
  140.     property Color;
  141.     property Constraints;
  142.     property DragCursor;
  143.     property DragKind;
  144.     property DragMode;
  145.     property Enabled;
  146.     property Font;
  147.     property ParentColor;
  148.     property ParentFont;
  149.     property ParentShowHint;
  150.     property PopupMenu;
  151.     property ShowHint;
  152.     property TabStop;
  153.     property Visible;
  154.     property WordWrap: Boolean read FWordWrap write SetWordWrap default False;
  155.  
  156.     property OnClick;
  157.     property OnContextPopup;
  158.     property OnDblClick;
  159.     property OnDragDrop;
  160.     property OnDragOver;
  161.     property OnEndDock;
  162.     property OnEndDrag;
  163.     property OnEnter;
  164.     property OnExit;
  165.     property OnLinkClick: TeHtmlClicEvento read FOnLinkClick write FOnLinkClick;
  166.     property OnMouseDown;
  167.     property OnMouseMove;
  168.     property OnMouseUp;
  169.     property OnStartDock;
  170.     property OnStartDrag;
  171.   end;
  172.  
  173. procedure Register;
  174.  
  175. implementation
  176.  
  177. procedure Register;
  178. begin
  179.   RegisterComponents('Componentes efectisoft', [TeLinkLabel,TeHtmlLabel]);
  180. end;
  181.  
  182. { TeLinkLabel }
  183.  
  184. procedure TeLinkLabel.ApplyTransparentColor(const Value: TColor);
  185. begin
  186.   FGlyph.Transparent := True;
  187.   FGlyph.TransparentColor := Value;
  188. end;
  189.  
  190. function TeLinkLabel.CanAutoSize(var NewWidth, NewHeight: Integer): Boolean;
  191. var
  192.   ANewWidth, ANewHeight: Integer;
  193. begin
  194.   Result := True;
  195.   MakeAutoSize(ANewWidth, ANewHeight);
  196.   if Align in [alNone, alLeft, alRight] then
  197.     NewWidth := ANewWidth;
  198.   if Align in [alNone, alTop, alBottom] then
  199.     NewHeight := ANewHeight;
  200. end;
  201.  
  202. procedure TeLinkLabel.Changed;
  203. begin
  204.   if AutoSize then AdjustSize
  205.     else Invalidate;
  206. end;
  207.  
  208. procedure TeLinkLabel.CMEnabledChanged(var Message: TMessage);
  209. begin
  210.   inherited;
  211.   RefreshText;
  212. end;
  213.  
  214. procedure TeLinkLabel.CMFontChanged(var Message: TMessage);
  215. begin
  216.   inherited;
  217.   Changed;
  218. end;
  219.  
  220. procedure TeLinkLabel.CMMouseEnter(var Message: TMessage);
  221. begin
  222.   if not(csDesigning in ComponentState) then begin
  223.     FHover := True;
  224.     RefreshText;
  225.   end;
  226. end;
  227.  
  228. procedure TeLinkLabel.CMMouseLeave(var Message: TMessage);
  229. begin
  230.   if not(csDesigning in ComponentState) then begin
  231.     FHover := False;
  232.     RefreshText;
  233.   end;
  234. end;
  235.  
  236. procedure TeLinkLabel.CMTextChanged(var Message: TMessage);
  237. begin
  238.   Invalidate;
  239.   Realign;
  240. end;
  241.  
  242. constructor TeLinkLabel.Create(AOwner: TComponent);
  243. begin
  244.   inherited;
  245.   ControlStyle := [csCaptureMouse, csClickEvents, csSetCaption, csDoubleClicks, csReplicatable];
  246.   DoubleBuffered := True;
  247.   AutoSize := True;
  248.   FDisplayMode := dmGlyph;
  249.   FGlyph := TBitmap.Create;
  250.   FGlyph.OnChange := DoGlyphChange;
  251.   FImageIndex := -1;
  252.   FImages := nil;
  253.   FTransparentColor := clNone;
  254.   FHover := False;
  255.   FTextDistance := 2;
  256.   FTransparent := False;
  257.   FVertSpacing := 2;
  258.   ParentColor := True;
  259. end;
  260.  
  261. procedure TeLinkLabel.CreateParams(var Params: TCreateParams);
  262. begin
  263.   inherited;
  264.  
  265. end;
  266.  
  267. procedure TeLinkLabel.CreateWnd;
  268. begin
  269.   inherited;
  270.  
  271. end;
  272.  
  273. destructor TeLinkLabel.Destroy;
  274. begin
  275.   FGlyph.Free;
  276.   inherited;
  277. end;
  278.  
  279. procedure TeLinkLabel.DoEnter;
  280. begin
  281.   inherited;
  282.   Invalidate;
  283. end;
  284.  
  285. procedure TeLinkLabel.DoExit;
  286. begin
  287.   inherited;
  288.   Invalidate;
  289. end;
  290.  
  291. procedure TeLinkLabel.DoGlyphChange(Sender: TObject);
  292. begin
  293.   ApplyTransparentColor(FGlyph.Canvas.Pixels[0, FGlyph.Height - 1]);
  294.   Changed;
  295. end;
  296.  
  297. procedure TeLinkLabel.MakeAutoSize(var NewWidth, NewHeight: Integer);
  298. begin
  299.   if HandleAllocated then begin
  300.     Canvas.Font.Assign(Font);
  301.     NewHeight := Canvas.TextHeight(Caption);
  302.     NewWidth := Canvas.TextWidth(Caption);
  303.     case FDisplayMode of
  304.       dmGlyph:
  305.         if not Glyph.Empty then with Canvas do begin
  306.           if FGlyph.Height > NewHeight then NewHeight := FGlyph.Height;
  307.           Inc(NewWidth, FGlyph.Width + FTextDistance);
  308.         end;
  309.       dmImageList:
  310.         if Assigned(FImages) and InRange(FImageIndex, 0, FImages.Count) then begin
  311.           if FImages.Height > NewWidth then NewHeight := FImages.Height;
  312.           Inc(NewWidth, FImages.Width + FTextDistance);
  313.         end;
  314.     end;
  315.     NewHeight := NewHeight + FVertSpacing;
  316.   end;
  317. end;
  318.  
  319. procedure TeLinkLabel.MouseDown(Button: TMouseButton; Shift: TShiftState; X,
  320.   Y: Integer);
  321. begin
  322.   inherited;
  323.   if TabStop then
  324.   begin
  325.     SetFocus;
  326.     Invalidate;
  327.   end;
  328. end;
  329.  
  330. procedure TeLinkLabel.Notification(AComponent: TComponent;
  331.   Operation: TOperation);
  332. begin
  333.   inherited;
  334.   if (Operation = opRemove) and (AComponent = FImages) then FImages := nil;
  335. end;
  336.  
  337. procedure TeLinkLabel.Paint;
  338. var
  339. X, Y: Integer;
  340.   fr: TRect;
  341. begin
  342.   inherited;
  343. X := 0;
  344.   with Canvas do begin
  345.     if Transparent then
  346.       DrawTransparent(Self, Canvas)
  347.     else begin
  348.       Brush.Color := Self.Color;
  349.       FillRect(ClientRect);
  350.     end;
  351.     case FDisplayMode of
  352.       dmGlyph:
  353.         if not(FGlyph.Empty) then begin
  354.           Y := (Height div 2) - (FGlyph.Height div 2);
  355.           FGlyph.Transparent := True;
  356.           DrawBitmap(Canvas, X, Y, FGlyph, Color);
  357.           Inc(X, FGlyph.Width + FTextDistance);
  358.         end;
  359.       dmImageList:
  360.         if Assigned(FImages) and InRange(FImageIndex, 0, FImages.Count) then begin
  361.           Y := (Height div 2) - (Images.Height div 2);
  362.           FGlyph.Transparent := True;
  363.           FImages.Draw(Canvas, X, Y, FImageIndex);
  364.           Inc(X, FImages.Width + FTextDistance);
  365.         end;
  366.     end;
  367.     Font.Assign(Self.Font);
  368.     if FHover then
  369.       Font.Style := Font.Style + [fsUnderline];
  370.     if not Enabled then
  371.       Font.Color := clGrayText;
  372.     TGraphicsProvider.DrawTextRect(Canvas, Rect(X, 0, Width, Height), taLeftJustify, Caption);
  373.     fr := Rect(0, 0, Width, Height);
  374.     if Focused then
  375.       TGraphicsProvider.DrawFocused(Canvas, fr);
  376.   end;
  377. end;
  378.  
  379. procedure TeLinkLabel.RefreshText;
  380. var
  381.   r: TRect;
  382. begin
  383.   if not(FGlyph.Empty) then r := Rect(FGlyph.Width + FTextDistance, 0, ClientWidth, ClientHeight) else r := ClientRect;
  384.   InvalidateRect(Handle, @r, False);
  385. end;
  386.  
  387. procedure TeLinkLabel.SetCaption(const Value: WideString);
  388. begin
  389.   FCaption := Value;
  390.   Changed;
  391. end;
  392.  
  393. procedure TeLinkLabel.SetDisplayMode(const Value: TeLinkLabelDisplayMode);
  394. begin
  395.   FDisplayMode := Value;
  396.   Changed;
  397. end;
  398.  
  399. procedure TeLinkLabel.SetGlyph(const Value: TBitmap);
  400. begin
  401.   FGlyph.Assign(Value);
  402.   Changed;
  403. end;
  404.  
  405. procedure TeLinkLabel.SetImageIndex(const Value: TImageIndex);
  406. begin
  407.   FImageIndex := Value;
  408.   Invalidate;
  409. end;
  410.  
  411. procedure TeLinkLabel.SetImages(const Value: TCustomImageList);
  412. begin
  413.   FImages := Value;
  414.   if Value <> nil then begin
  415.     FImages.FreeNotification(Self);
  416.   end else begin
  417.     FImages.RemoveFreeNotification(Self);
  418.   end;
  419. end;
  420.  
  421. procedure TeLinkLabel.SetName(const Value: TComponentName);
  422. begin
  423.   inherited;
  424.   if not (csLoading in ComponentState) then
  425.     if Caption = '' then
  426.       Caption := Name;
  427. end;
  428.  
  429. procedure TeLinkLabel.SetTextDistance(const Value: Integer);
  430. begin
  431.   FTextDistance := Value;
  432.   Changed;
  433. end;
  434.  
  435. procedure TeLinkLabel.SetTransparent(const Value: Boolean);
  436. begin
  437.   FTransparent := Value;
  438.   Invalidate;
  439. end;
  440.  
  441. procedure TeLinkLabel.SetTransparentColor(const Value: TColor);
  442. begin
  443.   FTransparentColor := Value;
  444.   ApplyTransparentColor(FTransparentColor);
  445. end;
  446.  
  447. procedure TeLinkLabel.SetVertSpacing(const Value: Integer);
  448. begin
  449.   FVertSpacing := Value;
  450.   Changed;
  451. end;
  452.  
  453. procedure TeLinkLabel.WMEraseBkGnd(var Message: TWMEraseBkGnd);
  454. begin
  455.   Message.Result := 1;
  456. end;
  457.  
  458. procedure TeLinkLabel.WMKillFocus(var Message: TWMSetFocus);
  459. begin
  460.   inherited;
  461.   Invalidate;
  462. end;
  463.  
  464. procedure TeLinkLabel.WMWindowPosChanged(var Message: TWMWindowPosChanged);
  465. begin
  466.   inherited;
  467.   if Transparent then
  468.     Invalidate;
  469. end;
  470.  
  471. { TeHtmlLabel }
  472.  
  473. procedure TeHtmlLabel.AdjustBounds;
  474. const
  475.   WordWraps: array[Boolean] of Word = (0, DT_WORDBREAK);
  476. var
  477.   DC: HDC;
  478.   X: Integer;
  479.   Rect: TRect;
  480.   AAlignment: TAlignment;
  481. begin
  482.   if not (csReading in ComponentState) and AutoSize then begin
  483.     Rect := ClientRect;
  484.     DC := GetDC(0);
  485.     try
  486.       Canvas.Handle := DC;
  487.       DoDrawText(Rect, (DT_EXPANDTABS or DT_CALCRECT) or WordWraps[FWordWrap]);
  488.       Canvas.Handle := 0;
  489.     finally
  490.       ReleaseDC(0, DC);
  491.     end;
  492.     X := Left;
  493.     //AAlignment := FAlignment;
  494.     if UseRightToLeftAlignment then
  495.       ChangeBiDiModeAlignment(AAlignment);
  496.     //if AAlignment = taRightJustify then
  497.       Inc(X, Width - Rect.Right);
  498.     SetBounds(X, Top, Rect.Right, Rect.Bottom);
  499.   end;
  500. end;
  501.  
  502. function TeHtmlLabel.CanAutoSize(var NewWidth, NewHeight: Integer): Boolean;
  503. var
  504.   HtmlInfo: THtmlInfo;
  505. begin
  506.   Result := True;
  507.   HtmlInfo := ProcessHTML(Canvas, ClientRect, Caption, Point(0, 0), False);
  508.   NewWidth := HtmlInfo.Size.cx;
  509.   NewHeight := HtmlInfo.Size.cy;
  510. end;
  511.  
  512. procedure TeHtmlLabel.CMMouseLeave(var Message: TMessage);
  513. begin
  514.   if Screen.Cursor = crHandPoint then
  515.     Screen.Cursor := Cursor;
  516. end;
  517.  
  518. constructor TeHtmlLabel.Create(AOwner: TComponent);
  519. begin
  520.   inherited;
  521.  
  522. end;
  523.  
  524. destructor TeHtmlLabel.Destroy;
  525. begin
  526.  
  527.   inherited;
  528. end;
  529.  
  530. procedure TeHtmlLabel.DoDrawText(var Rect: TRect; Flags: Integer);
  531.   procedure DoDrawThemeTextEx(DC: HDC; const Text: string;
  532.     var TextRect: TRect; TextFlags: Cardinal);
  533.   var
  534.     Options: TDTTOpts;
  535.   begin
  536.     FillChar(Options, SizeOf(Options), 0);
  537.     Options.dwSize := SizeOf(Options);
  538.     Options.dwFlags := DTT_TEXTCOLOR or DTT_COMPOSITED;
  539.     if TextFlags and DT_CALCRECT = DT_CALCRECT then
  540.       Options.dwFlags := Options.dwFlags or DTT_CALCRECT;
  541.     Options.crText := ColorToRGB(Canvas.Font.Color);
  542.  
  543.     with ThemeServices.GetElementDetails(teEditTextNormal) do
  544.       DrawThemeTextEx(ThemeServices.Theme[teEdit], DC, Part, State,
  545.         PWideChar(WideString(Text)), Length(WideString(Text)), TextFlags, @TextRect, Options);
  546.   end;
  547.  
  548.   procedure DrawText(DC: HDC; const Text: string; TextLen: Integer;
  549.     var TextRect: TRect; TextFlags: Cardinal);
  550.   var
  551.     LForm: TCustomForm;
  552.     PaintOnGlass: Boolean;
  553.   begin
  554.     PaintOnGlass := ThemeServices.ThemesEnabled and DwmCompositionEnabled and
  555.       not (csDesigning in ComponentState);
  556.     if PaintOnGlass then
  557.     begin
  558.       LForm := GetParentForm(Self);
  559.       PaintOnGlass := (LForm <> nil) and LForm.GlassFrame.FrameExtended and
  560.         LForm.GlassFrame.IntersectsControl(Self);
  561.     end;
  562.     if PaintOnGlass then
  563.       DoDrawThemeTextEx(DC, Text, TextRect, TextFlags)
  564.     else
  565.     Windows.DrawText(DC, PChar(Text), TextLen, TextRect, TextFlags);
  566.   end;
  567.  
  568. const
  569.   EllipsisStr = '...';
  570.   Ellipsis: array[TEllipsisPosition] of Longint = (0, DT_PATH_ELLIPSIS,
  571.     DT_END_ELLIPSIS, DT_WORD_ELLIPSIS);
  572. var
  573.   Text, DText: string;
  574.   NewRect: TRect;
  575.   Height, Delim: Integer;
  576. begin
  577.   Text := GetLabelText;
  578.   if (Flags and DT_CALCRECT <> 0) and ((Text = '') or FShowAccelChar and
  579.     (Text[1] = '&') and (Text[2] = #0)) then Text := Text + ' ';
  580.   if not FShowAccelChar then Flags := Flags or DT_NOPREFIX;
  581.   Flags := DrawTextBiDiModeFlags(Flags);
  582.   Canvas.Font := Font;
  583.   if (FEllipsisPosition <> epNone) and not AutoSize then
  584.   begin
  585.     DText := Text;
  586.     Flags := Flags and not DT_EXPANDTABS;
  587.     Flags := Flags or Ellipsis[FEllipsisPosition];
  588.     if FWordWrap and (FEllipsisPosition in [epEndEllipsis, epWordEllipsis]) then
  589.     begin
  590.       repeat
  591.         NewRect := Rect;
  592.         Dec(NewRect.Right, Canvas.TextWidth(EllipsisStr));
  593.         Windows.DrawText(Canvas.Handle, PChar(DText), Length(DText), NewRect, Flags or DT_CALCRECT);
  594.         Height := NewRect.Bottom - NewRect.Top;
  595.         if (Height > ClientHeight) and (Height > Canvas.Font.Height) then
  596.         begin
  597.           Delim := LastDelimiter(' '#9, Text);
  598.           if Delim = 0 then
  599.             Delim := Length(Text);
  600.           Dec(Delim);
  601.           if ByteType(Text, Delim) = mbLeadByte then
  602.             Dec(Delim);
  603.           Text := Copy(Text, 1, Delim);
  604.           DText := Text + EllipsisStr;
  605.           if Text = '' then
  606.             Break;
  607.         end else
  608.           Break;
  609.       until False;
  610.     end;
  611.     if Text <> '' then
  612.       Text := DText;
  613.   end;
  614.   if not Enabled then
  615.   begin
  616.     OffsetRect(Rect, 1, 1);
  617.     Canvas.Font.Color := clBtnHighlight;
  618.     DrawText(Canvas.Handle, Text, Length(Text), Rect, Flags);
  619.     OffsetRect(Rect, -1, -1);
  620.     Canvas.Font.Color := clBtnShadow;
  621.     DrawText(Canvas.Handle, Text, Length(Text), Rect, Flags);
  622.   end
  623.   else
  624.     DrawText(Canvas.Handle, Text, Length(Text), Rect, Flags);
  625. end;
  626.  
  627. function TeHtmlLabel.GetLabelText: string;
  628. begin
  629.   Result := Caption;
  630. end;
  631.  
  632. procedure TeHtmlLabel.MouseDown(Button: TMouseButton; Shift: TShiftState; X,
  633.   Y: Integer);
  634. begin
  635.   inherited;
  636.  
  637. end;
  638.  
  639. procedure TeHtmlLabel.MouseMove(Shift: TShiftState; X, Y: Integer);
  640. var
  641.   TagValue: WideString;
  642. begin
  643.   inherited;
  644.   TagValue := ProcessHTML(Canvas, Self.ClientRect, Caption, Point(X, Y), False).TagValue;
  645.   if TagValue <> '' then
  646.     Screen.Cursor := crHandPoint
  647.   else
  648.     Screen.Cursor := Cursor;
  649. end;
  650.  
  651. procedure TeHtmlLabel.MouseUp(Button: TMouseButton; Shift: TShiftState; X,
  652.   Y: Integer);
  653. var
  654.   TagValue: WideString;
  655. begin
  656.   inherited;
  657.   TagValue := ProcessHTML(Canvas, Self.ClientRect, Caption, Point(X, Y), False).TagValue;
  658.   if TagValue <> '' then
  659.     if Assigned(OnLinkClick) then
  660.       OnLinkClick(Self, TagValue);
  661. end;
  662.  
  663. procedure TeHtmlLabel.Paint;
  664. begin
  665.   inherited;
  666.   with Canvas do begin
  667.     Font.Assign(Self.Font);
  668.     Brush.Color := Color;
  669.     FillRect(ClientRect);
  670.   end;
  671.   ProcessHTML(Canvas, ClientRect, Caption, Point(0, 0), True);
  672. end;
  673.  
  674. procedure TeHtmlLabel.SetCaption(const Value: WideString);
  675. begin
  676.   FCaption := Value;
  677.   Invalidate;
  678. end;
  679.  
  680. procedure TeHtmlLabel.SetEllipsisPosition(const Value: TEllipsisPosition);
  681. begin
  682.   if FEllipsisPosition <> Value then begin
  683.     FEllipsisPosition := Value;
  684.     AutoSize := False;
  685.     Invalidate;
  686.   end;
  687. end;
  688.  
  689. procedure TeHtmlLabel.SetShowAccelChar(const Value: Boolean);
  690. begin
  691.   if FShowAccelChar <> Value then begin
  692.     FShowAccelChar := Value;
  693.     Invalidate;
  694.   end;
  695. end;
  696.  
  697. procedure TeHtmlLabel.SetWordWrap(const Value: Boolean);
  698. begin
  699.   if FWordWrap <> Value then begin
  700.     FWordWrap := Value;
  701.     AdjustBounds;
  702.     Invalidate;
  703.   end;
  704. end;
  705.  
  706. procedure TeHtmlLabel.WMEraseBkGnd(var Message: TWMEraseBkGnd);
  707. begin
  708.   Message.Result := 1;
  709. end;
  710.  
  711. end.



y cuando la llamas la usas tan simple como:



delphi
  1. ...
  2. var
  3.   miLabel: TeHTMLLabel;
  4. begin
  5. ...
  6.   miLabel.Caption := 'El alumno <b>Juan Perez</b> fue expulsado.';
  7. ...



espero te sirva, saludos.
  • 0

#4 Pratasvenska

Pratasvenska

    Member

  • Miembros
  • PipPip
  • 38 mensajes
  • LocationSuecia

Escrito 29 mayo 2012 - 06:12

Hola, disculpa tenía días que no me pasaba por aquí pero ahora veo tu solución. Claro que sirve. Muchas gracias!
  • 0




IP.Board spam blocked by CleanTalk.