因此,表单上有GMapControl。我想打印地图,这是代码
PrintDocument doc = new PrintDocument { DocumentName = "Map printing file" };
doc.PrintPage += DocOnPrintPage;
PrintDialog dialog = new PrintDialog { Document = doc };
DialogResult result = dialog.ShowDialog();
if (result == DialogResult.OK) doc.Print();
和
private void DocOnPrintPage(object sender, PrintPageEventArgs e)
{
var img = View.gmap.ToImage();
System.Drawing.Point loc = new System.Drawing.Point(0, 0);
e.Graphics.DrawImage(img, loc);
}
我正在使用ToImage()
method,但是它无法按我的意愿工作(就像PrintScreen,因为还有其他对象,例如光标,对话框等。)是否有任何解决方法来实现没有此对象的打印?
Gmap.Net.Core
和 Gmap.Net.WindowForms
版本是1.7.0.0,.Net Framework版本是4.0,我无法升级.Net Framework版本,因为某些客户端正在使用Windows XP。
通过使用临时图像解决了问题。
string path = Path.GetTempPath() + Path.GetRandomFileName() + @".png";
_tmpImage = View.gmap.ToImage();
if (_tmpImage == null) return;
_tmpImage.Save(path);
PrintDocument doc = new PrintDocument { DocumentName = "Map printing file" };
doc.PrintPage += DocOnPrintPage;
PrintDialog dialog = new PrintDialog { Document = doc };
DialogResult result = dialog.ShowDialog();
if (result == DialogResult.OK) doc.Print();
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句