代码如下:
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方法才生效。其他情况只有缩放生效。
请大家帮忙解决,不胜感激!

解决方案 »

  1.   

    附带一个示例代码 方便大家研究了:
    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();
            }
        }
    }