/// <summary> /// Creates a logical cosmetic or geometric pen that has the specified style, width, and brush /// attributes. /// </summary> /// <param name="pen">The <see cref="T:System.Drawing.Pen"/> to convert.</param> /// <returns>If the function succeeds, the return value is a handle that identifies a logical pen; /// otherwise, the return value is <c>IntPtr.Zero</c>.</returns> public static IntPtr ExtCreatePen(Pen pen) { /* * Determine the pen style. */ uint penStyle = WinGdi.PS_GEOMETRIC | WinGdi.PS_ENDCAP_SQUARE | WinGdi.PS_JOIN_ROUND; switch (pen.DashStyle) { case DashStyle.Dash: penStyle |= WinGdi.PS_DASH; break; case DashStyle.DashDot: penStyle |= WinGdi.PS_DASHDOT; break; case DashStyle.DashDotDot: penStyle |= WinGdi.PS_DASHDOTDOT; break; case DashStyle.Dot: penStyle |= WinGdi.PS_DOT; break; default: penStyle |= WinGdi.PS_SOLID; break; } /* * Determine the pen width. */ uint penWidth = (uint)pen.Width; /* * Initialize LOGBRUSH. */ LOGBRUSH logBrush = new LOGBRUSH(); logBrush.lbStyle = WinGdi.BS_SOLID; logBrush.lbColor = ColorTranslator.ToWin32(pen.Color); /* * Call native method. */ return(Gdi32.ExtCreatePen(penStyle, penWidth, ref logBrush, 0, null)); }
/// <summary> /// Creates a logical pen from the specified <see cref="T:System.Drawing.Pen"/>. /// </summary> /// <param name="pen">The <see cref="T:System.Drawing.Pen"/> to convert.</param> /// <returns>If the function succeeds, the return value is a handle that identifies a logical pen. /// If the function fails, the return value is <c>IntPtr.Zero</c>.</returns> /// <exception cref="ArgumentNullException"><para><paramref name="pen"/> is <see langword="null"/>.</para></exception> public static IntPtr CreatePen(Pen pen) { if (pen == null) { throw new ArgumentNullException("pen"); } Int32 penStyle; switch (pen.DashStyle) { case DashStyle.Dash: penStyle = WinGdi.PS_DASH; break; case DashStyle.DashDot: penStyle = WinGdi.PS_DASHDOT; break; case DashStyle.DashDotDot: penStyle = WinGdi.PS_DASHDOTDOT; break; case DashStyle.Dot: penStyle = WinGdi.PS_DOT; break; default: penStyle = WinGdi.PS_SOLID; break; } Int32 width = (Int32)pen.Width; Int32 color = ColorTranslator.ToWin32(pen.Color); return(Gdi32.CreatePen(penStyle, width, color)); }
/// <summary> /// Sets the pixel at the specified coordinates to the closest approximation of the specified color. /// The point must be in the clipping region and the visible part of the device surface. /// </summary> /// <param name="hdc">Handle to the device context.</param> /// <param name="x">Specifies the x-coordinate, in logical units, of the point to be set.</param> /// <param name="y">Specifies the y-coordinate, in logical units, of the point to be set.</param> /// <param name="color">Specifies the color to be used to paint the point.</param> /// <returns>If the function succeeds, the return value is <see langword="true"/>; otherwise, <see langword="false"/>.</returns> public static Boolean SetPixelV(IntPtr hdc, Int32 x, Int32 y, Color color) { return(Gdi32.SetPixelV(hdc, x, y, ColorTranslator.ToWin32(color))); }
/// <summary> /// Sets the pixel at the specified coordinates to the specified color. /// </summary> /// <param name="hdc">Handle to the device context.</param> /// <param name="x">Specifies the x-coordinate, in logical units, of the point to be set.</param> /// <param name="y">Specifies the y-coordinate, in logical units, of the point to be set.</param> /// <param name="color">Specifies the color to be used to paint the point.</param> /// <returns>If the function succeeds, the return value is the <see cref="T:Color"/> that the function /// sets the pixel to. This value may differ from the color specified by color; that occurs when an /// exact match for the specified color cannot be found. If the function fails, the return value is -1.</returns> public static Color SetPixel(IntPtr hdc, Int32 x, Int32 y, Color color) { return(ColorTranslator.FromWin32(Gdi32.SetPixel(hdc, x, y, ColorTranslator.ToWin32(color)))); }
/// <summary> /// Sets the pixel at the specified coordinates to the closest approximation of the specified color. /// The point must be in the clipping region and the visible part of the device surface. /// </summary> /// <param name="hdc">Handle to the device context.</param> /// <param name="x">Specifies the x-coordinate, in logical units, of the point to be set.</param> /// <param name="y">Specifies the y-coordinate, in logical units, of the point to be set.</param> /// <param name="color">Specifies the color to be used to paint the point.</param> /// <returns>If the function succeeds, the return value is <see langword="true"/>; otherwise, <see langword="false"/>.</returns> public static bool SetPixelV(IntPtr hdc, int x, int y, Color color) { return(Gdi32.SetPixelV(hdc, x, y, ColorTranslator.ToWin32(color))); }
/// <summary> /// Fills a rectangle by using a brush of the specified color. This function includes the left and /// top borders, but excludes the right and bottom borders of the rectangle. /// </summary> /// <param name="hdc">Handle to the device context.</param> /// <param name="lprc">Pointer to a RECT structure that contains the logical coordinates of the rectangle to be filled.</param> /// <param name="crColor">Specifies the color to fill the rectangle with.</param> /// <returns></returns> public static Int32 FillSolidRect(IntPtr hdc, [In] ref RECT lprc, Color crColor) { return(FillRect(hdc, ref lprc, Gdi32.CreateSolidBrush(crColor))); }