我做了一個窗體,並在其中擴展了玻璃,如下圖所示。但是,當我移動窗口,使其不能在屏幕上全部顯示時,玻璃渲染在我將它移回後錯誤: 玻璃不是正確的
如何處理此問題,以便窗口呈現正確?
這是我的代碼:
[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);
}
}
如何知道如果它不可見? – Gabe
不確定你的意思......你是說如果你移動窗口越過屏幕邊緣再返回,那麼玻璃已經在窗口與屏幕邊緣相交的部分消失了? – series0ne
P.S.我過去曾多次使用過玻璃。在Google中搜索Daniel Moth和Glass ...他似乎是一位具有玻璃效果的古茹! – series0ne