public static extern IntPtr ExtCreatePen( uint dwPenStyle, uint dwWidth, ref LOGBRUSH lplb, uint dwStyleCount, uint[] lpStyle );
/// <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> /// <exception cref="ArgumentNullException"><para><paramref name="pen"/> is <see langword="null"/>.</para></exception> public static IntPtr ExtCreatePen(Pen pen) { if (pen == null) { throw new ArgumentNullException("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 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> /// <exception cref="ArgumentNullException"><para><paramref name="pen"/> is <see langword="null"/>.</para></exception> public static IntPtr ExtCreatePen(Pen pen) { if (pen == null) { throw new ArgumentNullException("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); }