unit ISButton; interface uses Windows, Messages, Classes, Graphics, Controls, StdCtrls, ImgList, JvButton,JvCtrls; type TISButton = class(TJvCustomImageButton) public procedure DrawButtonText(TextBounds: TRect; TextEnabled: Boolean); override; procedure CalcButtonParts(ButtonRect: TRect; var RectText, RectImage: TRect); override; published property Alignment; property Animate; property AnimateFrames; property AnimateInterval; property Color; property DropDownMenu; property DropArrow; property Flat; property HotTrack; property HotTrackFont; property HotTrackFontOptions; property HintColor; property Images; property ImageIndex; property ImageVisible; property Kind; property Layout; property Margin; property Spacing; property WordWrap; property OnMouseEnter; property OnMouseLeave; property OnParentColorChange; property OwnerDraw; {$IFDEF VCL} property OnButtonDraw; {$ENDIF VCL} property OnDropDownMenu; property OnGetAnimateIndex; end; procedure Register; implementation uses Consts, SysUtils, Forms, ActnList, ExtCtrls, JvJCLUtils, JvJVCLUtils, JvThemes; Const Alignments: array [TAlignment] of Word = (DT_LEFT, DT_RIGHT, DT_CENTER); procedure Register; begin RegisterComponents('InFoStar', [TISButton]); end; procedure TISButton.DrawButtonText(TextBounds: TRect; TextEnabled: Boolean); var Flags: DWORD; RealCaption: string; cap: array[1..10] of string; pm,pc,SubH:integer; SubRect:TRect; FontHeight: Integer; begin RealCaption :=GetRealCaption; with Canvas do begin Brush.Style := bsClear; FontHeight := TextHeight('W'); Pm:=1; Cap[pm]:=''; For pc:=1 to length(RealCaption) do if (Realcaption[pc] = '~') and (Pm < 11) then begin inc(pm); Cap[pm]:=''; end else Cap[pm]:=Cap[pm]+RealCaption[pc]; SubH:=(ClientRect.Bottom-ClientRect.Top)-(FontHeight*pm); SubH:=SubH div (pm+1); for pc:=1 to pm do begin SubRect.Left:=TextBounds.Left; SubRect.Right:=TextBounds.Right; SubRect.Top:=(ClientRect.Top+(SubH*pc)+FontHeight*(pc-1)){*2}; SubRect.Bottom:=SubRect.Top+FontHeight; Flags := DT_EXPANDTABS or DT_VCENTER or Alignments[Alignment]; DrawText(Handle, PChar(cap[pc]), -1, SubRect, Flags); end; end; end; procedure TISButton.CalcButtonParts(ButtonRect: TRect; var RectText, RectImage: TRect); var ButtonHeight, BlockMargin, InternalSpacing: Integer; begin // ButtonWidth := ButtonRect.Right - ButtonRect.Left; ButtonHeight := ButtonRect.Bottom - ButtonRect.Top; if Margin = -1 then BlockMargin := 0 else BlockMargin := Margin; if IsImageVisible then begin with GetImageList do SetRect(RectImage, 0, 0, Width - 1, Height - 1); InternalSpacing := Spacing; end else begin SetRect(RectImage, 0, 0, 0, 0); InternalSpacing := 0; end; SetRect(RectText, 0, 0, 0, 0); RectText.Right := Width - RectImage.Right - Spacing - 6 - margin; case Layout of blImageLeft: begin OffsetRect(RectImage, BlockMargin, 0); OffsetRect(RectText, RectImage.Right + InternalSpacing, 0); end; blImageRight: begin OffsetRect(RectText, BlockMargin, 0); OffsetRect(RectImage, RectText.Right + InternalSpacing, 0); end; end; OffsetRect(RectImage, ButtonRect.Left, BlockMargin{(ButtonHeight - RectImage.Bottom) div 2} + ButtonRect.Top); OffsetRect(RectText, ButtonRect.Left, (ButtonHeight - RectText.Bottom) div 2 + ButtonRect.Top); end; end.