View Issue Details
ID | Project | Category | View Status | Date Submitted | Last Update |
---|---|---|---|---|---|
0006600 | JEDI VCL | 00 JVCL Components | public | 2017-10-21 15:57 | 2018-07-18 15:59 |
Reporter | tetardd | Assigned To | |||
Priority | normal | Severity | feature | Reproducibility | N/A |
Status | acknowledged | Resolution | open | ||
Product Version | 3.48 | ||||
Target Version | Fixed in Version | ||||
Summary | 0006600: Changed to TJvArrowButton to make it easy to ownerdraw | ||||
Description | I have made some changes to the JvArrowButton unit (quite trivial ones) to allow a descendant of TJvArrowButton to be owner drawn (caption and glyph). The changes are all marked with my name "David Tetard" and some explanation why I made these changes are included in the uploaded file. | ||||
Tags | No tags attached. | ||||
related to | 0006601 | acknowledged | TJvArrowButton - Glyph and caption not properly drawn when using Margin |
2017-10-21 15:57
|
JvArrayButton.pas (19,650 bytes) |
|
I forgot to add, now to owner draw, simply create a descendant of TGlyphButton and override the DrawText and/or DrawGlyph methods (now made protected and virtual) and override the new procedure CreateGlyphButton to use: FGlyphButton := TMyGlyphButton.Create(Self). Here is an example: =================================================== unit Unit4; interface uses Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics, Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.Buttons, JvExControls, JvArrowButton; type TDTButtonGlyph = Class(TButtonGlyph) Protected procedure DrawButtonText(Canvas: TCanvas; const Caption: string; TextBounds: TRect; State: TButtonState; Alignment: TAlignment; VerticalAlignment: TVerticalAlignment); Override; End; TDTArrowButton = Class(TJvArrowButton) Protected Procedure CreateButtonGlyph; Override; End; TForm4 = class(TForm) procedure FormCreate(Sender: TObject); private id_DTArrowButton : TDTArrowButton; public { Public declarations } end; var Form4: TForm4; implementation Uses JvJCLUtils; {$R *.dfm} procedure TForm4.FormCreate(Sender: TObject); begin id_DTArrowButton := TDTArrowButton.Create(Self); id_DTArrowButton.Parent := Self; id_DTArrowButton.SetBounds(10, 10, 300, 50); id_DTArrowButton.Caption := Blah Blah Blah; end; { TDTArrowButton } procedure TDTArrowButton.CreateButtonGlyph; begin FGlyph := TDTButtonGlyph.Create(Self); end; { TDTButtonGlyph } procedure TDTButtonGlyph.DrawButtonText(Canvas: TCanvas; const Caption: string; TextBounds: TRect; State: TButtonState; Alignment: TAlignment; VerticalAlignment: TVerticalAlignment); const AlignFlags: array[TAlignment] of Integer = (DT_LEFT, DT_RIGHT, DT_CENTER); VerticalAlignFlags: array[TVerticalAlignment] of Integer = (DT_TOP, DT_BOTTOM, DT_VCENTER); var S: string; begin S := Caption; with Canvas do begin Brush.Style := bsClear; // Just to test that it works, all captions will be drawn in blue: Font.Color := clBlue; if State = bsDisabled then begin OffsetRect(TextBounds, 1, 1); DrawText(Canvas, S, -1, TextBounds, AlignFlags[Alignment] or VerticalAlignFlags[VerticalAlignment] or DT_SINGLELINE); OffsetRect(TextBounds, -1, -1); Font.Color := clBtnShadow; DrawText(Canvas, S, -1, TextBounds, AlignFlags[Alignment] or VerticalAlignFlags[VerticalAlignment] or DT_SINGLELINE); end else begin DrawText(Canvas, S, -1, TextBounds, AlignFlags[Alignment] or VerticalAlignFlags[VerticalAlignment] or DT_SINGLELINE); end; end; end; |