Delphi Programming Forum
C++Builder  |  Delphi  |  FireMonkey  |  C/C++  |  Free Pascal  |  Firebird
볼랜드포럼 BorlandForum
 경고! 게시물 작성자의 사전 허락없는 메일주소 추출행위 절대 금지
델파이 포럼
Q & A
FAQ
팁&트릭
강좌/문서
자료실
컴포넌트/라이브러리
FreePascal/Lazarus
볼랜드포럼 홈
헤드라인 뉴스
IT 뉴스
공지사항
자유게시판
해피 브레이크
공동 프로젝트
구인/구직
회원 장터
건의사항
운영진 게시판
회원 메뉴
북마크
델마당
볼랜드포럼 광고 모집

델파이 팁&트릭
Delphi Programming Tip&Tricks
[266] TPageControl에서 탭부분만 폰트를 변경한다면...
DrK [whitekid] 6043 읽음    2009-02-17 19:09
블로그 글을 그대로 올립니다...

TPageControl에서 탭부분만 폰트를 다른것 쓰려고 하면, 있을것 같은 TabFont 같은 프러퍼티가 없습니다. 델파이가 지원하지 않는건지, 아니면 Windows에서 지원하지 않는건지 잘 모르겠지만.. .하여간 지원하지 않습니다.

그런데 이걸 어떻게 해볼라고 뒤져보면 생각보다 힘듭니다. 그러다가 OwnerDraw 기능으로 하면 되겠지 하고 하면 어라? Theme기능이 안되네.. 쩝.. 이거 잘못하면 배보다 배꼽이 커집니다. 나는 그냥 탭 폰트만 바꾸고 싶었을 뿐인데, 그것도 아주 화려하게 색 넣을 필요도 없이 간단히 볼드만 넣고 싶을 뿐인데.....

그래서 구글링을 좀 하면 이런, 이런 자료가 나오지요. 모두들 OwnerDraw:=True로 만들어놓고 열심히 ThemeService를 이용해서 그립니다. 소스를 보자니, 이거참 나중에 이거 가져왔다 유지보수하려먼 머리 깨질것 같습니다. 그냥 탭 폰트 볼드만 주고 싶을 뿐인데....

그래.. 그럼 TPageControl의 폰트는 볼드주고 안의 모든 컨트럴들은 ParentFont := False를 주면... 하고 생각해주지만 이거 역시 그냥 볼드를 주는데, 복잡해지는것 같고, ParentFont := False라는 제약을 두는거 왠지 이상합니다.. 쩝...

그러다가 퍼뜩 든 생각.. 그냥 TabFont 프러퍼티주고, 그냥 오버라이드해서 Font로 설정하는것 내부 TabSheet까지 같은 폰트로 설정하는것 막아버리는거 되는거아닌가?... 그 생각으로 간단히 맹글어봤더니 어라? 그냥 쉽게 됩니다. 혹시나 이런 문제고 고민했던 분들... 그냥 쉽게 살아요.. ^^;

아래는 소스 그대로 올립니다. 정리하고 콤포넌트 만들기 귀찮아서...

unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, ComCtrls;

type
  TPageControl = class(ComCtrls.TPageControl)
  private
    FTabFont: TFont;
    procedure CMFontChanged(var Message); message CM_FONTCHANGED;
    procedure SetTabFont(const Value: TFont);
    procedure TabFontChanged(Sender: TObject);

  public
    constructor Create(AOwner: TComponent); override;
    destructor Destroy; override;

  published
    property TabFont: TFont read FTabFont write SetTabFont;
  end;


  TForm1 = class(TForm)
    PageControl1: TPageControl;
    TabSheet1: TTabSheet;
    TabSheet2: TTabSheet;
    Label1: TLabel;
    FontDialog1: TFontDialog;
    FontDialog2: TFontDialog;
    Button1: TButton;
    Button2: TButton;
    Button3: TButton;
    FontDialog3: TFontDialog;
    procedure FormCreate(Sender: TObject);
    procedure Button1Click(Sender: TObject);
  private    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}


{ TPageControl }

type
  TControlAccess = class(TControl);

procedure TPageControl.CMFontChanged(var Message);
begin
  NotifyControls(CM_PARENTFONTCHANGED);
end;

constructor TPageControl.Create(AOwner: TComponent);
begin
  inherited;

  FTabFont := TFont.Create;
  FTabFont.OnChange := TabFontChanged;
  FTabFont.Assign(Font);
end;

destructor TPageControl.Destroy;
begin
  FreeAndNil(FTabFont);
  inherited;
end;

procedure TPageControl.SetTabFont(const Value: TFont);
begin
  FTabFont.Assign(Value);
end;

procedure TPageControl.TabFontChanged(Sender: TObject);
begin
  if HandleAllocated then
  begin
    Perform(WM_SETFONT, WPARAM(FTabFont.Handle), 0);
    Perform(WM_SIZE, 0, 0);
  end;
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
  if Sender = Button1 then
  begin
    if FontDialog1.Execute then
      PageControl1.TabFont := FontDialog1.Font;
  end else if Sender = Button2 then begin
    if FontDialog2.Execute then
      PageControl1.Font := FontDialog2.Font;
  end else begin
    if FontDialog3.Execute then
      Font := FontDialog3.Font;
  end;
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
  FontDialog1.Font := PageControl1.TabFont;
  FontDialog2.Font := PageControl1.Font;
  FontDialog3.Font := Font;
end;

end.
이이 [freepass]   2009-03-29 00:47 X
의도는 알겠지만...
단지 BOLD만 주려면 그냥 이게 더 간단하지 않을까요 ?
procedure TfrmMain.pgcProductDrawTab(Control: TCustomTabControl;
  TabIndex: Integer; const Rect: TRect; Active: Boolean);
begin
  with Control.Canvas do
  begin
    if Active then
    begin
      Font.Style := [fsBold];
      TextOut(Rect.Left+1, Rect.Top+1, (Control as TPageControl).Pages[TabIndex].Caption);
    end
    else
    begin
      Font.Style := Font.Style - [fsBold];
      TextOut(Rect.Left+1, Rect.Top+1, (Control as TPageControl).Pages[TabIndex].Caption);
    end;
  end;
end;
김태선 [cppbuilder]   2009-07-13 18:03 X
저는 간단히 그냥 Font 프로퍼티에 원하는 폰트를 지정하고

페이지 위에 Panel 같은 컨테이너 컴포넌트를 올리고 여기에 보통의 폰트를 지정하는 방법을 쓸때도 있습니다.

+ -

관련 글 리스트
266 TPageControl에서 탭부분만 폰트를 변경한다면... DrK 6043 2009/02/17
Google
Copyright © 1999-2015, borlandforum.com. All right reserved.