/* * FillWithColorSamples */ /// <summary> /// </summary> /// <param name="colors"></param> /// <param name="imageListToFill"></param> /// <exception cref="ArgumentNullException"> /// <para><paramref name="colors"/> is <see langword="null"/>.</para> /// </exception> public void FillWithColorSamples(IList <Color> colors, out ImageList imageListToFill) { if (colors == null) { throw new ArgumentNullException("colors"); } imageListToFill = new ImageList(); imageListToFill.ImageSize = _sampleImageBounds.Size; foreach (Color color in colors) { Image sampleImage = new Bitmap(_sampleImageBounds.Width, _sampleImageBounds.Height); using (Graphics g = Graphics.FromImage(sampleImage)) { using (SolidBrush sb = new SolidBrush(color)) using (Pen pen = new Pen(Color.Black)) { g.FillRectangle(sb, _sampleImageBounds); g.DrawRectangle(pen, NuGenControlPaint.BorderRectangle(_sampleImageBounds)); } } imageListToFill.Images.Add(sampleImage); } }
/// <summary> /// </summary> /// <param name="paintParams"></param> public void DrawBorder(NuGenPaintParams paintParams) { base.DrawBorder( paintParams.Graphics , NuGenControlPaint.BorderRectangle(paintParams.Bounds) , paintParams.State ); }
/// <summary> /// </summary> /// <param name="paintParams"></param> /// <exception cref="ArgumentNullException"> /// <para> /// <paramref name="paintParams"/> is <see langword="null"/>. /// </para> /// </exception> public void DrawBorder(NuGenPaintParams paintParams) { if (paintParams == null) { throw new ArgumentNullException("paintParams"); } this.DrawBorder(paintParams.Graphics, NuGenControlPaint.BorderRectangle(paintParams.Bounds), paintParams.State); }
public void BorderRectangleTest() { Rectangle clientRectangle = new Rectangle(0, 0, 101, 101); Rectangle borderRectangle = NuGenControlPaint.BorderRectangle(clientRectangle); Assert.AreEqual(clientRectangle.Left, borderRectangle.Left); Assert.AreEqual(clientRectangle.Top, borderRectangle.Top); Assert.AreEqual(clientRectangle.Width - 1, borderRectangle.Width); Assert.AreEqual(clientRectangle.Height - 1, borderRectangle.Height); }
/// <summary> /// </summary> /// <param name="paintParams"></param> /// <exception cref="ArgumentNullException"> /// <para><paramref name="paintParams"/> is <see langword="null"/>.</para> /// </exception> public void DrawScrollTrack(NuGenPaintParams paintParams) { if (paintParams == null) { throw new ArgumentNullException("paintParams"); } Graphics g = paintParams.Graphics; Rectangle bounds = paintParams.Bounds; NuGenControlState state = paintParams.State; Color borderColor = this.ColorManager.GetBorderColor(NuGenControlState.Normal); Color bkgndColor; switch (state) { case NuGenControlState.Pressed: { bkgndColor = Color.FromArgb(130, borderColor); break; } case NuGenControlState.Hot: { bkgndColor = Color.FromArgb(90, borderColor); break; } default: { bkgndColor = Color.FromArgb(50, borderColor); break; } } using (SolidBrush sb = new SolidBrush(bkgndColor)) { g.FillRectangle(sb, bounds); } Rectangle borderRectangle = NuGenControlPaint.BorderRectangle(bounds); this.DrawLine( g, NuGenControlPaint.RectTLCorner(borderRectangle), NuGenControlPaint.RectTRCorner(borderRectangle), NuGenControlState.Normal ); this.DrawLine( g, NuGenControlPaint.RectBLCorner(borderRectangle), NuGenControlPaint.RectBRCorner(borderRectangle), NuGenControlState.Normal ); }
/* * GetFrameRectangle */ /// <summary> /// Returns the bounds for the group box frame. /// </summary> /// <param name="labelRectangle"></param> /// <param name="clientRectangle"></param> /// <returns></returns> protected virtual Rectangle GetFrameRectangle(Rectangle labelRectangle, Rectangle clientRectangle) { Rectangle borderRectangle = NuGenControlPaint.BorderRectangle(clientRectangle); return(new Rectangle( borderRectangle.Left, borderRectangle.Top + labelRectangle.Top + labelRectangle.Height / 2, borderRectangle.Width, borderRectangle.Height - labelRectangle.Top - labelRectangle.Height / 2 )); }
public void BorderRectangleCustomPenTest() { int penWidth = 2; Rectangle clientRectangle = new Rectangle(0, 0, 100 + penWidth, 100 + penWidth); Rectangle borderRectangle = NuGenControlPaint.BorderRectangle(clientRectangle, penWidth); Assert.AreEqual(clientRectangle.Left, borderRectangle.Left); Assert.AreEqual(clientRectangle.Top, borderRectangle.Top); Assert.AreEqual(clientRectangle.Width - penWidth, borderRectangle.Width); Assert.AreEqual(clientRectangle.Height - penWidth, borderRectangle.Height); }
/// <summary> /// </summary> /// <param name="paintParams"></param> /// <exception cref="ArgumentNullException"> /// <para><paramref name="paintParams"/> is <see langword="null"/>.</para> /// </exception> public void DrawTrackButton(NuGenTrackButtonPaintParams paintParams) { if (paintParams == null) { throw new ArgumentNullException("paintParams"); } Graphics g = paintParams.Graphics; Rectangle bounds = paintParams.Bounds; NuGenControlState state = paintParams.State; TickStyle tickStyle = paintParams.Style; Rectangle borderRectangle = NuGenControlPaint.BorderRectangle(bounds); using (NuGenGrfxMode mode = new NuGenGrfxMode(g)) { g.SmoothingMode = SmoothingMode.AntiAlias; using (GraphicsPath gp = NuGenSmoothTrackBarRenderer.GetGraphicsPath(borderRectangle, tickStyle)) { /* Background */ using ( Brush brush = this.GetBackgroundBrush( borderRectangle, state == NuGenControlState.Normal || state == NuGenControlState.Focused ? NuGenControlState.Hot : state ) ) { g.FillPath(brush, gp); } /* Body */ Rectangle bodyRectangle = Rectangle.Inflate(borderRectangle, 0, -3); using (GraphicsPath bgp = NuGenSmoothTrackBarRenderer.GetBodyGraphicsPath(borderRectangle, tickStyle)) using (Brush brush = this.GetBackgroundBrush(bodyRectangle, state)) { g.FillPath(brush, bgp); } /* Border */ using (Pen pen = this.GetBorderPen(state)) { g.DrawPath(pen, gp); } } } }
/// <summary> /// </summary> /// <exception cref="ArgumentNullException"> /// <para><paramref name="g"/> is <see langword="null"/>.</para> /// </exception> public static void DrawAdornments(Graphics g, Rectangle bounds) { if (g == null) { throw new ArgumentNullException("g"); } using (Pen pen = new Pen(SystemColors.ControlDarkDark)) { pen.DashStyle = DashStyle.Dash; g.DrawRectangle(pen, NuGenControlPaint.BorderRectangle(bounds)); } }
/* * OnPaintAdornments */ /// <summary> /// Receives a call when the control that the designer is managing has painted /// its surface so the designer can paint any additional adornments on top of /// the control. /// </summary> /// <param name="e">The <see cref="System.Windows.Forms.PaintEventArgs"/> instance containing the event data.</param> protected override void OnPaintAdornments(PaintEventArgs e) { if (_ctrlReflector != null) { Graphics g = e.Graphics; using (Pen pen = new Pen(SystemColors.ControlDarkDark)) { pen.DashStyle = DashStyle.Dash; e.Graphics.DrawRectangle(pen, NuGenControlPaint.BorderRectangle(_ctrlReflector.ClientRectangle)); } } }
/* * DrawTabBody */ /// <summary> /// </summary> /// <param name="paintParams"></param> /// <exception cref="ArgumentNullException"> /// <para> /// <paramref name="paintParams"/> is <see langword="null"/>. /// </para> /// </exception> public void DrawTabBody(NuGenTabBodyPaintParams paintParams) { if (paintParams == null) { throw new ArgumentNullException("paintParams"); } Graphics g = paintParams.Graphics; Rectangle bounds = paintParams.Bounds; this.DrawBackground(g, bounds, NuGenControlState.Normal); this.DrawBorder(g, NuGenControlPaint.BorderRectangle(bounds), NuGenControlState.Normal); }
/// <summary> /// </summary> /// <exception cref="ArgumentNullException"><paramref name="paintParams"/> is <see langword="null"/>.</exception> public void DrawSelectionFrame(NuGenPaintParams paintParams) { if (paintParams == null) { throw new ArgumentNullException("paintParams"); } Graphics g = paintParams.Graphics; Rectangle bounds = paintParams.Bounds; NuGenControlState state = paintParams.State; this.DrawBackground(paintParams); this.DrawBorder(g, NuGenControlPaint.BorderRectangle(bounds), state); }
/* * OnPaintAdornments */ /// <summary> /// </summary> /// <param name="e">The <see cref="System.Windows.Forms.PaintEventArgs"/> instance containing the event data.</param> protected override void OnPaintAdornments(PaintEventArgs e) { if (_pictureBox != null) { using (Pen pen = new Pen(SystemColors.ControlDarkDark)) { pen.DashStyle = DashStyle.Dash; e.Graphics.DrawRectangle( pen, NuGenControlPaint.BorderRectangle(new Rectangle(0, 0, _pictureBox.Width, _pictureBox.Height)) ); } } }
/// <summary> /// </summary> /// <exception cref="ArgumentNullException"><paramref name="paintParams"/> is <see langword="null"/>.</exception> public void DrawFisheyeExpander(NuGenPaintParams paintParams) { if (paintParams == null) { throw new ArgumentNullException("paintParams"); } Graphics g = paintParams.Graphics; Rectangle bounds = paintParams.Bounds; NuGenControlState state = paintParams.State; NuGenControlState expanderState = NuGenControlState.Normal; if (state == NuGenControlState.Hot) { using (SolidBrush sb = new SolidBrush(Color.FromArgb(30, this.ColorManager.GetBorderColor(expanderState)))) { g.FillRectangle(sb, bounds); } this.DrawBorder(g, bounds, expanderState); } else if (state == NuGenControlState.Normal) { this.DrawBorder(g, NuGenControlPaint.BorderRectangle(bounds), expanderState); } NuGenPaintParams arrowPaintParams = new NuGenPaintParams(paintParams); arrowPaintParams.State = expanderState; arrowPaintParams.Bounds = Rectangle.FromLTRB( bounds.Left , bounds.Bottom - 20 , bounds.Right , bounds.Bottom ); this.DrawScrollButtonBody(arrowPaintParams); arrowPaintParams.Bounds = Rectangle.FromLTRB( bounds.Left , bounds.Top , bounds.Right , bounds.Top + 30 ); g.RotateTransform(180); g.TranslateTransform(-(bounds.Width * 2 + bounds.Left + 3), -(24 + bounds.Y * 2)); this.DrawScrollButtonBody(arrowPaintParams); g.ResetTransform(); }
/// <summary> /// </summary> /// <param name="paintParams"></param> /// <exception cref="ArgumentNullException"><para><paramref name="paintParams"/> is <see langword="null"/>.</para></exception> public void DrawBorder(NuGenPaintParams paintParams) { if (paintParams == null) { throw new ArgumentNullException("paintParams"); } Graphics g = paintParams.Graphics; using (NuGenGrfxMode mode = new NuGenGrfxMode(g)) { g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias; this.DrawRoundBorder(g, NuGenControlPaint.BorderRectangle(paintParams.Bounds), paintParams.State); } }
/// <summary> /// </summary> /// <param name="paintParams"></param> /// <exception cref="ArgumentNullException"> /// <para><paramref name="paintParams"/> is <see langword="null"/>.</para> /// </exception> public void DrawNavigationPaneBorder(NuGenPaintParams paintParams) { if (paintParams == null) { throw new ArgumentNullException("paintParams"); } Graphics g = paintParams.Graphics; Rectangle bounds = NuGenControlPaint.BorderRectangle(paintParams.Bounds); NuGenControlState state = paintParams.State; Point topLeftCorner = NuGenControlPaint.RectTLCorner(bounds); Point bottomLeftCorner = NuGenControlPaint.RectBLCorner(bounds); Point topRightCorner = NuGenControlPaint.RectTRCorner(bounds); Point bottomRightCorner = NuGenControlPaint.RectBRCorner(bounds); this.DrawLine(g, topLeftCorner, bottomLeftCorner, state); this.DrawLine(g, topRightCorner, bottomRightCorner, state); }
private Image GetColorSample(Color color) { if (color == Color.Transparent) { color = Color.White; } Rectangle sampleRectangle = new Rectangle(0, 0, 28, Math.Max(6, this.ClientRectangle.Height - 6)); Image image = new Bitmap(sampleRectangle.Width, sampleRectangle.Height); using (Graphics g = Graphics.FromImage(image)) { using (SolidBrush sb = new SolidBrush(color)) using (Pen pen = new Pen(Color.Black)) { g.FillRectangle(sb, sampleRectangle); g.DrawRectangle(pen, NuGenControlPaint.BorderRectangle(sampleRectangle)); } } return(image); }
/// <summary> /// </summary> /// <exception cref="ArgumentNullException"> /// <para><paramref name="paintParams"/> is <see langword="null"/>.</para> /// </exception> public void DrawSizeBox(NuGenPaintParams paintParams) { if (paintParams == null) { throw new ArgumentNullException("paintParams"); } Graphics g = paintParams.Graphics; Rectangle bounds = paintParams.Bounds; NuGenControlState state = paintParams.State; this.DrawBackground(paintParams); this.DrawBorder(g, NuGenControlPaint.BorderRectangle(bounds), state); if (bounds.Width > 12) { int oneGripY = bounds.Top + bounds.Height / 2 - _gripLineHeight / 2; int twoGripY = bounds.Top + bounds.Height / 2 + _gripLineHeight / 2; int oneGripX = bounds.Left + bounds.Width / 2; int twoGripX = oneGripX - _gripLineOffset; int threeGripX = oneGripX + _gripLineOffset; Point p11 = new Point(oneGripX, oneGripY); Point p12 = new Point(oneGripX, twoGripY); Point p21 = new Point(twoGripX, oneGripY); Point p22 = new Point(twoGripX, twoGripY); Point p31 = new Point(threeGripX, oneGripY); Point p32 = new Point(threeGripX, twoGripY); this.DrawLine(g, p11, p12, state); this.DrawLine(g, p21, p22, state); this.DrawLine(g, p31, p32, state); } }
/* * DrawTabButton */ /// <summary> /// </summary> /// <param name="paintParams"></param> /// <exception cref="ArgumentNullException"> /// <para> /// <paramref name="paintParams"/> is <see langword="null"/>. /// </para> /// </exception> public void DrawTabButton(NuGenTabButtonPaintParams paintParams) { if (paintParams == null) { throw new ArgumentNullException("paintParams"); } Graphics g = paintParams.Graphics; Rectangle bounds = paintParams.Bounds; NuGenControlState currentState = NuGenControlState.Normal; /* Helps to draw background properly if the BackColor property is set to Color.Transparent. */ g.FillRectangle(SystemBrushes.Control, new Rectangle(0, 0, bounds.Width, 2)); switch (paintParams.State) { case TabItemState.Disabled: { currentState = NuGenControlState.Disabled; break; } case TabItemState.Hot: { currentState = NuGenControlState.Hot; break; } case TabItemState.Selected: { currentState = NuGenControlState.Pressed; break; } default: { currentState = NuGenControlState.Normal; break; } } Rectangle tweakedRectangle = NuGenControlPaint.BorderRectangle(bounds); using (NuGenGrfxMode mode = new NuGenGrfxMode(g)) { g.SmoothingMode = SmoothingMode.AntiAlias; DrawRoundBackground(g, tweakedRectangle, currentState, NuGenRoundRectangleStyle.TopRound); DrawRoundBorder(g, tweakedRectangle, currentState, NuGenRoundRectangleStyle.TopRound); } this.DrawText( g, paintParams.TextBounds, currentState, paintParams.Text, paintParams.Font, paintParams.ForeColor, System.Drawing.ContentAlignment.MiddleLeft ); if (paintParams.Image != null) { this.DrawImage( g, paintParams.ImageBounds, currentState, paintParams.Image ); } }
/// <summary> /// Raises the <see cref="E:System.Windows.Forms.Control.Paint"></see> event. /// </summary> /// <param name="e">A <see cref="T:System.Windows.Forms.PaintEventArgs"></see> that contains the event data.</param> protected override void OnPaint(PaintEventArgs e) { Graphics g = e.Graphics; Rectangle bounds = this.ClientRectangle; if (this.Orientation == NuGenOrientationStyle.Horizontal) { bounds.X++; bounds.Width -= 2; } else { bounds.Y++; bounds.Height -= 2; } Rectangle contentBounds = this.LayoutManager.GetContentRectangle(bounds); NuGenControlState currentState = this.ButtonStateTracker.GetControlState(); NuGenPaintParams paintParams = new NuGenPaintParams(e.Graphics); paintParams.Bounds = bounds; paintParams.State = currentState; if (currentState != NuGenControlState.Normal) { this.Renderer.DrawBackground(paintParams); NuGenPaintParams borderPaintParams = new NuGenPaintParams(paintParams); borderPaintParams.Bounds = NuGenControlPaint.BorderRectangle(borderPaintParams.Bounds); this.Renderer.DrawBorder(borderPaintParams); } Image image = this.Image; Rectangle imageBounds = Rectangle.Empty; ContentAlignment imageAlign = this.ImageAlign; if (image != null) { NuGenImagePaintParams imagePaintParams = new NuGenImagePaintParams(g); imagePaintParams.Bounds = imageBounds = this.LayoutManager.GetImageBounds( new NuGenBoundsParams(contentBounds , imageAlign , new Rectangle(Point.Empty, image.Size) , this.RightToLeft ) ); imagePaintParams.Image = image; imagePaintParams.State = currentState; this.Renderer.DrawImage(imagePaintParams); } if (imageBounds != Rectangle.Empty) { imageBounds.Inflate(3, 3); } NuGenTextPaintParams textPaintParams = new NuGenTextPaintParams(g); textPaintParams.Bounds = this.LayoutManager.GetTextBounds( new NuGenBoundsParams(contentBounds, imageAlign, imageBounds, this.RightToLeft) ); textPaintParams.Font = this.Font; textPaintParams.ForeColor = this.ForeColor; textPaintParams.Text = this.Text; textPaintParams.TextAlign = NuGenControlPaint.RTLContentAlignment(this.TextAlign, this.RightToLeft); textPaintParams.State = currentState; this.Renderer.DrawText(textPaintParams); }
private void DrawHeader(Graphics g, Rectangle bounds) { Debug.Assert(g != null, "g != null"); int headerHeight = this.LayoutManager.GetHeaderHeight(); int collapseButtonWidth = this.LayoutManager.GetCollapseButtonWidth(); Rectangle headerBounds = new Rectangle( bounds.Left , bounds.Top + headerHeight , bounds.Width , headerHeight ); Rectangle headerBodyBounds = headerBounds; headerBodyBounds.Width -= collapseButtonWidth; if (this.RightToLeft == RightToLeft.Yes) { headerBodyBounds.X += collapseButtonWidth; } NuGenControlState headerState = this.HeaderStateTracker.GetControlState(); NuGenItemPaintParams headerPaintParams = new NuGenItemPaintParams(g); headerPaintParams.Bounds = NuGenControlPaint.BorderRectangle(headerBounds); headerPaintParams.ContentAlign = this.RightToLeft == RightToLeft.Yes ? ContentAlignment.MiddleRight : ContentAlignment.MiddleLeft ; headerPaintParams.Font = this.Font; headerPaintParams.ForeColor = this.ForeColor; headerPaintParams.Image = this.Image; headerPaintParams.State = headerState; headerPaintParams.Text = this.Text; this.Renderer.DrawBackground(headerPaintParams); this.Renderer.DrawBorder(headerPaintParams); headerPaintParams.Bounds = headerBodyBounds; this.Renderer.DrawHeader(headerPaintParams); Rectangle collapseButtonBounds = new Rectangle(headerBounds.Left, headerBounds.Top, collapseButtonWidth, headerBounds.Height); if (this.RightToLeft == RightToLeft.Yes) { if (!_collapsed) { NuGenControlPaint.Make180CCWGraphics(headerPaintParams.Graphics, collapseButtonBounds); } } else { if (!_collapsed) { headerPaintParams.Graphics.RotateTransform(180); headerPaintParams.Graphics.TranslateTransform( -(headerBounds.Width + headerBodyBounds.Width) + 1 , -headerHeight + 1 ); } collapseButtonBounds.X += headerBodyBounds.Right; } headerPaintParams.Bounds = collapseButtonBounds; this.Renderer.DrawCollapseButton(headerPaintParams); }