/// <summary> /// Fills a round rect /// </summary> /// <param name="bounds">bound of the round rect</param> /// <param name="roundX">round on x</param> /// <param name="roundY">round on y</param> /// <param name="backColor">backColor</param> /// <param name="graphics">graphics object</param> public static void FillRoundRect(Rectangle bounds, int roundX, int roundY, Color backColor, Graphics graphics) { IntPtr hdc = graphics.GetHdc(); try { int argb = ColorToRGB(backColor); IntPtr hPen = CreatePen(W32PenStyle.Null, 1, 0); LogBrush brushData = new LogBrush(); brushData.lbColor = argb; brushData.lbStyle = W32BrushStyle.Solid; IntPtr hBrush = CreateBrushIndirect(ref brushData); IntPtr oldPen = SelectObject(hdc, hPen); IntPtr oldBrush = SelectObject(hdc, hBrush); RoundRect(hdc, bounds.X, bounds.Y, bounds.Right, bounds.Bottom, roundX, roundY); DeleteObject(SelectObject(hdc, oldPen)); DeleteObject(SelectObject(hdc, oldBrush)); } finally { graphics.ReleaseHdc(hdc); } }
/// <summary> /// Draws a round rect /// </summary> /// <param name="bounds">bound of the round rect</param> /// <param name="roundX">round on x</param> /// <param name="roundY">round on y</param> /// <param name="pen">pen object</param> /// <param name="graphics">graphics object</param> public static void DrawRoundRect(Rectangle bounds, int roundX, int roundY, Pen pen, Graphics graphics) { IntPtr hdc = graphics.GetHdc(); try { int argb = ColorToRGB(pen.Color); IntPtr hPen = CreatePen(GetPenStyle(pen.DashStyle), (int)pen.Width, argb); LogBrush brushData = new LogBrush(); brushData.lbColor = ColorToRGB(Color.Transparent); brushData.lbStyle = W32BrushStyle.Null; IntPtr hBrush = CreateBrushIndirect(ref brushData); IntPtr oldPen = SelectObject(hdc, hPen); IntPtr oldBrush = SelectObject(hdc, hBrush); RoundRect(hdc, bounds.X, bounds.Y, bounds.Right, bounds.Bottom, roundX, roundY); DeleteObject(SelectObject(hdc, oldPen)); DeleteObject(SelectObject(hdc, oldBrush)); } finally { graphics.ReleaseHdc(hdc); } }
private static extern IntPtr CreateBrushIndirect( ref LogBrush lplb // brush information );
/// <summary> /// The CreateBrushIndirect function creates a logical brush that has the specified style, color, and pattern /// </summary> /// <param name="plbrush">Pointer to a LOGBRUSH structure that contains information about the brush</param> /// <returns>If the function succeeds, the return value identifies a logical brush, else null</returns> /// <remarks>After an application creates a brush by calling CreateBrushIndirect, it can select it into any device context by calling the SelectObject function. /// </remarks> public static IntPtr CreateBrushIndirect([In] ref LogBrush plbrush) { return(Native.CreateBrushIndirect(ref plbrush)); }
public static extern IntPtr CreateBrushIndirect([In] ref LogBrush plbrush);
private static extern IntPtr CreateBrushIndirect( ref LogBrush lplb // 笔刷 信息 );