gpt4 book ai didi

c# - 在 Winform 或其等同物中访问 PrintPageEventArgs.PageVisual

转载 作者:行者123 更新时间:2023-11-30 17:04:23 26 4
gpt4 key购买 nike

我想打印我添加到我的 Winform 应用程序中的 WPF 控件(MapControl)的可视内容。

(基本上,用任何控件编译一个 WPF 用户控件,然后将生成的控件像任何其他控件一样添加到您的 Winform 项目中。)

另一个用户基本上给出了一些代码来完成打印部分。看: http://www.devexpress.com/Support/Center/Question/Details/Q386207

我可以在 Winform 端收集到的代码应该是:

private PrintDocument m_oPrintDoc;
public frmWhatever()
: base()
{
// This call is required by the Windows Form Designer.
InitializeComponent();

// Set up the printing
m_oPrintDoc = new PrintDocument();
m_oPrintDoc.PrintPage += PrintDoc_PrintPage;
}

void PrintDoc_PrintPage(object sender, PrintPageEventArgs e)
{
e.PageVisual = MapContainer;
}

问题是PageVisual在Winform端不存在。在 WPF 中显然是这样。

等效代码是什么?我对“MapContainer”部分没有问题。唯一缺少的成分是“e.what”方法?

如果我添加引用/使用对,PageVisual 是否可能存在?

在任何人要求我联系 DevExpress 之前,我已经尝试过了。他们的回答是这个问题与他们没有任何关系,是一个纯粹的 Microsoft.Net 问题,因此在这里提出问题。

哦,是的,我正在使用 Visual Studio 2012 和 .Net 4.5。

最佳答案

您正在使用 GDI 在 WinForms 中进行打印。

您的代码应该如下所示(未经测试):

void PrintDoc_PrintPage(object sender, PrintPageEventArgs e)
{
var bmp = new Bitmap(e.MarginBounds);
MapContainer.DrawToBitmap(bmp, e.MarginBounds);
e.Graphics.DrawImage(bmp, new Point(0, 0));
}

当这显示某些内容时,您必须调整缩放比例。可以很好玩(不是),用 PrintPreviewDialog 省点纸。

关于c# - 在 Winform 或其等同物中访问 PrintPageEventArgs.PageVisual,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17499162/

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