Skip to content

Instantly share code, notes, and snippets.

@Daniel15
Created November 21, 2011 04:31
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Daniel15/1381620 to your computer and use it in GitHub Desktop.
Save Daniel15/1381620 to your computer and use it in GitHub Desktop.
Semi-transparent window in GTK# (Mono, C#)
using System;
using System.Reflection;
using System.Runtime.InteropServices;
using Cairo;
using Gtk;
public class GtkDimScreen
{
private DrawingArea drawingArea;
public static void Main ()
{
new GtkDimScreen();
}
public GtkDimScreen()
{
Application.Init ();
var window = new Gtk.Window ("Invisible sandwich");
// Turn off title bar
window.Decorated = false;
// Create Cairo drawing area
drawingArea = new DrawingArea();
drawingArea.ScreenChanged += OnScreenChanged;
drawingArea.ExposeEvent += OnExposeEvent;
// Add drawing area to window
var box = new HBox (true, 0);
box.Add (drawingArea);
window.Add (box);
window.ShowAll ();
window.Maximize();
Application.Run ();
}
protected void OnScreenChanged(object o, ScreenChangedArgs args)
{
// Use the RGBA colour map, so that alpha values work
drawingArea.Screen.DefaultColormap = drawingArea.Screen.RgbaColormap;
}
protected void OnExposeEvent(object o, ExposeEventArgs args)
{
using (Context ctx = Gdk.CairoHelper.Create(drawingArea.GdkWindow))
{
// Paint a semitransparent colour onto the background
ctx.SetSourceRGBA(0, 0, 0, 0.4);
ctx.Operator = Operator.Source;
ctx.Paint();
}
}
}
@yogendersolanki91
Copy link

can you telll me how to add widget in that transparent area

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment