更改 MSChart 背景进行打印
我已输入代码来在打印时更改 MSCharting 区域颜色。
chart.ChartAreas[o].BackColor = System.Drawing.Color.White;
chart.Printing.PrintPreview();
我的问题是,在用户选择“打印”或“关闭”打印预览对话框后,或者单击对话框“X”后,如何处理颜色变回原始颜色。
事实上,如果我使用 PrintDialog,一旦打印完成或取消,如何将背景设置回正常状态?
I have put in code to change the MSCharting area colour when printing.
chart.ChartAreas[o].BackColor = System.Drawing.Color.White;
chart.Printing.PrintPreview();
My quesiton is, how can I handle the color to change back to its oringinal color, eitehr after user has selected Print, or Close form the printpreview dialog,, or if the click on the dialogs "X".
In fact if I use the PrintDialog instead, how could I set background back to normal once printing has been completed or canceled?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
有点晚了,但我希望它能帮助别人。
对于 MsChart 打印,我正在使用
PrintDocument
事件。BeginPrint
事件用于设置打印颜色,PrintPage
事件用于打印本身,EndPrint
事件用于在打印前设置颜色。示例代码:
little late but I hope it helps someone.
To MsChart print I'am using
PrintDocument
events.BeginPrint
event for setting colors for printing,PrintPage
event for print itself andEndPrint
event for setting colors back before print.Sample code:
不幸的是,没有简单的方法,因为 PrintPreview 不提供任何回调。
您可以制作仅用于打印的图表副本,并将默认图表区域替换为自定义区域(具有自定义背景)。
另一种方法是更改 BG 颜色,使用 PrintPaint 将图表打印到内存中的图像,恢复 BG 颜色并为刚刚渲染的图像手动显示打印对话框。
还有更多方法,例如挂钩新创建的窗口,但它们变得越来越复杂和肮脏。
祝你好运
Unfortunatly there is no easy way since PrintPreview doesnt provide any callbacks.
You can make a copy of the chart used solely for printing with the default chart area replaced by your custom area (with custom background).
Another way is to change the BG Color, print the chart to a in-memory image using PrintPaint, restore the BG Color and show a print dialog manually for the image you just rendered.
There are more ways like hooking the newly created window but they are getting more complex and more dirty.
Good luck