首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在Monomac中打印

在Monomac中打印
EN

Stack Overflow用户
提问于 2012-11-17 21:15:05
回答 1查看 225关注 0票数 0

如何在monomac中打印?这就是我所能得到的,但是我似乎不能在NSView中获得对图形上下文的引用。如果我将一个控件添加到PrintDoc中,这很好,但我想要绘制。

代码语言:javascript
复制
//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
    }
}
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2012-11-18 01:54:21

我已经设法通过手动获取上下文,而不是使用NSGraphicsContext.CurrentContext来让它工作:

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

代码片段:

代码语言:javascript
复制
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
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/13430923

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档