[System.Runtime.InteropServices.DllImport("dwmapi.dll", PreserveSig = false)]
public static extern bool DwmIsCompositionEnabled();
[System.Runtime.InteropServices.DllImport("DwmApi.dll")]
public static extern int DwmExtendFrameIntoClientArea(
IntPtr hwnd,
ref MARGINS pMarInset);
Then we'll write the method that determines the usage of glass effect on our form. [System.Runtime.InteropServices.StructLayout(System.Runtime.InteropServices.LayoutKind.Sequential)]
public struct MARGINS
{
public int cxLeftWidth;
public int cxRightWidth;
public int cyTopHeight;
public int cybottomHeight;
};
After that we'll write a method
void glassform()
{
MARGINS margins = new MARGINS();
margins.cxLeftWidth = -1; //-1 means all the form
margins.cxRightWidth = -1;
margins.cyTopHeight = -1;
margins.cyBottomHeight = -1;
if (DwmIsCompositionEnabled() == true)
{
IntPtr hWnd = this.Handle;
int result = DwmExtendFrameIntoClientArea(hWnd, ref margins);
}
else
{
this.BackColor = System.Drawing.Color.White;
}
}
And last we’ll call the glassform method from form_load
here’s the result
does not works for me
ReplyDeleteThis code, just remove the border from the inside of form!
ReplyDeleteWell done
ReplyDeletethis doesn't "just remove the border from the inside of form!"
its glass extension
not working for me either
ReplyDeleteDwmExtendFrameIntoClientArea render black as glass so you should set form back color to black
Delete