简体   繁体   English

在Windows上使用MonoDevelop中的Cairo绘图

[英]Drawing with Cairo in MonoDevelop on Windows

I install MonoDevelop, GTK# and stuff. 我安装了MonoDevelop,GTK#和东西。 I open some Cairo tutorials (following the advice given here ). 我打开一些开罗教程(遵循这里给出的建议)。 I create a new GTK# project in MonoDevelop and add the Cairo library to the references. 我在MonoDevelop中创建了一个新的GTK#项目,并将Cairo库添加到引用中。 Using this tutorial , I create an expose event for a DrawingArea in a simple GTK form. 使用本教程 ,我以简单的GTK形式为DrawingArea创建一个公开事件。 Code is the following: 代码如下:

protected void OnDrawingAreaExposed (object obj, Gtk.ExposeEventArgs args)
{
    DrawingArea drawArea = (DrawingArea)obj;
    Cairo.Context ctx = Gdk.CairoHelper.Create(drawArea.GdkWindow);

    PointD p1,p2,p3,p4;

    p1 = new PointD (10,10);
    p2 = new PointD(100,100);

    ctx.MoveTo(p1);
    ctx.LineTo(p2);

    ((IDisposable)ctx).Dispose();
}

Whe running the app, nothing is drawn. 在运行应用程序时,没有任何内容。 Ok, I assume that cairo lib is not installed in system. 好吧,我认为cairo lib没有安装在系统中。 I download it from GTK+ page , put in to folder, where project executable lies - and BANG! 我从GTK +页面下载它,放入文件夹,项目可执行文件所在 - 并且砰! - app crashes (System.DllNotFoundException). - 应用程序崩溃(System.DllNotFoundException)。 In result of all of the above I have a question - is it possible for one to use Cairo in Mono apps on Winows? 由于以上所有结果,我有一个问题 - 是否有可能在Winows上的Mono应用程序中使用Cairo?

PS Will add error window screenshot later, if it's of any help. PS稍后会添加错误窗口截图,如果有任何帮助的话。

I think you're missing some steps. 我想你错过了一些步骤。

Try to add this between ctx.LineTo(p2); 尝试在ctx.LineTo(p2);之间添加ctx.LineTo(p2); and ((IDisposable)ctx).Dispose(); ((IDisposable)ctx).Dispose(); :

// give a color to line (red in this case)
ctx.Color = new Color (1,0,0);
// this is line type
ctx.Stroke ();

((IDisposable) ctx.Target).Dispose ();                                      

You shouldn't try to copy that compiled cairo libraries into the bin folder. 您不应该尝试将已编译的cairo库复制到bin文件夹中。 Mono (or MonoDevelop - not sure of this part) is shipped with the libs needed. 单声道(或MonoDevelop - 不确定此部分)是否附带所需的库。 You just add them via clicking on References folder and then Edit References (similar to that of Visual Studio). 您只需通过单击References文件夹然后单击Edit References (类似于Visual Studio)来添加它们。

Problem is in the GTK UI editor of MonoDevelop. 问题出在MonoDevelop的GTK UI编辑器中。 There is no option to add a custom widget there, though I believe this to be a common task. 没有选项可以在那里添加自定义小部件,但我相信这是一项常见任务。 If you want to do so, you will have to hack on file, generated by that editor (file, named as your window class, in gtk-gui folder). 如果你想这样做,你将不得不破解由该编辑器生成的文件(文件,命名为你的窗口类,在gtk-gui文件夹中)。 Say, if you have a CairoCanvas class, which inherits the Gtk.DrawingArea widget class - you just find the line, like this.drawingarea1 = new global::Gtk.DrawingArea() and change it to this.drawingarea1 = new CairoCanvas() , not forgetting to add a using YourProjectName; 比方说,如果你有一个CairoCanvas类,它继承了Gtk.DrawingArea小部件类 - 你只需要找到一行,如this.drawingarea1 = new global::Gtk.DrawingArea()并将其更改为this.drawingarea1 = new CairoCanvas() ,不要忘记添加using YourProjectName; directive upwards, of course. 当然,指令向上。 Every time you change something in your GUI, file will be regenerated. 每次在GUI中更改某些内容时,都会重新生成文件。 So then you go to that file, see that waring that it's changed, press the "Keep changes" button to preserve your work. 那么你去那个文件,看到它已经改变了,按下“保持更改”按钮来保存你的工作。 Then rebuild your project once more, and that's it. 然后再次重建您的项目,就是这样。

I gladly hope this answer will help some Mono newcomers. 我很高兴地希望这个答案能够帮助一些Mono新人。 And I hope to celebrate the day, when MonoDevelop community (it's OSS, isn't it?) will implement that lacking functionality. 我希望庆祝这一天,当MonoDevelop社区(它的OSS,不是吗?)将实现缺乏功能。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM