Forget from the garden where you see, in short, the code, temporarily put here, spare. ~~~
Create a class called AeroGlass.cs, with the following code:
[CSharp] View plaincopy
Using System;
Using System.Runtime.InteropServices;
Using System.Windows;
Using System.Windows.Interop;
Using System.Windows.Media;
[StructLayout (LayoutKind.Sequential)]
public struct MARGINS
{
Public MARGINS (Thickness t)
{
left = (int) t.left;
right = (int) t.right;
Top = (int) t.top;
Bottom = (int) t.bottom;
}
public int left;
public int right;
public int Top;
public int Bottom;
}
public class Glasshelper
{
[DllImport ("Dwmapi.dll", PreserveSig = False)]
static extern void DwmExtendFrameIntoClientArea (
IntPtr hWnd, ref MARGINS Pmarinset);
[DllImport ("Dwmapi.dll", PreserveSig = False)]
static extern bool DwmIsCompositionEnabled ();
public static bool Extendglassframe (window window, Thickness margin)
{
if (! DwmIsCompositionEnabled ())
return false;
INTPTR hwnd = new windowinterophelper (window). Handle;
if (hwnd = = IntPtr.Zero)
throw New InvalidOperationException (
"The window must be shown before extending glass.");
Set the background to transparent from both the WPF and Win32 perspectives
Window. Background = brushes.transparent;
Hwndsource.fromhwnd (HWND). Compositiontarget.backgroundcolor = colors.transparent;
MARGINS MARGINS = new MARGINS (margin);
DwmExtendFrameIntoClientArea (hwnd, ref margins);
return true;
}
}
Add this piece of code to the main form!
protected override void Onsourceinitialized (EventArgs e)
{
Base. Onsourceinitialized (e);
Glasshelper.extendglassframe (This, new Thickness (-1));
}
Copy to Google TranslateTranslation Results
Search
Copy
Go WPF several lines of code implement form frosted glass effect (Aero Glass)