以下是引用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();
}
}
}