gpt4 book ai didi

c# - 如何打印 GMap.NET map ?

转载 作者:行者123 更新时间:2023-11-30 20:48:24 24 4
gpt4 key购买 nike

所以窗体上有GMapControl。我想打印 map ,这是代码

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() 方法,但它没有按我想要的那样工作(它就像 PrintScreen,因为还有其他对象,如光标、对话框等)是否有任何解决方法在没有这个对象的情况下实现打印?

附言 Gmap.Net.CoreGmap.Net.WindowForms verison 是 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();

关于c# - 如何打印 GMap.NET map ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24712198/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com