2012-03-07 41 views

回答

1

我不知道的人,但来自苹果概念文档是相关的,其样本片断应该很容易地移植到C#:https://developer.apple.com/library/mac/#documentation/Cocoa/Conceptual/Printing/Printing.html

+0

是的,我已经通过很多不同的可可印刷文档阅读,并有覆盖印刷为几个Objective-C的OS X书籍好。目前的MonoMac缺少防止打印NSView的东西。 – djunod 2012-03-09 03:46:30

+0

什么东西不见了?我建议你提交bug ... – 2012-03-09 05:47:21

+0

请参阅NSView参考了解打印和分页方法。你在哪里为MonoMac提交错误? – djunod 2012-03-20 11:03:54

0

我创建了一个PrintDocument类有点像这样: (你需要设置一个合适的大小,并添加在drawRect中的一些图)

public class PrintDocument:NSView { 

    NSPrintOperation MyPrinter = null; 
    static IntPtr selCurrentContext = Selector.GetHandle ("currentContext"); 
    static IntPtr classNSGraphicsContext = Class.GetHandle ("NSGraphicsContext"); 

    public PrintDocument() 
    { 
     MyPrinter=NSPrintOperation.FromView(this); 
     this.SetFrameSize(new SizeF(600,800)); 
    } 

    public void Print() 
    { 
     MyPrinter.RunOperation() 
    } 
    public override void DrawRect (RectangleF dirtyRect) 
    { 
     var context = new NSGraphicsContext (Messaging.IntPtr_objc_msgSend (classNSGraphicsContext, selCurrentContext)); 
     //NSPrintOperation.CurrentOperation 
    } 

}