Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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

This comment has been minimized.

Copy link

commented Mar 12, 2014

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
You can’t perform that action at this time.