我制作了一个表格,并在其中扩展了玻璃,如下图所示。但是当我移动窗口以使其并非全部在屏幕上可见时,将其移回后玻璃渲染是错误的:
我该如何处理才能正确呈现窗口?
这是我的代码:
[DllImport( "dwmapi.dll" )]
private static extern void DwmExtendFrameIntoClientArea( IntPtr hWnd, ref Margins mg );
[DllImport( "dwmapi.dll" )]
private static extern void DwmIsCompositionEnabled( out bool enabled );
public struct Margins{
public int Left;
public int Right;
public int Top;
public int Bottom;
}
private void Form1_Shown( object sender, EventArgs e ) {
this.CreateGraphics().FillRectangle( new SolidBrush( Color.Black ), new Rectangle( 0, this.ClientSize.Height - 32, this.ClientSize.Width, 32 ) );
bool isGlassEnabled = false;
Margins margin;
margin.Top = 0;
margin.Left = 0;
margin.Bottom = 32;
margin.Right = 0;
DwmIsCompositionEnabled( out isGlassEnabled );
if (isGlassEnabled) {
DwmExtendFrameIntoClientArea( this.Handle, ref margin );
}
}