[Mono-list] System.Graphics and GTK# applications
Francisco M. Marzoa
fmmarzoa at gmx.net
Mon Nov 15 14:38:08 EST 2010
I've found that if I create the Graphics.FromDrawable within the Expose
event function, it works as expected. I.e. move this code:
g = Gtk.DotNet.Graphics.FromDrawable (drawingarea1.GdkWindow);
>From MainWindow constructor to Redraw function (that's called on
ExposeEvent of drawing area).
Two misteries remain undisclosed for me anyway:
First is why the graphics instance must be recreated in each expose
event? and second, probably related with the first, is why when Graphics
instance is get just one time on MainWindow constructor I can see the
rectagle flickering from time to time while I change the window size...
Who knows... O_o
Anyway having it working is enough for now for me.
Thanks a lot everyone,
El 14/11/10 14:50, Francisco M. Marzoa escribió:
> Thanks for your help, Dimitar.
> This wants to work, but it didn't fully. It seem that I can draw an
> square on a DrawingArea, but it's erased just after drawing it. :-?
> Please, take a look at this code:
> using System;
> using Gtk;
> using Gtk.DotNet;
> using System.Drawing;
> public partial class MainWindow : Gtk.Window
> System.Drawing.Graphics g;
> public MainWindow () : base(Gtk.WindowType.Toplevel)
> Build ();
> g = Gtk.DotNet.Graphics.FromDrawable (drawingarea1.GdkWindow);
> protected void OnDeleteEvent (object sender, DeleteEventArgs a)
> Application.Quit ();
> a.RetVal = true;
> protected virtual void Redraw (object o, Gtk.ExposeEventArgs args)
> Pen p = new Pen (Color.Red);
> g.DrawRectangle (p, 10, 10, 100, 100);
> Is a GTK# solution I've created with Monodevelop: it has just a
> MainWindow, within which there's a VBox container with just one row,
> within which there's a DrawingArea named as default "drawingarea1".
> Also the Redraw method is connected to the Expose signal on
> drawingarea1, so it's redrawn everytime the MainWindow resizes (Miguel
> de Icaza told me to use that event for this task in a previous message.
> Thanks, Miguel).
> Now, when I run the application there's nothing drawn on the window, but
> if I drag a corner of the mainwindow resizing it continously, I can see
> from time to time a flickering red square within, that dissapears when I
> stop to drag the corner.
> So it seems like the rectangle where drawn, but it's "erased" just after
> Do you know where the problem may be??
> Thanks a million in advance,
> El 13/11/10 18:47, Dimitar Dobrev escribió:
>> Add a reference to gtkdotnet and use Graphics.FormDrawable, which returns a
>> Graphics object for drawing on the widget with the specified GdkWindow. This
>> works on Windows and Linux but not on Mac OS X. I'm looking for a way to use
>> it on the latter as well.
> Mono-list maillist - Mono-list at lists.ximian.com
More information about the Mono-list