[Gtk-sharp-list] Gtk nonrectangular window

daniil00 fr.daniil at gmail.com
Thu May 22 15:13:32 EDT 2008


I figured out myself.  If anyone else wants to know:

public class WinUtil
{
               public static bool ModifyWindowShape( System.Drawing.Bitmap
bmp, Gtk.Window window )
		{
			bool ret = false;
			try
			{
				//save bitmap to stream
				System.IO.MemoryStream stream = new System.IO.MemoryStream();
				bmp.Save( stream, System.Drawing.Imaging.ImageFormat.Png );
				//verry important: put stream on position 0
				stream.Position     = 0;
				//get the pixmap mask
				Gdk.Pixbuf buf      = new Gdk.Pixbuf( stream, bmp.Width, bmp.Height );
				Gdk.Pixmap map1, map2;
				buf.RenderPixmapAndMask( out map1, out map2, 255 );
				//shape combine window 
				window.ShapeCombineMask( map2, 0, 0 );
				//dispose
				buf.Dispose();
				map1.Dispose();
				map2.Dispose();
				bmp.Dispose();
				//if evrything is ok return true;
				ret = true;
			}
			catch(Exception ex)
			{
				Console.WriteLine( ex.Message + "\r\n" + ex.StackTrace );
			}
			return ret;
		}
}

and in your window class add this:

    using System.Drawing;

    [...] // initialize  your form code here, and then:

    this.ShowAll();
    Bitmap bmp = new Bitmap( 640, 480 );
    Graphics g  = Graphics.FromImage( bmp );
    Brush b = new SolidBrush( Color.Red );
    g.FillEllipse( b, 0,0,bmp.Width,bmp.Height );
    g.Dispose();
    WinUtil.ModifyWindowShape( bmp, this );


daniil00 wrote:
> 
> Hy guys,
> 
> Can you provide me with a code sample in making a non rectangular window
> in gtk?  
> With winforms it was easy using the Region property, but I can't find
> something similar in gtk. 
> 
> 
> 

-- 
View this message in context: http://www.nabble.com/Gtk-nonrectangular-window-tp17335292p17411467.html
Sent from the Mono - Gtk# mailing list archive at Nabble.com.



More information about the Gtk-sharp-list mailing list