/// <summary> /// Retrieves an image with the specified name from resources. /// </summary> /// <exception cref="T:System.ArgumentNullException"> /// <para> /// <paramref name="assemblyContainingImage"/> is <see langword="null"/>. /// </para> /// -or- /// <para> /// <paramref name="imageName"/> is <see langword="null"/>. /// </para> /// </exception> public static Bitmap GetImage(string assemblyContainingImage, string imageName) { if (assemblyContainingImage == null) { throw new ArgumentNullException("assemblyContainingImage"); } if (imageName == null) { throw new ArgumentNullException("imageName"); } Assembly[] assemblies = AppDomain.CurrentDomain.GetAssemblies(); foreach (Assembly a in assemblies) { string aName = a.GetName().Name; if (aName == assemblyContainingImage) { return(NuGenControlPaint.GetImage(a, imageName)); } } return(null); }
/// <summary> /// Retrieves an image with the specified name from resources. /// </summary> /// /// <exception cref="ArgumentNullException"> /// <para> /// <paramref name="assemblyContainingImage"/> is <see langword="null"/>. /// </para> /// -or- /// <para> /// <paramref name="imageName"/> is <see langword="null"/>. /// </para> /// </exception> public static Bitmap GetImage(Assembly assemblyContainingImage, string imageName) { if (assemblyContainingImage == null) { throw new ArgumentNullException("assemblyContainingImage"); } if (imageName == null) { throw new ArgumentNullException("imageName"); } try { Stream stream = assemblyContainingImage.GetManifestResourceStream(imageName); if (stream != null) { Bitmap bmp = new Bitmap(stream); NuGenControlPaint.MakeBackgroundTransparent(bmp); return(bmp); } } finally { } return(null); }
/* * GetHalfRoundRectangleGraphicsPath */ /// <summary> /// </summary> public static GraphicsPath GetHalfRoundRectangleGraphicsPath(Rectangle rectangleBounds, float radius) { /* * Verify input parameters. */ if (rectangleBounds.IsEmpty) { return(new GraphicsPath()); } if (radius <= 0) { throw new ArgumentException( Properties.Resources.Argument_NotPositiveRadius ); } float size = radius * 2f; GraphicsPath path = new GraphicsPath(); path.AddArc(rectangleBounds.X, rectangleBounds.Y, size, size, 180, 90); path.AddArc(rectangleBounds.X + rectangleBounds.Width - size, rectangleBounds.Y, size, size, 270, 90); path.AddLine( NuGenControlPaint.RectBRCorner(rectangleBounds), NuGenControlPaint.RectBLCorner(rectangleBounds) ); path.CloseFigure(); return(path); }
/* * StringFormatForAlignment */ /// <summary> /// Converts <see cref="T:System.Drawing.ContentAlignment"/> to <see cref="T:System.Drawing.StringFormat"/>. /// </summary> public static StringFormat ContentAlignmentToStringFormat(ContentAlignment alignmentToConvert) { StringFormat stringFormat = new StringFormat(); stringFormat.Alignment = NuGenControlPaint.TranslateAlignment(alignmentToConvert); stringFormat.LineAlignment = NuGenControlPaint.TranslateLineAlignment(alignmentToConvert); return(stringFormat); }
/* * SetStyle */ /// <summary> /// Sets the specified style for the specified <see cref="T:System.Windows.Forms.Control"/>. /// </summary> /// <param name="ctrl">Specifies the <see cref="T:System.Windows.Forms.Control"/> to set the style for.</param> /// <param name="ctrlStyles">Specifies the style to set.</param> /// <param name="value"><see langword="true"/> to set the style for the <see cref="T:System.Windows.Forms.Control"/>; /// otherwise, <see langword="false"/>.</param> /// <exception cref="T:System.ArgumentNullException"> /// <paramref name="ctrl"/> is <see langword="null"/>. /// </exception> public static void SetStyle(Control ctrl, ControlStyles ctrlStyles, bool value) { if (ctrl == null) { throw new ArgumentNullException("ctrl"); } NuGenControlPaint.InvokeSetStyle(ctrl, ctrlStyles, value); }
/* * GetImage */ /// <summary> /// Retrieves an image with the specified name from resources. /// </summary> /// <exception cref="ArgumentNullException"> /// <para> /// <paramref name="typeToSpecifyAssemblyContainingImage"/> is <see langword="null"/>. /// </para> /// -or- /// <para> /// <paramref name="imageName"/> is <see langword="null"/>. /// </para> /// </exception> public static Bitmap GetImage(Type typeToSpecifyAssemblyContainingImage, string imageName) { if (typeToSpecifyAssemblyContainingImage == null) { throw new ArgumentNullException("typeToSpecifyAssemblyContainingImage"); } if (imageName == null) { throw new ArgumentNullException("imageName"); } return(NuGenControlPaint.GetImage(typeToSpecifyAssemblyContainingImage.Module.Assembly, imageName)); }
/* * FillHalfRoundRectangle */ /// <summary> /// Fills a half-round rectangle on the specified graphics surface with the specified pen within the /// specified bounds and with the specified radius. /// </summary> /// <exception cref="ArgumentNullException"> /// <para><paramref name="g"/> is <see langword="null"/>.</para> /// -or- /// <para><paramref name="brush"/> is <see langword="null"/>.</para> /// </exception> public static void FillHalfRoundRectangle(Graphics g, Brush brush, Rectangle rectangleBounds, float radius) { if (g == null) { throw new ArgumentNullException("g"); } if (brush == null) { throw new ArgumentNullException("brush"); } using (GraphicsPath path = NuGenControlPaint.GetHalfRoundRectangleGraphicsPath(rectangleBounds, radius)) { g.FillPath(brush, path); } }
/* * DrawHalfRoundRectangle */ /// <summary> /// </summary> /// <exception cref="ArgumentNullException"> /// <para><paramref name="g"/> is <see langword="null"/>.</para> /// -or- /// <para><paramref name="pen"/> is <see langword="null"/>.</para> /// </exception> public static void DrawHalfRoundRectangle(Graphics g, Pen pen, Rectangle rectangleBounds, float radius) { if (g == null) { throw new ArgumentNullException("g"); } if (pen == null) { throw new ArgumentNullException("pen"); } using (GraphicsPath path = NuGenControlPaint.GetHalfRoundRectangleGraphicsPath(rectangleBounds, radius)) { g.DrawPath(pen, path); } }
/* * DrawRoundRectangle */ /// <summary> /// Draws a round rectangle on the specified graphics surface with the specified pen within the /// specified bounds and with the specified radius. /// </summary> /// <exception cref="ArgumentException"> /// <para> /// <paramref name="radius"/> should be positive. /// </para> /// </exception> /// <exception cref="ArgumentNullException"> /// <para><paramref name="g"/> is <see langword="null"/>.</para> /// -or- /// <para><paramref name="pen"/> is <see langword="null"/>.</para> /// </exception> public static void DrawRoundRectangle(Graphics g, Pen pen, Rectangle rectangleBounds, Single radius, NuGenRoundRectangleStyle style) { if (g == null) { throw new ArgumentNullException("g"); } if (pen == null) { throw new ArgumentNullException("pen"); } using (GraphicsPath path = NuGenControlPaint.GetRoundRectangleGraphicsPath(rectangleBounds, radius, style)) { g.DrawPath(pen, path); } }
/* * CreateStringFormat */ /// <summary> /// Builds <see cref="T:System.Drawing.StringFormat"/> for the specified <see cref="T:System.Windows.Forms.Control"/>. /// </summary> /// <param name="ctrl">Specifies the <see cref="T:System.Windows.Forms.Control"/> to build /// <see cref="T:System.Drawing.StringFormat"/> for.</param> /// <param name="textAlign">Specifies text alignment on the drawing surface.</param> /// <param name="showEllipsis">Specifies the value indicating whether to show ellipsis if the whole text /// cannot be displayed.</param> /// <param name="useMnemonic">Specifies the value indicating whether an ampersand (&) is included in the /// text.</param> /// <returns></returns> /// <exception cref="T:System.ArgumentNullException"><paramref name="ctrl"/> is <see langword="null"/>.</exception> public static StringFormat CreateStringFormat( Control ctrl, ContentAlignment textAlign, bool showEllipsis, bool useMnemonic ) { if (ctrl == null) { throw new ArgumentNullException("ctrl"); } StringFormat stringFormat = NuGenControlPaint.ContentAlignmentToStringFormat(textAlign); if (ctrl.RightToLeft == RightToLeft.Yes) { stringFormat.FormatFlags |= StringFormatFlags.DirectionRightToLeft; } if (showEllipsis) { stringFormat.Trimming = StringTrimming.EllipsisCharacter; stringFormat.FormatFlags |= StringFormatFlags.LineLimit; } if (!useMnemonic) { stringFormat.HotkeyPrefix = HotkeyPrefix.None; } else if (new NuGenInvoker(ctrl).Properties["ShowKeyboardCues"].GetValue <bool>()) { stringFormat.HotkeyPrefix = HotkeyPrefix.Show; } else { stringFormat.HotkeyPrefix = HotkeyPrefix.Hide; } if (ctrl.AutoSize) { stringFormat.FormatFlags |= StringFormatFlags.MeasureTrailingSpaces; } return(stringFormat); }
public static void DrawLine(Graphics g, Pen pen, Point pt1, Point pt2) { if (g == null) { throw new ArgumentNullException("g"); } if (pen == null) { throw new ArgumentNullException("pen"); } NuGenControlPaint.DrawLine( g, pen, pt1.X, pt1.Y, pt2.X, pt2.Y ); }
/// <summary> /// Gets a thumbnail for the specified image. /// </summary> /// /// <exception cref="T:System.ArgumentNullException"> /// <para> /// <paramref name="sourceImage"/> is <see langword="null"/>. /// </para> /// -or- /// <para> /// <paramref name="outputPath"/> is <see langword="null"/>. /// </para> /// -or- /// <para> /// <paramref name="outputPath"/> is an empty string. /// </para> /// </exception> public static void GetThumbnail(Image sourceImage, Size thumbnailSize, string outputPath) { if (sourceImage == null) { throw new ArgumentNullException("sourceImage"); } if (string.IsNullOrEmpty("outputPath")) { throw new ArgumentNullException("outputPath"); } EncoderParameters encoderParams = new EncoderParameters(1); ImageCodecInfo jpgCodecInfo = NuGenControlPaint.GetCodecInfo("image/jpeg"); encoderParams.Param[0] = new EncoderParameter(System.Drawing.Imaging.Encoder.Quality, 80L); using (Image img = NuGenControlPaint.GetThumbnail(sourceImage, thumbnailSize)) { img.Save(outputPath, jpgCodecInfo, encoderParams); } }
/// <summary> /// Draws the control. /// </summary> /// <param name="e">Provides data for the <c>System.Windows.Forms.Control.Paint</c> event.</param> protected override void OnPaint(PaintEventArgs e) { Graphics g = e.Graphics; string bufferString = ""; if (this.UseClearTypeTextRendering) { // High quality text drawing. g.TextRenderingHint = TextRenderingHint.ClearTypeGridFit; } // Define a tweaked rectangle for that the border was visible. Rectangle tweakedRectangle = new Rectangle( this.ClientRectangle.X, this.ClientRectangle.Y, this.ClientRectangle.Width - PEN_WIDTH, this.ClientRectangle.Height - PEN_WIDTH ); /* * Text */ StringFormat sf = new StringFormat(); sf.Alignment = this.TextAlignment; sf.LineAlignment = this.TextLineAlignment; if (this.WordWrap == false) { sf.FormatFlags = StringFormatFlags.NoWrap; } if (this.TextOrientation == NuGenOrientationStyle.Vertical) { sf.FormatFlags = StringFormatFlags.DirectionVertical; } if (this.AutoSize == false && this.WordWrap == false && this.EatLine == true) { Debug.Assert(this.StringProcessor != null, "this.StringProcessor != null"); bufferString = this.StringProcessor.EatLine( this.Text, this.Font, (this.TextOrientation == NuGenOrientationStyle.Vertical) ? tweakedRectangle.Height : tweakedRectangle.Width, g ); } else { bufferString = this.Text; } using (SolidBrush sb = new SolidBrush(this.ForeColor)) { g.DrawString(bufferString, this.Font, sb, tweakedRectangle, sf); } /* * Border */ NuGenControlPaint.DrawBorder(g, this.ClientRectangle, NuGenControlPaint.ColorFromArgb(this.ForegroundTransparency, this.BorderColor), this.BorderStyle); }