积极答复者
打印

问题
-
我想用WPF写一个类似于微软的打印窗口,实现微软打印窗口的功能。比如,在另一个窗体里有一个文本,点击打印,要跳出我的打印窗口。点击确定,会显示和微软打印窗口点击确定后一样的效果。
由于我是应届毕业生,对C#只能说是刚刚入门,之前也没写过类似的程序,所以我到论坛上去扒代码,
结果现在我遇到一些问题,我自己已经可以把打印窗口弹出了,但是我没办法像微软那样获得打印机的型号那些值!
页面设置我也像微软那样直接用dailog弹出,但我不知道我写的是否有效!
还有就是我知道打印范围和份数只要在程序中加几个if条件判断,但是我不知道该加在哪!
我希望我的打印窗口,可以打印类似于图片等等的,而不是光光打印文本。
希望各位大侠帮帮我!给我点思路,最好给我点相关的参考!!!
答案
-
当然可以自己写,你自己写好界面,然后实例化一个 PrintDialog,但不要ShowDialog()。
然后通过你自己的界面去设置 PrintDialog 的 PrintQueue 和 PrintTicket 等参数就可以了,最后了call PrintDocument() 或者 PrintVisual() 方法。一个简单的例子,看这个帖子:http://stackoverflow.com/questions/2995559/how-to-print-directly-without-print-dialog-in-wpf
还有,我要提醒的是,你不要把Winform的PrintDialog和WPF里面的混淆,因为我看你提到了 PrintDocument, 这个是Winform中System.Drawing.Printing名字空间的类,不是WPF的。
我个人认为,如果你只是初学的,不要一下做这么复杂的应用,你会很难把握。一点点来,否则空中楼阁只会造成大量bug和一堆问题。先从基础来看,理清各种技术逻辑关系。
Bob Bao [MSFT]
MSDN Community Support | Feedback to us
Get or Request Code Sample from Microsoft
Please remember to mark the replies as answers if they help and unmark them if they provide no help.
- 已建议为答案 Jie BaoModerator 2011年8月16日 9:27
- 已标记为答案 IT_民工 2011年8月17日 1:45
全部回复
-
PrintDialog 就可以, 参看这个 http://msdn.microsoft.com/zh-cn/library/ms742418.aspx 还有任何一本WPF书都有详细的关于打印功能的描述,
还有这个好好看看:http://www.codeproject.com/Articles/103184/How-to-Render-Bitmap-or-to-Print-a-Visual-in-WPF
Bob Bao [MSFT]
MSDN Community Support | Feedback to us
Get or Request Code Sample from Microsoft
Please remember to mark the replies as answers if they help and unmark them if they provide no help.
-
当然可以自己写,你自己写好界面,然后实例化一个 PrintDialog,但不要ShowDialog()。
然后通过你自己的界面去设置 PrintDialog 的 PrintQueue 和 PrintTicket 等参数就可以了,最后了call PrintDocument() 或者 PrintVisual() 方法。一个简单的例子,看这个帖子:http://stackoverflow.com/questions/2995559/how-to-print-directly-without-print-dialog-in-wpf
还有,我要提醒的是,你不要把Winform的PrintDialog和WPF里面的混淆,因为我看你提到了 PrintDocument, 这个是Winform中System.Drawing.Printing名字空间的类,不是WPF的。
我个人认为,如果你只是初学的,不要一下做这么复杂的应用,你会很难把握。一点点来,否则空中楼阁只会造成大量bug和一堆问题。先从基础来看,理清各种技术逻辑关系。
Bob Bao [MSFT]
MSDN Community Support | Feedback to us
Get or Request Code Sample from Microsoft
Please remember to mark the replies as answers if they help and unmark them if they provide no help.
- 已建议为答案 Jie BaoModerator 2011年8月16日 9:27
- 已标记为答案 IT_民工 2011年8月17日 1:45
-
WPF中的PrintDialog中,是通过PrintTicket来设置和页面相关的参数的:http://msdn.microsoft.com/zh-cn/library/system.windows.controls.printdialog.printticket.aspx 和 http://msdn.microsoft.com/zh-cn/library/system.printing.printticket.aspx
Bob Bao [MSFT]
MSDN Community Support | Feedback to us
Get or Request Code Sample from Microsoft
Please remember to mark the replies as answers if they help and unmark them if they provide no help.