How do I draw a smooth blurred-glass effect on a border-less Form? I have tried the code listed on Image Processing for Dummies with C and GDI+ page but I\'m sure it\'s not what
Using Win API like DwmEnableBlurBehindWindow
[DllImport("gdi32")]
private static extern IntPtr CreateEllipticRgn(int nLeftRect, int nTopRect, int nRightRect, int nBottomRect);
[DllImport("dwmapi")]
private static extern int DwmEnableBlurBehindWindow(IntPtr hWnd, ref DwmBlurbehind pBlurBehind);
public struct DwmBlurbehind
{
public int DwFlags;
public bool FEnable;
public IntPtr HRgnBlur;
public bool FTransitionOnMaximized;
}
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
var hr = CreateEllipticRgn(0, 0, Width, Height);
var dbb = new DwmBlurbehind {FEnable = true, DwFlags = 1, HRgnBlur = hr, FTransitionOnMaximized = false};
DwmEnableBlurBehindWindow(Handle, ref dbb);
}
protected override void OnPaint(PaintEventArgs e)
{
e.Graphics.FillRectangle(new SolidBrush(Color.Black), new Rectangle(0, 0, Width, Height));
}
Example 1:
Example 2: You can change the brush color (ex: DarkRed) to get nice effects
Thing to note here is that you can pick a region where this applies and you can have more then 1.
You can use the same approach.
Wpf has much better support for shaders and you can add effect like blur, but thy are more performance heavy. Also your image is most likely from a program created by WPF and Blend.
If i remember correctly you can not use shaders like blur on solid color brush. Therefor following would not give the same effect. Set background 50% see through (Window properties AllowsTransparency="True" and WindowStyle="None")
Wpf support has been described here: http://www.paulrohde.com/native-glass-with-wpf/
I got following result with slightly different approach: