- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我想打印我添加到我的 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/
判断这2个相似的Uris实际上相同的标准方法是什么? var a = new Uri("http://sample.com/sample/"); var b = new Uri("http://sam
这个问题在这里已经有了答案: Why does "true" == true show false in JavaScript? (5 个答案) 关闭 5 年前。 可能我很困惑,但我无法理解这个愚蠢
我是一名优秀的程序员,十分优秀!