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

Borja Sánchez Zamorano borsanza@terra.es
Fri, 05 Mar 2004 16:01:39 +0100


--=-AVZyPJwbracBVSfZaC2J
Content-Type: text/plain; charset=ISO-8859-15
Content-Transfer-Encoding: quoted-printable

Hello Yao Heling, I do it for you:


using Gtk;

public class BasicForm : DrawingArea {
  Window win;
  Gdk.GC gc;
=09
  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);
  }
=09
  void OnDeleteEvent (object o, DeleteEventArgs args)
  {
    Application.Quit ();
  }

  void OnExposeEvent(object obj, ExposeEventArgs args)=20
  {
    Gdk.Drawable drawable =3D GdkWindow;
	=09
    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;
=09
      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:

> 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 S=E1nchez Zamorano <borsanza@terra.es>

--=-AVZyPJwbracBVSfZaC2J
Content-Type: text/html; charset=utf-8
Content-Transfer-Encoding: 7bit

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 TRANSITIONAL//EN">
<HTML>
<HEAD>
  <META HTTP-EQUIV="Content-Type" CONTENT="text/html; CHARSET=UTF-8">
  <META NAME="GENERATOR" CONTENT="GtkHTML/3.0.9">
</HEAD>
<BODY>
Hello Yao Heling, I do it for you:<BR>
<BR>
<BR>
using Gtk;<BR>
<BR>
public class BasicForm : DrawingArea {<BR>
&nbsp; Window win;<BR>
&nbsp; Gdk.GC gc;<BR>
	<BR>
&nbsp; public static void Main()<BR>
&nbsp; {<BR>
&nbsp;&nbsp;&nbsp; Application.Init ();<BR>
&nbsp;&nbsp;&nbsp; new BasicForm();<BR>
&nbsp;&nbsp;&nbsp; Application.Run ();<BR>
&nbsp; }<BR>
<BR>
&nbsp; public BasicForm()<BR>
&nbsp; {<BR>
&nbsp;&nbsp;&nbsp; win = new Window(&quot;Form&quot;);<BR>
&nbsp;&nbsp;&nbsp; win.Add(this);<BR>
&nbsp;&nbsp;&nbsp; win.ShowAll();<BR>
&nbsp;&nbsp;&nbsp; ExposeEvent += new ExposeEventHandler(OnExposeEvent);<BR>
&nbsp;&nbsp;&nbsp; win.DeleteEvent += new DeleteEventHandler (OnDeleteEvent);<BR>
&nbsp; }<BR>
	<BR>
&nbsp; void OnDeleteEvent (object o, DeleteEventArgs args)<BR>
&nbsp; {<BR>
&nbsp;&nbsp;&nbsp; Application.Quit ();<BR>
&nbsp; }<BR>
<BR>
&nbsp; void OnExposeEvent(object obj, ExposeEventArgs args) <BR>
&nbsp; {<BR>
&nbsp;&nbsp;&nbsp; Gdk.Drawable drawable = GdkWindow;<BR>
		<BR>
&nbsp;&nbsp;&nbsp; using (gc = new Gdk.GC (drawable)) {<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Gdk.Color black_color = new Gdk.Color(0, 0, 0);<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Gdk.Colormap colormap = Gdk.Colormap.System;<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; colormap.AllocColor (ref black_color, true, true);<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; gc.Foreground = black_color;<BR>
	<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Pango.Layout layout = new Pango.Layout(PangoContext);<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; layout.FontDescription = Pango.FontDescription.FromString(&quot;Arial 12&quot;);<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; layout.SetText(&quot;This is my string!&quot;);<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; drawable.DrawLayout(gc, 25, 25, layout);<BR>
&nbsp;&nbsp;&nbsp; }<BR>
&nbsp; }<BR>
}<BR>
<BR>
<BR>
Compile:<BR>
&nbsp; mcs -r:gdk-sharp -r:gtk-sharp -r:pango-sharp gtk-draw.cs<BR>
<BR>
<BR>
Jejeje, &#161;&#161;Gtk-sharp has double buffering!!<BR>
<BR>
&nbsp; BorSanZa<BR>
<BR>
<BR>
<BR>
El jue, 04-03-2004 a las 15:37, Yao Heling escribi&#243;:
<BLOCKQUOTE TYPE=CITE>
<PRE><FONT COLOR="#737373"><I>Hello all,

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? 

using System;
using System.Drawing;
using System.Windows.Forms;

public class BasicForm: Form
{
  public static void Main()
  {
    BasicForm f = new BasicForm();
    Application.Run(f);
  }
  protected override void OnPaint(PaintEventArgs e)
  {
    Graphics g = e.Graphics;
    g.DrawString(&quot;This is my string!&quot;, new Font(&quot;Arial&quot;,12),
			Brushes.Black, 25, 25);
    base.OnPaint(e);
  }
}

Basically, I'd like to access the Graphics so that I can use
System.Drawing stuff. 

I really appreciate any help/suggestions.


Joseph H. Yao

p.s: I'm not on the list, pls cc me when you reply. Thanks!

_______________________________________________
Gtk-sharp-list maillist  -  Gtk-sharp-list@lists.ximian.com</FONT>
<A HREF="http://lists.ximian.com/mailman/listinfo/gtk-sharp-list"><U>http://lists.ximian.com/mailman/listinfo/gtk-sharp-list</U></I></A></PRE>
</BLOCKQUOTE>
<PRE><TABLE CELLSPACING="0" CELLPADDING="0" WIDTH="100%">
<TR>
<TD>
-- <BR>
Borja S&#225;nchez Zamorano &lt;<A HREF="mailto:borsanza@terra.es"><U>borsanza@terra.es</U></A>&gt;
</TD>
</TR>
</TABLE>
</PRE>
</BODY>
</HTML>

--=-AVZyPJwbracBVSfZaC2J--