2012-03-07 38 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 
    } 

}