另存为图像文件 [英] Saving as Image File
本文介绍了另存为图像文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个drawCircuit按钮,单击它可以在面板上绘制一个电路图.还有一个带有saveDialogbox的Save菜单.我想将此电路图保存为面板上的图像文件.在面板的绘画事件中.
请帮助我另存为图像文件.
I have a drawCircuit button,when click it,it draws a cicuit diagram on a panel.And I also have a Save menu with saveDialogbox.I want to save this circuitdiagram on the panel as an image file.The diagrm is drawn in the panel''s paint event.
Please help me to save as an image file.
推荐答案
在面板上绘制电路图时,您使用了PaintEventArgs
参数中传递的Graphics
对象. .
如果研究PrintDocument
类,您会看到OnPrintPage(System.Drawing.Printing.PrintPageEventArgs e)
方法还会在其PrintPageEventArgse
参数中传递一个Graphics
对象.因此,如果使用此Graphics对象执行相同的操作,则将绘制到打印机而不是面板上.
启用两者的最简单方法是将代码从绘制处理程序中提取到接受Graphics对象作为参数的新方法中.像
When you draw the circuit diagram on the Panel you used theGraphics
object passed in thePaintEventArgs
parameter.
If you research thePrintDocument
class you will see that theOnPrintPage(System.Drawing.Printing.PrintPageEventArgs e)
method also passes aGraphics
object in itsPrintPageEventArgse
parameter. Therefore if you perform the same operations using this Graphics object you will draw to the printer rather than the panel.
The easiest way to enable both is to extract the code from your paint handler into a new method that accepts a Graphics object as a prameter. Something like
private void DrawDiagram(Graphics gr)
{
.........................
// your drawing code here
.........................
}
以下是有关打印的几篇文章,可帮助您入门.
使用CSharp打印 [使用C#打印 [
Here are a couple of articles about printing to get you started.
Printing Using CSharp[^]
Printing in C#[^]
If those do not suit, there are plenty more on the internet.
这篇关于另存为图像文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文