2012-11-17 4 views
0

monomac에서 어떻게 인쇄합니까? 이것은 가능한 한 내 것이지만 NSView의 그래픽 컨텍스트에 대한 참조를 얻을 수없는 것 같습니다. 괜찮 았던 PrintDoc에 컨트롤을 추가했지만 그리려합니다.Monomac에서 인쇄

//Print Function 
void Print(){ 
    PrintDoc NewDoc = new PrintDoc(); 
    NewDoc.SetFrameSize(new SizeF(600,1000)); 
    NSPrintOperation P = NSPrintOperation.FromView (NewDoc); 
    P.RunOperation(); 
} 

//NSView to be printed 
class PrintDoc:NSView 
{ 
    public PrintDoc() 
    { 
    } 
    public override void DrawRect (System.Drawing.RectangleF dirtyRect) 
    { 
     //NSPrintOperation.CurrentOperation.Context !! this is null 
     //NSGraphicsContext.CurrentContext !! this hangs 
    } 
} 

답변

0

나는 NSGraphicsContext.CurrentContext을 수동으로 컨텍스트를 얻는 대신 사용하여 작업 얻을 관리했습니다 :

https://github.com/picoe/Eto/blob/feature/printing/Source/Eto.Platform.Mac/Forms/Printing/PrintDocumentHandler.cs#L39

발췌문 :

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

public override void DrawRect (System.Drawing.RectangleF dirtyRect) 
{ 
    var operation = NSPrintOperation.CurrentOperation; 

    var context = new NSGraphicsContext(Messaging.IntPtr_objc_msgSend (classNSGraphicsContext, selCurrentContext)); 
    // this causes monomac to hang for some reason: 
    //var context = NSGraphicsContext.CurrentContext; 
} 
+0

사랑 나누기를! 그게 효과가 있었는데, 당신이 그 해킹을 어떻게 내놓았는지 잘 모르겠다. –

관련 문제