/// <summary> /// Remove the corners of a window by replacing the background of these corners by transparency. /// </summary> /// <param name="handle"></param> /// <param name="windowImage"></param> /// <param name="redBGImage"></param> /// <param name="windowRect"></param> /// <returns></returns> private static Image RemoveCorners(IntPtr handle, Image windowImage, Bitmap redBGImage, Rectangle windowRect) { const int cornerSize = 5; if (windowRect.Width > cornerSize * 2 && windowRect.Height > cornerSize * 2) { FileSystem.AppendDebug("Clean transparent corners"); if (redBGImage == null) { using (Form form = new Form()) { form.FormBorderStyle = FormBorderStyle.None; form.ShowInTaskbar = false; form.BackColor = Color.Red; NativeMethods.ShowWindow(form.Handle, (int)NativeMethods.WindowShowStyle.ShowNormalNoActivate); NativeMethods.SetWindowPos(form.Handle, handle, windowRect.X, windowRect.Y, windowRect.Width, windowRect.Height, NativeMethods.SWP_NOACTIVATE); Application.DoEvents(); redBGImage = CaptureRectangle(windowRect) as Bitmap; } } return(GraphicsMgr.RemoveCorners(windowImage, redBGImage)); } return(null); }