| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 3055 人关注过本帖
标题:C# 直接打印字体为粗体怪问题
只看楼主 加入收藏
pmaojie
Rank: 2
等 级:论坛游民
帖 子:8
专家分:10
注 册:2009-11-12
结帖率:50%
收藏
已结贴  问题点数:20 回复次数:9 
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
baikil
Rank: 10Rank: 10Rank: 10
来 自:X星球
等 级:青峰侠
威 望:4
帖 子:282
专家分:1580
注 册:2009-7-20
收藏
得分:15 
从这里看没有什么异常啊,能否发上代码,可以帮你调试.

自创QQ群64885635,方便C#学习交流.希望各项工作路好学都好入!
2010-01-16 10:08
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
baikil
Rank: 10Rank: 10Rank: 10
来 自:X星球
等 级:青峰侠
威 望:4
帖 子:282
专家分:1580
注 册:2009-7-20
收藏
得分:0 
没有出现你说的那个异常,是常发生吗?
testPoint.rar (45.42 KB)

自创QQ群64885635,方便C#学习交流.希望各项工作路好学都好入!
2010-01-16 14:11
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
baikil
Rank: 10Rank: 10Rank: 10
来 自:X星球
等 级:青峰侠
威 望:4
帖 子:282
专家分:1580
注 册:2009-7-20
收藏
得分:0 
可能是你的系统有问题,
能否对你的操作系统修复.

自创QQ群64885635,方便C#学习交流.希望各项工作路好学都好入!
2010-01-16 17:07
qingzhu5753
Rank: 4
等 级:业余侠客
帖 子:64
专家分:248
注 册:2009-10-28
收藏
得分:5 
using System;
using System.Collections.Generic;
using
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

public class Form1 : Form
{
    public static void Main()
    {
        Application.Run(new Form1());
    }
    private System.Drawing.Printing.PrintDocument printdoc;
    public Form1()
    {
        Button button1=new Button();
        Button button2=new Button();
        button1.Location = new System.Drawing.Point(0, 0);
        button2.Location = new System.Drawing.Point(0, 100);
        this.Controls.Add(button1);
        this.Controls.Add(button2);
        button1.Name="button1";
        button1.Text = "button1";
        button1.UseVisualStyleBackColor = true;
        button1.Size = new System.Drawing.Size(200, 50);
        button2.Name="button2";
        button2.Text = "button2";
        button2.UseVisualStyleBackColor = true;
        button2.Size = new System.Drawing.Size(200, 50);
        button1.Click+=new EventHandler(this.button1_Click);
        button2.Click+=new EventHandler(this.button2_Click);
    }
   
    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 17:28
pmaojie
Rank: 2
等 级:论坛游民
帖 子:8
专家分:10
注 册:2009-11-12
收藏
得分:0 
谢谢各位了,可能和系统有点关系,我让别人测试好像都没问题..
图片附件: 游客没有浏览图片的权限,请 登录注册
2010-01-16 22:14
jasony2009
Rank: 1
等 级:新手上路
帖 子:3
专家分:0
注 册:2010-2-1
收藏
得分:0 
打印机的问题
2010-02-06 16:43
快速回复:C# 直接打印字体为粗体怪问题
数据加载中...
 
   



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

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