关于SetTextCharacterExtra 和ScaleTransform问题。

gezhaowan 2008-11-12 11:12:39
代码如下:
IntPtr hdc = g.GetHdc();
SetTextCharacterExtra(hdc, (int)WordSpacing);
g.ReleaseHdc(hdc);

g.ScaleTransform(this.TextFontHeightRatio, 1.0F);
g.DrawString(text, this.ifTextFont, brush, rc.Location.X , rc.Location.Y);

我想通过SetTextCharacterExtra 和ScaleTransform 方法 分别设置字符串得字间距 和缩放。
问题是目前俩个效果不能同时得到应用!? 只有未经过缩放得(或者说缩放比例是1,我只缩放X方向)应用SetTextCharacterExtra方法才生效。其他情况只有缩放生效。
请大家帮忙解决,不胜感激!
...全文
171 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
gezhaowan 2008-11-22
  • 打赏
  • 举报
回复
为什么!分不能给自己 好歹来个人领下分撒!
gezhaowan 2008-11-18
  • 打赏
  • 举报
回复
没人来哦
gezhaowan 2008-11-12
  • 打赏
  • 举报
回复
附带一个示例代码 方便大家研究了:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Runtime.InteropServices;


namespace PrintTemplate
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
SetStyle(ControlStyles.Opaque, true);
Bounds = new Rectangle(0, 0, 500, 300);
}

private void Form1_Load(object sender, EventArgs e)
{

}

[DllImport("gdi32.dll", CharSet = CharSet.Auto)]
public static extern int SetTextCharacterExtra(
IntPtr hdc, // handle to DC
int nCharExtra // extra-space value
);

protected override void OnPaint(PaintEventArgs e)
{
Graphics g = e.Graphics;
IntPtr hdc = g.GetHdc();
SetTextCharacterExtra(hdc, (int)this.numericUpDown1.Value);
g.ReleaseHdc(hdc);
int y = 20;

g.FillRectangle(Brushes.White, ClientRectangle);

Rectangle rect = new Rectangle(0, y, 400, Font.Height);
g.DrawRectangle(Pens.Blue,rect);
g.ScaleTransform((float)this.numericUpDown2.Value, 1.0F);
g.DrawString("这是设置字体间距实例!", Font, Brushes.Black, rect);
y += Font.Height + 20;


}

private void numericUpDown1_ValueChanged(object sender, EventArgs e)
{
this.Refresh();
}
}
}

111,119

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • AIGC Browser
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧