如何實現字型樣式預覽? |
答題得分者是:hagar
|
qoo1234
版主 發表:256 回覆:1167 積分:659 註冊:2003-02-24 發送簡訊給我 |
|
Fishman
尊榮會員 發表:120 回覆:1949 積分:2163 註冊:2006-10-28 發送簡訊給我 |
|
Fishman
尊榮會員 發表:120 回覆:1949 積分:2163 註冊:2006-10-28 發送簡訊給我 |
Hi: 也可以直接使用 Dialogs 下的 FontDialog
procedure TForm1.Button17Click(Sender: TObject); begin if FontDialog1.Execute then Button17.Font := FontDialog1.Font; end;至於 ComboBox,........努力中 -------------------------------- 小弟才疏學淺,若有謬誤請不吝指教 --------------------------------
------
Fishman |
qoo1234
版主 發表:256 回覆:1167 積分:659 註冊:2003-02-24 發送簡訊給我 |
|
hagar
版主 發表:143 回覆:4056 積分:4445 註冊:2002-04-14 發送簡訊給我 |
http://codecentral.borland.com/codecentral/ccweb.exe/listing?id=17197
unit FontComboBx; interface uses Windows, Messages, SysUtils, Classes, Controls, StdCtrls; type TFontComboBox = class(TCustomComboBox) private { Private declarations } protected { Protected declarations } procedure DrawItem(Index: Integer; Rect: TRect; State: TOwnerDrawState); override; procedure CreateWnd; override; public constructor Create(AOwner: TComponent); override; { Public declarations } published property AutoComplete default True; property AutoDropDown default False; property BevelEdges; property BevelInner; property BevelKind default bkNone; property BevelOuter; property Anchors; property BiDiMode; property CharCase; property Color; property Constraints; property Ctl3D; property DragCursor; property DragKind; property DragMode; property DropDownCount; property Enabled; property Font; property ImeMode; property ImeName; property ItemHeight; property ItemIndex default -1; property MaxLength; property ParentBiDiMode; property ParentColor; property ParentCtl3D; property ParentFont; property ParentShowHint; property PopupMenu; property ShowHint; property Sorted; property TabOrder; property TabStop; property Text; property Visible; property OnChange; property OnClick; property OnCloseUp; property OnContextPopup; property OnDblClick; property OnDragDrop; property OnDragOver; property OnDrawItem; property OnDropDown; property OnEndDock; property OnEndDrag; property OnEnter; property OnExit; property OnKeyDown; property OnKeyPress; property OnKeyUp; property OnSelect; property OnStartDock; property OnStartDrag; property Items; { Must be published after OnMeasureItem } end; procedure Register; implementation uses Graphics, Forms; procedure Register; begin RegisterComponents('Custom', [TFontComboBox]); end; { TFontComboBox } constructor TFontComboBox.Create(AOwner: TComponent); begin inherited Create(AOwner); Style := csOwnerDrawVariable; end; procedure TFontComboBox.CreateWnd; var I: Integer; begin inherited; // Measure each item.. Items := Screen.Fonts; for I := 0 to Items.Count - 1 do begin Canvas.Font.Name := Items[I]; Canvas.Font.Size := 0; // use font's preferred size Perform(CB_SETITEMHEIGHT, I, Canvas.TextHeight(Items[I])); end; end; procedure TFontComboBox.DrawItem(Index: Integer; Rect: TRect; State: TOwnerDrawState); begin Canvas.FillRect(Rect); if (Index >= 0) and (Index < Items.Count) then begin if odSelected in State then Canvas.Font.Color := clHighlightText; Canvas.Font.Name := Items[Index]; Canvas.TextRect(Rect, Rect.Left 2, Rect.Top 2, Items[Index]); end; end; end.--- Everything I say is a lie. |
qoo1234
版主 發表:256 回覆:1167 積分:659 註冊:2003-02-24 發送簡訊給我 |
本站聲明 |
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。 2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。 3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇! |