/* * RestoreFormState */ /// <summary> /// </summary> /// <exception cref="ArgumentNullException"> /// <paramref name="formToRestore"/> is <see langword="null"/>. /// </exception> public void RestoreFormState(Form formToRestore) { if (formToRestore == null) { throw new ArgumentNullException("formToRestore"); } Debug.Assert(this.StoredForms != null, "this.StoredForms != null"); if (this.StoredForms.ContainsKey(formToRestore)) { NuGenFormStateDescriptor stateDescriptor = this.StoredForms[formToRestore]; ControlStyles[] formControlStyles = NuGenEnum.ToArray <ControlStyles>(); for (int i = 0; i < formControlStyles.Length; i++) { NuGenControlPaint.SetStyle( formToRestore, formControlStyles[i], stateDescriptor.Styles[formControlStyles[i]] ); formToRestore.BackColor = stateDescriptor.BackColor; formToRestore.Padding = stateDescriptor.Padding; } } }
/* * StoreFormState */ /// <summary> /// </summary> /// <exception cref="ArgumentNullException"> /// <paramref name="formToStore"/> is <see langword="null"/>. /// </exception> public void StoreFormState(Form formToStore) { if (formToStore == null) { throw new ArgumentNullException("formToStore"); } NuGenFormStateDescriptor stateDescriptor = new NuGenFormStateDescriptor(); stateDescriptor.BackColor = formToStore.BackColor; stateDescriptor.Padding = formToStore.Padding; ControlStyles[] formControlStyles = NuGenEnum.ToArray <ControlStyles>(); Debug.Assert(formControlStyles != null, "formControlStyles != null"); for (int i = 0; i < formControlStyles.Length; i++) { stateDescriptor.Styles.Add( formControlStyles[i], NuGenControlPaint.GetStyle(formToStore, formControlStyles[i]) ); } Debug.Assert(this.StoredForms != null, "this.StoredForms != null"); if (this.StoredForms.ContainsKey(formToStore)) { this.StoredForms[formToStore] = stateDescriptor; } else { this.StoredForms.Add(formToStore, stateDescriptor); } }
/// <summary> /// </summary> /// <exception cref="ArgumentNullException"> /// <para> /// <paramref name="g"/> is <see langword="null"/>. /// </para> /// -or- /// <para> /// <paramref name="image"/> is <see langword="null"/>. /// </para> /// </exception> public void DrawImage(Graphics g, Rectangle bounds, NuGenControlState state, Image image) { if (g == null) { throw new ArgumentNullException("g"); } if (image == null) { throw new ArgumentNullException("image"); } switch (state) { case NuGenControlState.Disabled: { g.DrawImage( image, bounds, 0, 0, image.Width, image.Height, GraphicsUnit.Pixel, NuGenControlPaint.GetDesaturatedImageAttributes() ); break; } default: { g.DrawImage(image, bounds); break; } } }
/* * OnPaint */ /// <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) { if (this.Orientation == NuGenOrientationStyle.Vertical) { NuGenControlPaint.Make90CCWGraphics(e.Graphics, this.ClientRectangle); } }
/* * OnPaint */ /// <summary> /// Raises the paint event. /// </summary> /// <param name="e">The <see cref="System.Windows.Forms.PaintEventArgs"/> instance containing the event data.</param> protected override void OnPaint(PaintEventArgs e) { Graphics g = e.Graphics; Rectangle bounds = this.ClientRectangle; NuGenControlState currentState = this.ButtonStateTracker.GetControlState(); Image image = this.Image; ContentAlignment imageAlign = this.ImageAlign; Rectangle imageBounds = Rectangle.Empty; if (image != null) { imageBounds = this.LayoutManager.GetImageBounds(new NuGenImageBoundsParams(bounds, image, imageAlign)); this.Renderer.DrawImage(new NuGenImagePaintParams(this, g, imageBounds, currentState, image)); } Rectangle textBounds = NuGenControlPaint.TextBoundsFromImageBounds( bounds, imageBounds, imageAlign ); NuGenTextPaintParams textPaintParams = new NuGenTextPaintParams(this, g, textBounds, currentState, this.Text); textPaintParams.Font = this.Font; textPaintParams.ForeColor = this.ForeColor; textPaintParams.TextAlign = this.TextAlign; this.Renderer.DrawText(textPaintParams); }
/* * 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> /// <exception cref="ArgumentNullException"> /// <para> /// <paramref name="g"/> is <see langword="null"/>. /// </para> /// -or- /// <para> /// <paramref name="text"/> is <see langword="null"/>. /// </para> /// -or- /// <para> /// <paramref name="font"/> is <see langword="null"/>. /// </para> /// </exception> public void DrawText( Graphics g, Rectangle bounds, NuGenControlState state, string text, Font font, Color foreColor, ContentAlignment textAlignment ) { if (g == null) { throw new ArgumentNullException("g"); } if (text == null) { throw new ArgumentNullException("text"); } if (font == null) { throw new ArgumentNullException("font"); } using (StringFormat sf = NuGenControlPaint.ContentAlignmentToStringFormat(textAlignment)) { sf.HotkeyPrefix = HotkeyPrefix.Show; sf.Trimming = StringTrimming.EllipsisCharacter; sf.FormatFlags = StringFormatFlags.NoWrap; this.DrawText(g, bounds, state, text, font, foreColor, sf); } }
/// <summary> /// Initializes a new instance of the <see cref="NuGenPictureBox"/> class. /// </summary> public NuGenPictureBox() { NuGenControlPaint.SetStyle(this, ControlStyles.OptimizedDoubleBuffer | ControlStyles.ResizeRedraw, true); NuGenControlPaint.SetStyle(this, ControlStyles.Selectable, false); this.AutoScroll = true; }
public void ImageBoundsFromContentAlignmentMiddleRightTest() { Rectangle imageBounds = NuGenControlPaint.ImageBoundsFromContentAlignment(_imageSize, _fitRectangle, ContentAlignment.MiddleRight); Assert.AreEqual(_rectWidth - _imageSize.Width, imageBounds.Left); Assert.AreEqual(_rectHeight / 2 - _imageSize.Height / 2, imageBounds.Top); }
public void ImageBoundsFromContentAlignmentTopLeftTest() { Rectangle imageBounds = NuGenControlPaint.ImageBoundsFromContentAlignment(_imageSize, _fitRectangle, ContentAlignment.TopLeft); Assert.AreEqual(0, imageBounds.Left); Assert.AreEqual(0, imageBounds.Top); }
/* * OnPaint */ /// <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; if (this.Orientation == NuGenOrientationStyle.Vertical) { NuGenControlPaint.Make90CCWGraphics(g, this.ClientRectangle); } NuGenTrackBarPaintParams paintParams = new NuGenTrackBarPaintParams( this, g, this.AgnosticTrackBounds, this.StateTracker.GetControlState(), this.ValueTracker, this.TickStyle ); this.Renderer.DrawTrack(paintParams); if (_focused && this.ShowFocusCues) { ControlPaint.DrawFocusRectangle(e.Graphics, this.ClientRectangle); } }
public void ImageBoundsFromContentAlignmentBottomLeftTest() { Rectangle imageBounds = NuGenControlPaint.ImageBoundsFromContentAlignment(_imageSize, _fitRectangle, ContentAlignment.BottomLeft); Assert.AreEqual(0, imageBounds.Left); Assert.AreEqual(_rectHeight - _imageSize.Height, imageBounds.Top); }
/// <summary> /// </summary> /// <param name="clientRectangle"></param> /// <param name="imageSize"></param> /// <returns></returns> public Rectangle GetImageBounds(Rectangle clientRectangle, Size imageSize) { return(NuGenControlPaint.ScaleToFit( Rectangle.Inflate(clientRectangle, -15, -15) , imageSize )); }
/// <summary> /// </summary> /// <exception cref="ArgumentNullException"><para><paramref name="paintParams"/> is <see langword="null"/>.</para></exception> public void DrawShadow(NuGenPaintParams paintParams) { if (paintParams == null) { throw new ArgumentNullException("paintParams"); } Graphics g = paintParams.Graphics; Rectangle bounds = paintParams.Bounds; int alpha = 0; Color baseColor = Color.Black; int alphaStep = 5; Padding deflatePadding = new Padding(1); using (NuGenGrfxMode mode = new NuGenGrfxMode(g)) { NuGenControlPaint.SetGraphicsVeryHighQuality(g); using (Pen pen = new Pen(Color.FromArgb(alpha, baseColor))) { for (int i = 0; i <= _shadowStepCount; i++) { NuGenControlPaint.DrawRoundRectangle(g, pen, bounds, _shadowRadius); pen.Color = Color.FromArgb(alpha += alphaStep, baseColor); bounds = NuGenControlPaint.DeflateRectangle(bounds, deflatePadding); if (i == 1) { alphaStep = 10; } } } } }
/* * DrawTabButtonImage */ /// <summary> /// </summary> /// <exception cref="ArgumentNullException"> /// <para> /// <paramref name="g"/> is <see langword="null"/>. /// </para> /// -or- /// <para> /// <paramref name="imageToDraw"/> is <see langword="null"/>. /// </para> /// </exception> private void DrawTabButtonImage(Graphics g, Image imageToDraw, Rectangle imageBounds, bool enabled) { if (g == null) { throw new ArgumentNullException("g"); } if (imageToDraw == null) { throw new ArgumentNullException("imageToDraw"); } if (enabled) { g.DrawImage(imageToDraw, imageBounds); } else { g.DrawImage( imageToDraw, imageBounds, 0, 0, imageBounds.Width, imageBounds.Height, GraphicsUnit.Pixel, NuGenControlPaint.GetGrayscaleImageAttributes() ); } }
/* * DrawShadow */ /// <summary> /// </summary> /// <param name="paintParams"></param> /// <exception cref="ArgumentNullException"> /// <para> /// <paramref name="paintParams"/> is <see langword="null"/>. /// </para> /// </exception> public void DrawShadow(NuGenPaintParams paintParams) { if (paintParams == null) { throw new ArgumentNullException("paintParams"); } Graphics g = paintParams.Graphics; Rectangle bounds = paintParams.Bounds; using (NuGenGrfxMode mode = new NuGenGrfxMode(g)) { g.SmoothingMode = SmoothingMode.AntiAlias; g.PixelOffsetMode = PixelOffsetMode.HighQuality; for (int i = 0; i < _shadowColorsCount; i++) { using (Pen pen = new Pen(_shadowColors[i])) { NuGenControlPaint.DrawRoundRectangle(g, pen, bounds, _shadowColorsCount - i); } bounds.Inflate(-1, -1); } } }
/// <summary> /// Initializes a new instance of the <see cref="NuGenBevel"/> class. /// </summary> public NuGenBevel() { NuGenControlPaint.SetStyle(this, ControlStyles.Selectable, false); NuGenControlPaint.SetStyle(this, ControlStyles.ResizeRedraw, true); this.TabStop = false; }
private void _printButton_Click(object sender, EventArgs e) { Canvas activeCanvas = _tabbedMdi.ActiveCanvas; if (activeCanvas != null) { if (!ScanningAndPrinting.CanPrint) { ShowWiaError(); return; } Control schema = activeCanvas.Schema; using (Bitmap bmp = new Bitmap(schema.Width, schema.Height)) { NuGenControlPaint.DrawToBitmap(schema, bmp); String tempFileName = Path.GetTempFileName(); String tempBmpFileName = String.Format(CultureInfo.CurrentCulture, "{0}.bmp", tempFileName); bmp.Save(tempBmpFileName, ImageFormat.Bmp); ScanningAndPrinting.Print(this, tempBmpFileName); try { File.Delete(tempFileName); File.Delete(tempBmpFileName); } catch { } } } }
private void _exportToImageButton_Click(Object sender, EventArgs e) { Canvas activeCanvas = _tabbedMdi.ActiveCanvas; if (activeCanvas != null) { Control schema = activeCanvas.Schema; using (Bitmap bmp = new Bitmap(schema.Width, schema.Height)) { NuGenControlPaint.DrawToBitmap(schema, bmp); Application.DoEvents(); using (NuGenSmoothImageExportBlock imageExport = new NuGenSmoothImageExportBlock()) { Application.DoEvents(); imageExport.ThumbnailMode = NuGenThumbnailMode.LoupeView; imageExport.Images.Add(bmp); StringCollection exportPathCollection = Settings.Default.MainForm_ExportPathCollection; if (exportPathCollection != null) { foreach (String path in exportPathCollection) { imageExport.ExportPathCollection.Add(path); } } imageExport.ShowDialog(this); Settings.Default.MainForm_ExportPathCollection = imageExport.ExportPathCollection; } } } }
/// <summary> /// Raises the <see cref="E:System.Windows.Forms.Control.Paint"/> event. /// </summary> /// <param name="e">A <see cref="T:System.Windows.Forms.PaintEventArgs"/> that contains the event data.</param> protected override void OnPaint(PaintEventArgs e) { if (this.Image != null) { Graphics g = e.Graphics; switch (this.DisplayMode) { case NuGenDisplayMode.ActualSize: g.DrawImage( this.Image, this.AutoScrollPosition.X, this.AutoScrollPosition.Y, this.Image.Width, this.Image.Height ); break; case NuGenDisplayMode.ScaleToFit: Rectangle fitRect = NuGenControlPaint.ScaleToFit(this.ClientRectangle, this.Image); g.DrawImage( this.Image, fitRect ); break; case NuGenDisplayMode.StretchToFit: g.DrawImage( this.Image, this.DisplayRectangle ); break; } } }
/* * InitializeHostForm */ /// <summary> /// Initializes the <see cref="HostForm"/>. /// </summary> /// <remarks>Note for inheritors. Make sure to check the <see cref="NuGenRibbonManager.HostForm"/> /// for <see langword="null"/>.</remarks> protected virtual void InitializeHostForm() { if (!this.DesignMode && this.HostForm != null) { Debug.Assert(this.FormStateStore != null, "this.FormStateStore != null"); this.FormStateStore.StoreFormState(this.HostForm); this.MessageFilter.TargetControl = this.HostForm; NuGenWmHandlerList msgMap = this.MessageProcessor.MessageMap; foreach (int wmId in msgMap) { this.MessageFilter.MessageMap.AddWmHandler(wmId, msgMap[wmId]); } NuGenControlPaint.SetStyle( this.HostForm, ControlStyles.AllPaintingInWmPaint | ControlStyles.OptimizedDoubleBuffer | ControlStyles.ResizeRedraw | ControlStyles.UserPaint, true ); this.HostForm.BackColor = this.Renderer.ColorTable.Form.BackColor; this.HostForm.Padding = new Padding( this.RibbonFormProperties.DisplayRectangleReductionHorizontal, this.RibbonFormProperties.DisplayRectangleReductionTop, this.RibbonFormProperties.DisplayRectangleReductionHorizontal, this.RibbonFormProperties.DisplayRectangleReductionBottom ); this.HostForm.HandleCreated += this.HostForm_HandleCreated; this.HostForm.Paint += this.HostForm_Paint; this.HostForm.Resize += this.HostForm_Resize; } }
private void TrackButton_MouseMove(object sender, MouseEventArgs e) { if (_isDragging) { Point cursorPos = NuGenControlPaint.TranslatePoint(e.Location, _trackButton, this); this.Value = this.GetValueFromPosition(cursorPos); } }
/// <summary> /// </summary> /// <param name="paintParams"></param> public void DrawBorder(NuGenPaintParams paintParams) { base.DrawBorder( paintParams.Graphics , NuGenControlPaint.BorderRectangle(paintParams.Bounds) , paintParams.State ); }
/// <summary> /// </summary> public Image GetSketch() { Rectangle bounds = this.GetBounds(); Bitmap sketch = new Bitmap(bounds.Width, bounds.Height); NuGenControlPaint.DrawToBitmap(_hWnd, sketch); return(sketch); }
public void SizeFToSizeTest2() { SizeF size = new SizeF(2.6f, 4.8f); Size convertedSize = NuGenControlPaint.SizeFToSize(size); Assert.AreEqual(3, convertedSize.Width); Assert.AreEqual(5, convertedSize.Height); }
/// <summary> /// Initializes a new instance of the <see cref="NuGenToolButton"/> class. /// </summary> public NuGenToolButton() { NuGenControlPaint.SetStyle(this, ControlStyles.Opaque | ControlStyles.Selectable, false); NuGenControlPaint.SetStyle(this, ControlStyles.ResizeRedraw | ControlStyles.SupportsTransparentBackColor, true); this.BackColor = Color.Transparent; this.TabStop = false; }
/// <summary> /// </summary> /// <param name="textBoundsParams"></param> /// <returns></returns> public Rectangle GetTextBounds(NuGenTextBoundsParams textBoundsParams) { return(NuGenControlPaint.TextBoundsFromImageBounds( textBoundsParams.Bounds, textBoundsParams.ImageBounds, textBoundsParams.ImageAlign )); }
/* * GetRightNotchedPolygon */ /// <summary> /// </summary> /// <param name="bounds"></param> /// <returns></returns> private Point[] GetRightNotchedPolygon(Rectangle bounds) { return(new Point[] { new Point(bounds.Right - _rightNotchSize.Width, bounds.Top), new Point(bounds.Right, bounds.Top + _rightNotchSize.Height), NuGenControlPaint.RectBRCorner(bounds) }); }
/* * OnPaint */ /// <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) { Debug.Assert(this.ButtonStateTracker != null, "this.ButtonStateTracker != null"); Debug.Assert(this.Renderer != null, "this.Renderer != null"); Graphics g = e.Graphics; NuGenControlState currentState = this.ButtonStateTracker.GetControlState(); Rectangle bounds = this.ClientRectangle; Rectangle contentBounds = this.LayoutManager.GetContentRectangle(bounds); NuGenPaintParams paintParams = new NuGenPaintParams(g); paintParams.Bounds = bounds; paintParams.State = currentState; this.Renderer.DrawBackground(paintParams); this.Renderer.DrawShadow(paintParams); this.Renderer.DrawBorder(paintParams); 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); }
/* * GetLeftTopNotchedPolygon */ /// <summary> /// </summary> /// <param name="bounds"></param> /// <returns></returns> private Point[] GetLeftTopNotchedPolygon(Rectangle bounds) { return(new Point[] { NuGenControlPaint.RectBLCorner(bounds), new Point(bounds.Left, bounds.Top + _leftNotchSize.Height), new Point(bounds.Left + _leftNotchSize.Width, bounds.Top), new Point(bounds.Right - _rightNotchSize.Width - _penWidth, bounds.Top) }); }