Skip to content

Instantly share code, notes, and snippets.

@NepNet
Last active September 26, 2016 18:22
Show Gist options
  • Save NepNet/16f338a67a1dc77bc65eed2387fd540d to your computer and use it in GitHub Desktop.
Save NepNet/16f338a67a1dc77bc65eed2387fd540d to your computer and use it in GitHub Desktop.
Gtk# 3 semi-transparent window
using System;
using Gtk;
using Cairo;
namespace TransTest
{
class MainClass
{
public static void Main (string[] args)
{
Application.Init ();
new TransparentWindow ();
Application.Run ();
}
}
class TransparentWindow : Gtk.Window
{
Box box1 = new Box (Orientation.Vertical, 0);
double alpha = 0.5;
Scale SC = new Scale (Orientation.Horizontal, 0, 1, 0.05);
public TransparentWindow () : base(Gtk.WindowType.Toplevel)
{
// This allows to pain directly on window
this.AppPaintable = true;
// This makes window transparent
this.Visual = Gdk.Screen.Default.RgbaVisual;
this.SetSizeRequest (200, 200);
this.Add (box1);
SC.Value = alpha;
SC.ChangeValue += delegate {
alpha = SC.Value;
QueueDraw ();
};
box1.Add (SC);
box1.Add (new Label("Test Label"));
ShowAll ();
}
protected override bool OnDrawn (Context cr)
{
cr.SetSourceRGB (0, 0, 0);
cr.PaintWithAlpha (alpha);
return base.OnDrawn (cr);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment