TFont 의 Style 은 TFontStyles 라는 건데 열거형이다. [fsBold, fsItalic, fsUnderline, fsStrikeOut]

예를 들어 Label1 의 폰트에 스타일을 Bold, Italic 세팅을 하자면

 

Label1.Font.Style:=[fsBold, fsItalic]; 

 

요렇게 하면 된다.

 

이걸 만약에 체크박스를 4개 두고 각각을 체크할 때 마다 폰트에 적용해 줘야 할 경우를 위한 코드다.

 

// 폼의 private 변수로 체크박스 배열 설정 

private 

chkStyles: array [0..3] of TCheckBox; 

... 

...

// 미리 상수선언 

const 

BOLD=0

ITALIC=1

UNDERLINE=2

STRIKEOUT=3

... 

... 

// 체크박스 배열 초기화 

procedure TForm1.FormShow(Sender: TObject); 

begin 

chkStyles[BOLD]:=chkBold 

chkStyles[ITALIC]:=chkItalic; 

chkStyles[UNDERLINE]:=chkUnderline; 

chkStyles[STRIKEOUT]:=chkStrikeOut; 

end

... 

... 

... 

// 각 체크박스에 동일한 이벤트 핸들러를 건다. 바로 아래의 프로시져 

procedure TForm1.chkStyleClick(Sender: TObject); 

var i: Integer; 

begin 

// 각 체크박스의 Checked 를 검사해서 해당 폰트스타일을 더하거나 빼줌. 

for i:=BOLD to STRIKEOUT do begin 

if chkStyle[i].Checked then Label1.Font.Style:=Label1.Font.Style+[TFontStyle(i)]

else                        Label1.Font.Style:=Label1.Font.Style-[TFontStyle(i)]; 

end

end






Posted by bloodguy
,