再学 GDI+文本输出文本样式

news/2024/7/6 1:26:37

代码文件:


unit Unit1;

interfaceuses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, CheckLst;

type
  TForm1 = class(TForm)
    CheckListBox1: TCheckListBox;
    procedure FormPaint(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure CheckListBox1Click(Sender: TObject);
  end;

var
  Form1: TForm1;

implementation{$R *.dfm}uses GDIPOBJ, GDIPAPI;

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 := 0to CheckListBox1.Items.Count - 1do
    if CheckListBox1.Checked[i] then
      fs := fs or fsArr[i];
  Repaint;
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
  CheckListBox1.Align := alLeft;
  CheckListBox1.Items.CommaText := 'FontStyleRegular,' +
                                   'FontStyleBold,' +
                                   'FontStyleItalic,' +
                                   'FontStyleBoldItalic,' +
                                   'FontStyleUnderline,' +
                                   'FontStyleStrikeout';
  CheckListBox1.Checked[0] := True;
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);
  g.DrawString('Delphi', -1, font, MakePoint(CheckListBox1.Width + 0.0, 0), sb);

  font.Free;
  sb.Free;
  g.Free;
end;

end.

窗体文件:


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
    Left = 8
    Top = 8
    Width = 113
    Height = 148
    ItemHeight = 13
    TabOrder = 0
    OnClick = CheckListBox1Click
  endend

文本样式的定义:


FontStyle = Integer;
const
  FontStyleRegular    = Integer(0); {普通文本}
  FontStyleBold       = Integer(1); {加粗文本}
  FontStyleItalic     = Integer(2); {倾斜文本}
  FontStyleBoldItalic = Integer(3); {加粗并倾斜文本}
  FontStyleUnderline  = Integer(4); {带下划线的文本}
  FontStyleStrikeout  = Integer(8); {中间有直线通过的文本}
Type
TFontStyle = FontStyle;

 

转载于:https://www.cnblogs.com/blogpro/p/11426655.html


http://www.niftyadmin.cn/n/3301285.html

相关文章

WordPress实现中英文数字之间自动加空格排版

通常来说中文与英文、中文和数字之间加上空格的排版会更加好看,但是如果让我们在编辑文章的时候人工添加,感觉非常繁琐和让人厌烦,所以今天龙笑天下就来跟大家介绍一下WordPress如何实现中英文数字之间自动加空格的排版技巧。(PS&…

[Elasticsearch] 控制相关度 (五) - function_score查询及field_value_factor,boost_mode,max_

本章翻译自Elasticsearch官方指南的Controlling Relevance一章。 function_score查询 function_score查询是处理分值计算过程的终极工具。它让你能够对所有匹配了主查询的每份文档调用一个函数来调整甚至是完全替换原来的_score。 实际上,你可以通过设置过滤器来将查…

Delphi利用Windows GDI实现文字倾斜

Delphi利用Windows GDI实现文字倾斜摘要 Delphi利用Windows GDI实现文字倾斜procedure TForm1.FormPaint(Sender: TObject);var FLogFont: tagLogFontW; hTempFont, hPrevFont: HFONT; //字体句柄 hTempDC: HDC; //设备描述表或图形设备句柄 TempString: string; //输出的文…

CodeForces 631 A.Interview(水~)

Description f(x,l,r)表示将x序列的第l个元素到第r个元素按位或后的结果&#xff0c;给出两个长度为n的序列&#xff0c;问f(a,l,r)f(b,l,r)的最大值&#xff0c;1<l<r<n Input 第一行一整数n表示序列长度&#xff0c;之后输入两个长度为n的序列a和b(0<ai,bi<…

Python学习笔记(一)——输入与输出

输出&#xff1a;——print() Python中的输出使用print()完成 >>> 在屏幕中输出Hello World >>> print(Hello World) Hello World使用print()函数输出多个字符串时要使用逗号隔开 >>> print(hello,everyone,this,is,GUN) hello everyone this is GU…

ElasticSearch中设置排序Java

有用的链接:http://stackoverflow.com/questions/12215380/sorting-on-several-fields-in-elasticsearch 有的时候,需要自己设定排序,java的一个接口如下: String time1 ConstValue.GetCurrentDate();SortBuilder sortBuilder SortBuilders.fieldSort("tfp_save_time&qu…

C++如何判断某一文件是否存在

函数名: access功 能: 确定文件的访问权限用 法: int access(const char *filename, int amode);程序例:#include <stdio.h>#include <io.h>int file_exists(char *filename);int main(void){printf("Does NOTEXIST.FIL exist: %s\n",file_exists("…

CodeForces 631 B.Print Check(水~)

Description 给出一个n*m的网格图&#xff0c;起初所有格子颜色都是0&#xff0c;之后k次操作&#xff0c;每次把某一行或某一列涂成某种颜色&#xff0c;要求输出操作完后所有格子的颜色 Input 第一行三个整数n,m,k分别表示网格图的规模和操作数&#xff0c;之后k行每行三个…