0

backbufferGraphics と呼ばれる BufferedGraphics があり、PrintDialog を使用してバッファリングされたコンテンツを印刷したいのですが、これは私のコードですが、うまくいきません:

private print()
{
        printDocument1.PrintPage += new System.Drawing.Printing.PrintPageEventHandler(printDocument1_PrintPage);
        printDialog1.Document = printDocument1;
        printDialog1.AllowSelection = true;
        printDialog1.AllowSomePages = true;
        printDialog1.ShowDialog();
}
void printDocument1_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e)
{
    DrawToPrint(e.Graphics);
}
private void DrawToPrint(Graphics _Gd)
{
    backbufferGraphics.Render(_Gd);
}

ありがとう!

4

1 に答える 1

1

最初にバッファグラフィックを画像に設定し、画像を印刷した後に設定する必要があります。

Bitmap bmp = new Bitmap();

int X = e.X - bmp.Width/2;
int Y = e.Y - bmp.Height/2;
// créer et initialiser le BufferedGraphics
BufferedGraphics bg =
BufferedGraphicsManager.Current.Allocate(this.CreateGraphics(),
ClientRectangle);
Graphics g = bg.Graphics;

g.Clear(SystemColors.Control);
g.DrawImage(bmp, new Point(X, Y));

bg.Render();
g.Dispose(); 
bg.Dispose();
//save bmp as file 
于 2012-08-16T04:50:33.120 に答える