[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>
Window win;<BR>
Gdk.GC gc;<BR>
<BR>
public static void Main()<BR>
{<BR>
Application.Init ();<BR>
new BasicForm();<BR>
Application.Run ();<BR>
}<BR>
<BR>
public BasicForm()<BR>
{<BR>
win = new Window("Form");<BR>
win.Add(this);<BR>
win.ShowAll();<BR>
ExposeEvent += new ExposeEventHandler(OnExposeEvent);<BR>
win.DeleteEvent += new DeleteEventHandler (OnDeleteEvent);<BR>
}<BR>
<BR>
void OnDeleteEvent (object o, DeleteEventArgs args)<BR>
{<BR>
Application.Quit ();<BR>
}<BR>
<BR>
void OnExposeEvent(object obj, ExposeEventArgs args) <BR>
{<BR>
Gdk.Drawable drawable = GdkWindow;<BR>
<BR>
using (gc = new Gdk.GC (drawable)) {<BR>
Gdk.Color black_color = new Gdk.Color(0, 0, 0);<BR>
Gdk.Colormap colormap = Gdk.Colormap.System;<BR>
colormap.AllocColor (ref black_color, true, true);<BR>
gc.Foreground = black_color;<BR>
<BR>
Pango.Layout layout = new Pango.Layout(PangoContext);<BR>
layout.FontDescription = Pango.FontDescription.FromString("Arial 12");<BR>
layout.SetText("This is my string!");<BR>
drawable.DrawLayout(gc, 25, 25, layout);<BR>
}<BR>
}<BR>
}<BR>
<BR>
<BR>
Compile:<BR>
mcs -r:gdk-sharp -r:gtk-sharp -r:pango-sharp gtk-draw.cs<BR>
<BR>
<BR>
Jejeje, ¡¡Gtk-sharp has double buffering!!<BR>
<BR>
BorSanZa<BR>
<BR>
<BR>
<BR>
El jue, 04-03-2004 a las 15:37, Yao Heling escribió:
<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("This is my string!", new Font("Arial",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ánchez Zamorano <<A HREF="mailto:borsanza@terra.es"><U>borsanza@terra.es</U></A>>
</TD>
</TR>
</TABLE>
</PRE>
</BODY>
</HTML>
--=-AVZyPJwbracBVSfZaC2J--