[Gtk-sharp-list] how to use System.Drawing with gtk-sharp

Borja Sanchez Zamorano borsanza@terra.es
Fri, 05 Mar 2004 16:11:37 +0100


Sorry, in text/plain... it's my first mail to the list.

Hello Yao Heling, I do it for you:


using Gtk;

public class BasicForm : DrawingArea {
  Window win;
  Gdk.GC gc;

  public static void Main()
  {
    Application.Init ();
    new BasicForm();
    Application.Run ();
  }

  public BasicForm()
  {
    win =3D new Window("Form");
    win.Add(this);
    win.ShowAll();
    ExposeEvent +=3D new ExposeEventHandler(OnExposeEvent);
    win.DeleteEvent +=3D new DeleteEventHandler (OnDeleteEvent);
  }

  void OnDeleteEvent (object o, DeleteEventArgs args)
  {
    Application.Quit ();
  }

  void OnExposeEvent(object obj, ExposeEventArgs args)=20
  {
    Gdk.Drawable drawable =3D GdkWindow;

    using (gc =3D new Gdk.GC (drawable)) {
      Gdk.Color black_color =3D new Gdk.Color(0, 0, 0);
      Gdk.Colormap colormap =3D Gdk.Colormap.System;
      colormap.AllocColor (ref black_color, true, true);
      gc.Foreground =3D black_color;

      Pango.Layout layout =3D new Pango.Layout(PangoContext);
      layout.FontDescription =3D Pango.FontDescription.FromString("Arial 12=
");
      layout.SetText("This is my string!");
      drawable.DrawLayout(gc, 25, 25, layout);
    }
  }
}


Compile:
  mcs -r:gdk-sharp -r:gtk-sharp -r:pango-sharp gtk-draw.cs


Jejeje, =A1=A1Gtk-sharp has double buffering!!

  BorSanZa



El jue, 04-03-2004 a las 15:37, Yao Heling escribi=F3:=20
> Hello all,
>=20
> I wonder whether it's possible to using System.Drawing with gtk-sharp
> and how as I'm interested to see a cross platform canvas. so here's the
> code with winform, could someone pls convert it to gtk-sharp?=20
>=20
> using System;
> using System.Drawing;
> using System.Windows.Forms;
>=20
> public class BasicForm: Form
> {
>   public static void Main()
>   {
>     BasicForm f =3D new BasicForm();
>     Application.Run(f);
>   }
>   protected override void OnPaint(PaintEventArgs e)
>   {
>     Graphics g =3D e.Graphics;
>     g.DrawString("This is my string!", new Font("Arial",12),
> 			Brushes.Black, 25, 25);
>     base.OnPaint(e);
>   }
> }
>=20
> Basically, I'd like to access the Graphics so that I can use
> System.Drawing stuff.=20
>=20
> I really appreciate any help/suggestions.
>=20
>=20
> Joseph H. Yao
>=20
> p.s: I'm not on the list, pls cc me when you reply. Thanks!
>=20
> _______________________________________________
> Gtk-sharp-list maillist  -  Gtk-sharp-list@lists.ximian.com
> http://lists.ximian.com/mailman/listinfo/gtk-sharp-list
--=20
Borja Sanchez Zamorano <borsanza@terra.es>