private static void DrawFrameControl(Graphics graphics, int x, int y, int width, int height, WinApi.DrawFrameControlTypes kind, WinApi.DrawFrameControlStates state, Color foreColor, Color backColor) { WinApi.RECT rcFrame = WinApi.RECT.FromXYWH(0, 0, width, height); using (Bitmap bitmap = new Bitmap(width, height)) { using (Graphics g2 = Graphics.FromImage(bitmap)) { g2.Clear(Color.Transparent); /* using( WindowsGraphics wg = WindowsGraphics.FromGraphics(g2) ){ * DrawFrameControl(new HandleRef(wg, wg.DeviceContext.Hdc), ref rcFrame, kind, (int) state); */ IntPtr dc = g2.GetHdc(); try { WinApi.DrawFrameControl(new HandleRef(null, dc), ref rcFrame, kind, state); } finally { g2.ReleaseHdc(); } if (foreColor == Color.Empty || backColor == Color.Empty) { graphics.DrawImage(bitmap, x, y); } else { // Replace black/white with foreColor/backColor. ImageAttributes attrs = new ImageAttributes(); ColorMap cm1 = new ColorMap(); cm1.OldColor = Color.Black; cm1.NewColor = foreColor; ColorMap cm2 = new ColorMap(); cm2.OldColor = Color.White; cm2.NewColor = backColor; attrs.SetRemapTable(new ColorMap[2] { cm1, cm2 }, ColorAdjustType.Bitmap); graphics.DrawImage(bitmap, new Rectangle(x, y, width, height), 0, 0, width, height, GraphicsUnit.Pixel, attrs, null, IntPtr.Zero); } } } }
public static void DrawFrameControl(Graphics graphics, Rectangle rect, WinApi.DrawFrameControlTypes kind, WinApi.DrawFrameControlStates state, Color foreColor, Color backColor) { DrawFrameControl(graphics, rect.X, rect.Y, rect.Width, rect.Height, kind, state, foreColor, backColor); }