标题:C# 直接打印字体为粗体怪问题
取消只看楼主
pmaojie
Rank: 2
等 级:论坛游民
帖 子:8
专家分:10
注 册:2009-11-12
结帖率:50%
已结贴  问题点数:20 回复次数:4 
C# 直接打印字体为粗体怪问题
直接打印,设置字体为粗体为什么字跑到屏幕上去了,正常字体是可以的


  
程序代码:
   /// <summary>
        /// 打印
        /// </summary>
        public void Print()
        {
            this.printdoc = new System.Drawing.Printing.PrintDocument();
            this.printdoc.PrintPage += new System.Drawing.Printing.PrintPageEventHandler(printdoc_PrintPage);
            this.printdoc.Print();
        }

        /// <summary>
        /// 绘制图形
        /// </summary>
private void printdoc_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e)
{
Font printFont = new Font("宋体", 11,FontStyle.Bold);//这里设置粗体就不行
//e.Graphics.TextRenderingHint = System.Drawing.Text.TextRenderingHint.ClearTypeGridFit;
e.Graphics.DrawString(printText, printFont, printFontColor, GetRect(point, drawW, drawH), mStringFormat);
}


搜索更多相关主题的帖子: 字体 打印 
2010-01-16 00:09
pmaojie
Rank: 2
等 级:论坛游民
帖 子:8
专家分:10
注 册:2009-11-12
得分:0 
以下是引用baikil在2010-1-16 10:08:25的发言:

从这里看没有什么异常啊,能否发上代码,可以帮你调试.
非常感谢!

代码很简单,就是网上找的,不管是哪个只要是粗体就不行,我不知道是不是都这样的..

程序代码:
using System;
using System.Collections.Generic;
using  System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace WindowsFormsApplication1
{
    public partial class Form1 : Form
    {

        private System.Drawing.Printing.PrintDocument printdoc;
        public Form1()
        {
            InitializeComponent();
        }

        private void button2_Click(object sender, EventArgs e)
        {
            this.printdoc = new System.Drawing.Printing.PrintDocument();
            //PrintPage事件处理器追加
            printdoc.PrintPage += new System.Drawing.Printing.PrintPageEventHandler(this.printdoc_PrintPage);

            PrintPreviewDialog printPreviewDialog1 = new PrintPreviewDialog();
            printPreviewDialog1.Document = printdoc;
            printPreviewDialog1.FormBorderStyle = FormBorderStyle.Fixed3D;
            printPreviewDialog1.PrintPreviewControl.AutoZoom = false;
            printPreviewDialog1.PrintPreviewControl.Zoom = 1;
            printPreviewDialog1.ShowIcon = false;
            printPreviewDialog1.ShowDialog();
        }

        private void printdoc_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e)
        {
            StringFormat mStringFormat = new StringFormat();
            mStringFormat.Alignment = StringAlignment.Near;
            mStringFormat.LineAlignment = StringAlignment.Center;
            Font printFont = new Font("宋体", 11, FontStyle.Bold);//这里加上粗体就不行,正常字体是可以的.....
            SolidBrush printFontColor = new SolidBrush(System.Drawing.Color.Blue);//字体颜色

            //e.Graphics.TextRenderingHint = System.Drawing.Text.TextRenderingHint.ClearTypeGridFit;//加这句也是不行的....

            e.Graphics.DrawString("测试测试", printFont, printFontColor, new RectangleF(20, 0, 200, 30), mStringFormat);
            e.Graphics.DrawString("测试测试", printFont, printFontColor, new RectangleF(20, 40, 200, 30), mStringFormat);
            e.Graphics.DrawString("测试测试", printFont, printFontColor, new RectangleF(20, 80, 200, 30), mStringFormat);
            e.Graphics.DrawString("测试测试", printFont, printFontColor, new RectangleF(20, 120, 200, 30), mStringFormat);
            e.Graphics.DrawString("测试测试", printFont, printFontColor, new RectangleF(20, 140, 200, 30), mStringFormat);
            e.Graphics.DrawString("测试测试", printFont, printFontColor, new RectangleF(120, 140, 200, 30), mStringFormat);
            e.Graphics.DrawString("测试测试", printFont, printFontColor, new RectangleF(120, 140, 200, 30), mStringFormat);
            e.Graphics.DrawString("测试测试", printFont, printFontColor, new RectangleF(120, 140, 200, 30), mStringFormat); 
        }

        private void button1_Click(object sender, EventArgs e)
        {
            this.printdoc = new System.Drawing.Printing.PrintDocument();
            //PrintPage事件处理器追加
            printdoc.PrintPage += new System.Drawing.Printing.PrintPageEventHandler(this.printdoc_PrintPage);
            printdoc.Print();
        }
    }
}
2010-01-16 13:16
pmaojie
Rank: 2
等 级:论坛游民
帖 子:8
专家分:10
注 册:2009-11-12
得分:0 
难道还和机子有关系吗?版主可能帮我分析一下可能的原因?我下载你的还是一样的问题.
2010-01-16 15:07
pmaojie
Rank: 2
等 级:论坛游民
帖 子:8
专家分:10
注 册:2009-11-12
得分:0 
难道还和机子有关系吗?版主可能帮我分析一下可能的原因?我下载你的还是一样的问题.
2010-01-16 15:25
pmaojie
Rank: 2
等 级:论坛游民
帖 子:8
专家分:10
注 册:2009-11-12
得分:0 
谢谢各位了,可能和系统有点关系,我让别人测试好像都没问题..
2010-01-16 22:14



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-295836-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.201462 second(s), 9 queries.
Copyright©2004-2025, BCCN.NET, All Rights Reserved