首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
您现在的位置: 程式碼之家 >> 編程語言 >  >> 更多程式語言 >> Delphi

再學GDI+[39]: 文字樣式組合 - FontStyle 六種屬性任意組合預覽

     編輯:Delphi

前言

TGPFont 的 FontStyle 參數支援位元組合,六種基本樣式可任意疊加。本文提供 CheckListBox 即時勾選組合,展示「微軟雅黑」50pt 的複合樣式效果。

六大文字樣式位元定義

常數數值二進位效果
FontStyleRegular0000000普通(基準)
FontStyleBold1000001加粗
FontStyleItalic2000010傾斜
FontStyleBoldItalic3000011加粗+傾斜(預設組合)
FontStyleUnderline4000100下劃線
FontStyleStrikeout8001000刪除線

CheckListBox 位元組合實作

var fs: Integer;

procedure TForm1.CheckListBox1Click(Sender: TObject);
const
  fsArr: array[0..5] of Integer = (
    FontStyleRegular, FontStyleBold, FontStyleItalic,
    FontStyleBoldItalic, FontStyleUnderline, FontStyleStrikeout);
var i: Integer;
begin
  fs := 0;
  for i := 0 to CheckListBox1.Items.Count - 1 do
    if CheckListBox1.Checked[i] then
      fs := fs or fsArr[i];  {位元或運算組合}
  Repaint;
end;

procedure TForm1.FormPaint(Sender: TObject);
var g: TGPGraphics; sb: TGPSolidBrush; font: TGPFont;
begin
  g := TGPGraphics.Create(Canvas.Handle);
  sb := TGPSolidBrush.Create(aclRed);
  font := TGPFont.Create('微軟雅黑', 50, fs);  {fs 為組合後的樣式}
  g.DrawString('Delphi', -1, font, MakePoint(CheckListBox1.Width + 0.0, 0), sb);
  font.Free; sb.Free; g.Free;
end;

執行效果預覽

文字樣式組合效果

常見組合推薦

組合數值用途
Bold + Underline5標題強調
Italic + Underline6引用、書名
Bold + Strikeout9已完成任務、舊價格
Bold + Italic + Underline7超級強調
全開15測試/特效

表單定義檔

object Form1: TForm1
  Left = 0
  Top = 0
  Caption = 'Form1'
  ClientHeight = 98
  ClientWidth = 367
  Color = clBtnFace
  Font.Charset = DEFAULT_CHARSET
  Font.Color = clWindowText
  Font.Height = -11
  Font.Name = 'Tahoma'
  Font.Style = []
  OldCreateOrder = False
  Position = poDesktopCenter
  OnCreate = FormCreate
  OnPaint = FormPaint
  PixelsPerInch = 96
  TextHeight = 13
  object CheckListBox1: TCheckListBox ... {左側六項樣式}
end
  1. 上一篇文章:
  2. 下一篇文章:
Copyright © 程式碼之家 All Rights Reserved