protected override void OnPaint(PaintEventArgs e) { var g = e.Graphics; Rectangle clientRectangle = ClientRectangle; if (NeedNewGlyphSizeMeasurement) { MeasuredGlyphSize = TextRenderer.MeasureText( g, CloseButtonGlyph, CurrentCloseButtonGlyphFont, Size.Empty, TextFormatFlags.NoPadding); NeedNewGlyphSizeMeasurement = false; } // Block out the entire client area. using (var inactiveAreaBrush = new SolidBrush(OwnerTabControl.BackColor)) { g.FillRectangle(inactiveAreaBrush, clientRectangle); } // Then draw each tab page. for (int tabIndex = 0; tabIndex < OwnerTabControl.TabPages.Count; tabIndex++) { TabPage tabPage = OwnerTabControl.TabPages[tabIndex]; // Remember some things for drawing text later. Color tabBackColor; Color tabForeColor; Color glyphForeColor; Color glyphPressedBackColor; bool drawModifiedGlyph; bool drawCloseButtonGlyph; bool hoverOverThisTabPageGlyph = tabIndex == HoverTabIndex && HoverOverGlyph; bool drawGlyphPressed = hoverOverThisTabPageGlyph && tabIndex == GlyphPressedIndex; bool drawGlyphHighlight = hoverOverThisTabPageGlyph && GlyphPressedIndex == -1 || tabIndex == GlyphPressedIndex; if (tabIndex == OwnerTabControl.ActiveTabPageIndex) { using (var activeTabHeaderBrush = new SolidBrush(tabPage.ActiveBackColor)) { g.FillRectangle(activeTabHeaderBrush, new RectangleF(tabIndex * CurrentTabWidth, 0, CurrentTabWidth, CurrentHeight)); } tabBackColor = tabPage.ActiveBackColor; tabForeColor = tabPage.ActiveForeColor; glyphPressedBackColor = tabPage.ActiveBackColor.GetBrightness() >= 0.5f ? ControlPaint.Dark(tabPage.ActiveBackColor) : ControlPaint.Light(tabPage.ActiveBackColor); glyphForeColor = tabPage.GlyphForeColor.A == 0 ? tabForeColor : tabPage.GlyphForeColor; if (drawGlyphHighlight) { // Highlight when hovering or the glyph button is pressed. // Default to a lighter version if no color given. glyphForeColor = tabPage.GlyphHoverColor.A == 0 ? ControlPaint.Light(glyphForeColor) : tabPage.GlyphHoverColor; drawModifiedGlyph = false; drawCloseButtonGlyph = true; } else { drawModifiedGlyph = tabPage.IsModified; drawCloseButtonGlyph = !tabPage.IsModified; } } else { if (tabIndex == HoverTabIndex) { using (var hoverBrush = new SolidBrush(OwnerTabControl.InactiveTabHeaderHoverColor)) { g.FillRectangle(hoverBrush, tabIndex * CurrentTabWidth, 0, CurrentTabWidth, CurrentHeight); } // Drawing rectangles with a Pen includes the right border, so subtract 1 from the width. using (var hoverBorderPen = new Pen(OwnerTabControl.InactiveTabHeaderHoverBorderColor, 1)) { g.DrawRectangle(hoverBorderPen, tabIndex * CurrentTabWidth, 0, CurrentTabWidth - 1, CurrentHeight); } tabBackColor = OwnerTabControl.InactiveTabHeaderHoverColor; } else { tabBackColor = OwnerTabControl.BackColor; } tabForeColor = OwnerTabControl.ForeColor; glyphPressedBackColor = OwnerTabControl.BackColor; glyphForeColor = OwnerTabControl.InactiveTabHeaderGlyphForeColor.A == 0 ? tabForeColor : OwnerTabControl.InactiveTabHeaderGlyphForeColor; if (drawGlyphHighlight) { // Highlight when hovering or the glyph button is pressed. // Default to a lighter version if no color given. glyphForeColor = OwnerTabControl.InactiveTabHeaderGlyphHoverColor.A == 0 ? ControlPaint.Light(glyphForeColor) : OwnerTabControl.InactiveTabHeaderGlyphHoverColor; drawModifiedGlyph = false; drawCloseButtonGlyph = true; } else { drawModifiedGlyph = tabPage.IsModified; drawCloseButtonGlyph = !drawModifiedGlyph && tabIndex == HoverTabIndex; } } int textAreaLeftOffset = (int)Math.Floor(tabIndex * CurrentTabWidth + CurrentHorizontalTabTextMargin); int textAreaWidth = CurrentTextAreaWidthIncludeGlyph; if (drawModifiedGlyph || drawCloseButtonGlyph) { textAreaWidth -= MeasuredGlyphSize.Width; } g.SmoothingMode = SmoothingMode.AntiAlias; g.TextRenderingHint = TextRenderingHint.ClearTypeGridFit; TextRenderer.DrawText( g, tabPage.Text, OwnerTabControl.Font, new Rectangle(textAreaLeftOffset, 0, textAreaWidth, CurrentHeight), tabForeColor, tabBackColor, TextFormatFlags.Left | TextFormatFlags.VerticalCenter | TextFormatFlags.EndEllipsis | TextFormatFlags.NoPadding); if (drawModifiedGlyph || drawCloseButtonGlyph) { // Subtract the padding, one from the left, two from the right side. float hrzPadding = MeasuredGlyphSize.Width / EstimatedHorizontalGlyphPaddingRatio; float diameter = MeasuredGlyphSize.Width - 3 * hrzPadding; // Prevent drawing outside the glyph rectangle. float targetHeight = Math.Min(MeasuredGlyphSize.Height + hrzPadding * 2, CurrentHeight - hrzPadding * 2); RectangleF backgroundGlyphRectangle = new RectangleF( textAreaLeftOffset + textAreaWidth - hrzPadding, (CurrentHeight - targetHeight) / 2, MeasuredGlyphSize.Width + hrzPadding * 2, targetHeight); g.SetClip(backgroundGlyphRectangle); if (drawModifiedGlyph) { RectangleF modifiedGlyphRectangle = new RectangleF( textAreaLeftOffset + textAreaWidth + hrzPadding, (CurrentHeight - diameter) / 2, diameter, diameter); // Draw a circle where otherwise the '×' would be. using (var ellipseBrush = new SolidBrush(glyphForeColor)) { g.FillEllipse(ellipseBrush, modifiedGlyphRectangle); } } else if (drawCloseButtonGlyph) { if (drawGlyphPressed) { g.SmoothingMode = SmoothingMode.None; using (var backgroundBrush = new SolidBrush(glyphPressedBackColor)) { g.FillRectangle(backgroundBrush, backgroundGlyphRectangle); } g.SmoothingMode = SmoothingMode.AntiAlias; } // Make rectangle 2 pixels less high to not interfere with hover border. Rectangle glyphTextRectangle = new Rectangle( textAreaLeftOffset + textAreaWidth, 1, MeasuredGlyphSize.Width, MeasuredGlyphSize.Height - 2); TextRenderer.DrawText( g, CloseButtonGlyph, CurrentCloseButtonGlyphFont, glyphTextRectangle, glyphForeColor, drawGlyphPressed ? glyphPressedBackColor : tabBackColor, TextFormatFlags.HorizontalCenter | TextFormatFlags.VerticalCenter | TextFormatFlags.NoPadding | TextFormatFlags.PreserveGraphicsClipping); } g.ResetClip(); } g.SmoothingMode = SmoothingMode.None; } }
/// <summary> /// Darks the specified color. /// 让颜色变深一些 /// </summary> /// <param name="color">The color.</param> /// <returns></returns> public static Color Dark(Color color) { return(ControlPaint.Dark(color)); }
/// <summary> Method is called whenever this form is resized. </summary> /// <param name="e"></param> /// <remarks> This redraws the background of this form </remarks> protected override void OnResize(EventArgs e) { base.OnResize(e); // Get rid of any current background image if (BackgroundImage != null) { BackgroundImage.Dispose(); BackgroundImage = null; } if (ClientSize.Width > 0) { // Create the items needed to draw the background Bitmap image = new Bitmap(ClientSize.Width, ClientSize.Height); Graphics gr = Graphics.FromImage(image); Rectangle rect = new Rectangle(new Point(0, 0), ClientSize); // Create the brush LinearGradientBrush brush = new LinearGradientBrush(rect, SystemColors.Control, ControlPaint.Dark(SystemColors.Control), LinearGradientMode.Vertical); brush.SetBlendTriangularShape(0.33F); // Create the image gr.FillRectangle(brush, rect); gr.Dispose(); // Set this as the backgroundf BackgroundImage = image; } }
protected override void OnRenderButtonBackground(ToolStripItemRenderEventArgs e) { Graphics g = e.Graphics; TabStrip tabs = e.ToolStrip as TabStrip; TabStripButton tab = e.Item as TabStripButton; if (tabs == null || tab == null) { if (currentRenderer != null) { currentRenderer.DrawButtonBackground(e); } else { base.OnRenderButtonBackground(e); } return; } bool selected = tab.Checked; bool hovered = tab.Selected; int top = 0; int left = 0; int width = tab.Bounds.Width - 1; int height = tab.Bounds.Height - 1; Rectangle drawBorder; if (UseVS) { if (tabs.Orientation == Orientation.Horizontal) { if (!selected) { top = selOffset; height -= (selOffset - 1); } else { top = 1; } drawBorder = new Rectangle(0, 0, width, height); } else { if (!selected) { left = selOffset; width -= (selOffset - 1); } else { left = 1; } drawBorder = new Rectangle(0, 0, height, width); } using (Bitmap b = new Bitmap(drawBorder.Width, drawBorder.Height)) { VisualStyleElement el = VisualStyleElement.Tab.TabItem.Normal; if (selected) { el = VisualStyleElement.Tab.TabItem.Pressed; } if (hovered) { el = VisualStyleElement.Tab.TabItem.Hot; } if (!tab.Enabled) { el = VisualStyleElement.Tab.TabItem.Disabled; } if (!selected || hovered) { drawBorder.Width++; } else { drawBorder.Height++; } using (Graphics gr = Graphics.FromImage(b)) { VisualStyleRenderer rndr = new VisualStyleRenderer(el); rndr.DrawBackground(gr, drawBorder); if (tabs.Orientation == Orientation.Vertical) { if (Mirrored) { b.RotateFlip(RotateFlipType.Rotate270FlipXY); } else { b.RotateFlip(RotateFlipType.Rotate270FlipNone); } } else { if (Mirrored) { b.RotateFlip(RotateFlipType.RotateNoneFlipY); } } if (Mirrored) { left = tab.Bounds.Width - b.Width - left; top = tab.Bounds.Height - b.Height - top; } g.DrawImage(b, left, top); } } } else { if (tabs.Orientation == Orientation.Horizontal) { if (!selected) { top = selOffset; height -= (selOffset - 1); } else { top = 1; } if (Mirrored) { left = 1; top = 0; } else { top++; } width--; } else { if (!selected) { left = selOffset; width--; } else { left = 1; } if (Mirrored) { left = 0; top = 1; } } height--; drawBorder = new Rectangle(left, top, width, height); using (GraphicsPath gp = new GraphicsPath()) { if (Mirrored && tabs.Orientation == Orientation.Horizontal) { gp.AddLine(drawBorder.Left, drawBorder.Top, drawBorder.Left, drawBorder.Bottom - 2); gp.AddArc(drawBorder.Left, drawBorder.Bottom - 3, 2, 2, 90, 90); gp.AddLine(drawBorder.Left + 2, drawBorder.Bottom, drawBorder.Right - 2, drawBorder.Bottom); gp.AddArc(drawBorder.Right - 2, drawBorder.Bottom - 3, 2, 2, 0, 90); gp.AddLine(drawBorder.Right, drawBorder.Bottom - 2, drawBorder.Right, drawBorder.Top); } else if (!Mirrored && tabs.Orientation == Orientation.Horizontal) { gp.AddLine(drawBorder.Left, drawBorder.Bottom, drawBorder.Left, drawBorder.Top + 2); gp.AddArc(drawBorder.Left, drawBorder.Top + 1, 2, 2, 180, 90); gp.AddLine(drawBorder.Left + 2, drawBorder.Top, drawBorder.Right - 2, drawBorder.Top); gp.AddArc(drawBorder.Right - 2, drawBorder.Top + 1, 2, 2, 270, 90); gp.AddLine(drawBorder.Right, drawBorder.Top + 2, drawBorder.Right, drawBorder.Bottom); } else if (Mirrored && tabs.Orientation == Orientation.Vertical) { gp.AddLine(drawBorder.Left, drawBorder.Top, drawBorder.Right - 2, drawBorder.Top); gp.AddArc(drawBorder.Right - 2, drawBorder.Top + 1, 2, 2, 270, 90); gp.AddLine(drawBorder.Right, drawBorder.Top + 2, drawBorder.Right, drawBorder.Bottom - 2); gp.AddArc(drawBorder.Right - 2, drawBorder.Bottom - 3, 2, 2, 0, 90); gp.AddLine(drawBorder.Right - 2, drawBorder.Bottom, drawBorder.Left, drawBorder.Bottom); } else { gp.AddLine(drawBorder.Right, drawBorder.Top, drawBorder.Left + 2, drawBorder.Top); gp.AddArc(drawBorder.Left, drawBorder.Top + 1, 2, 2, 180, 90); gp.AddLine(drawBorder.Left, drawBorder.Top + 2, drawBorder.Left, drawBorder.Bottom - 2); gp.AddArc(drawBorder.Left, drawBorder.Bottom - 3, 2, 2, 90, 90); gp.AddLine(drawBorder.Left + 2, drawBorder.Bottom, drawBorder.Right, drawBorder.Bottom); } if (selected || hovered) { Color fill = (hovered) ? Color.WhiteSmoke : Color.White; if (renderMode == ToolStripRenderMode.Professional) { fill = (hovered) ? ProfessionalColors.ButtonCheckedGradientBegin : ProfessionalColors.ButtonCheckedGradientEnd; using (LinearGradientBrush br = new LinearGradientBrush(tab.ContentRectangle, fill, ProfessionalColors.ButtonCheckedGradientMiddle, LinearGradientMode.Vertical)) g.FillPath(br, gp); } else { using (SolidBrush br = new SolidBrush(fill)) g.FillPath(br, gp); } } using (Pen p = new Pen((selected) ? ControlPaint.Dark(SystemColors.AppWorkspace) : SystemColors.AppWorkspace)) g.DrawPath(p, gp); } } }
protected override void OnPaintBackground(PaintEventArgs e) { base.OnPaintBackground(e); if (Visible) { e.Graphics.Clear(BackColor); } e.Graphics.DrawRectangle(Focused ? new Pen(ControlPaint.Dark(BackColor), 10) : new Pen(ControlPaint.Dark(BackColor), 5), ClientRectangle); }
/// <summary> /// Perform a layout of the elements. /// </summary> /// <param name="context">Layout context.</param> public override void Layout(ViewLayoutContext context) { Debug.Assert(context != null); ClientRectangle = context.DisplayRectangle; // We always extend an extra pixel downwards to draw over the containers border Rectangle adjustRect = new Rectangle(ClientRectangle.X, ClientRectangle.Y, ClientWidth, ClientHeight + 1); // Get the client rect of the parent Rectangle parentRect = Parent.ClientRectangle; // If we are only partially visible on the right hand side if ((adjustRect.X < parentRect.Right) && (adjustRect.Right >= parentRect.Right)) { // Truncate on the right hand side to the parent adjustRect.Width = parentRect.Right - adjustRect.X; } // If we are only partially visible on the left hand side if ((adjustRect.Right > parentRect.X) && (adjustRect.X < parentRect.X)) { // Truncate on the left hand side to the parent adjustRect.Width = adjustRect.Right - parentRect.X; adjustRect.X = parentRect.X; } // Use adjusted rectangle as our client rectangle ClientRectangle = adjustRect; // Use the font height to decide on the text rectangle int fontHeight = _ribbon.CalculatedValues.DrawFontHeight; _textRect = new Rectangle(ClientLocation.X + TEXT_SIDE_GAP, ClientLocation.Y + (ClientHeight - fontHeight - TEXT_BOTTOM_GAP), ClientWidth - (TEXT_SIDE_GAP * 2), fontHeight); // Remember to dispose of old memento if (_mementoContentText != null) { _mementoContentText.Dispose(); _mementoContentText = null; } if (_mementoContentShadow1 != null) { _mementoContentShadow1.Dispose(); _mementoContentShadow1 = null; } if (_mementoContentShadow2 != null) { _mementoContentShadow2.Dispose(); _mementoContentShadow2 = null; } // Office 2010 draws a shadow effect of the text if (_ribbon.RibbonShape == PaletteRibbonShape.Office2010) { Rectangle shadowTextRect1 = new Rectangle(_textRect.X - 1, _textRect.Y + 1, _textRect.Width, _textRect.Height); Rectangle shadowTextRect2 = new Rectangle(_textRect.X + 1, _textRect.Y + 1, _textRect.Width, _textRect.Height); _contentProvider.OverrideTextColor = Color.FromArgb(128, ControlPaint.Dark(GetRibbonBackColor1(PaletteState.Normal))); if (DrawOnComposition) { _contentProvider.OverrideTextHint = PaletteTextHint.SingleBitPerPixelGridFit; } _mementoContentShadow1 = context.Renderer.RenderStandardContent.LayoutContent(context, shadowTextRect1, _contentProvider, this, VisualOrientation.Top, PaletteState.Normal, false); _mementoContentShadow2 = context.Renderer.RenderStandardContent.LayoutContent(context, shadowTextRect2, _contentProvider, this, VisualOrientation.Top, PaletteState.Normal, false); _contentProvider.OverrideTextColor = Color.Empty; } // Use the renderer to layout the text _mementoContentText = context.Renderer.RenderStandardContent.LayoutContent(context, _textRect, _contentProvider, this, VisualOrientation.Top, PaletteState.Normal, false); _contentProvider.OverrideTextHint = PaletteTextHint.Inherit; }
private void OnPaint(object sender, PaintEventArgs e) { // keep ' MyBase.OnPaint(e) // BackColor = com.convertColour(com.Config.GetConfig("Colors", "ButtonFace")) // keep // keep // keep ForeColor = com.convertColour(com.Config.GetConfig("Colors", "ButtonText")) // Console.WriteLine(Font.Name & Font.Size) // Dim f As New Font() // keep 'Font = SaveSystem.currentTheme.buttonFont // keep // keep colLightBorder = ControlPaint.Light(BackColor, 50); colDarkBorder = ControlPaint.Dark(BackColor, 50); // keep Graphics g = e.Graphics; g.Clear(BackColor); // keep g.TextRenderingHint = System.Drawing.Text.TextRenderingHint.SingleBitPerPixelGridFit; StringFormat sf = new StringFormat(); sf.Alignment = StringAlignment.Center; sf.LineAlignment = StringAlignment.Center; TextAlign = (ContentAlignment)512; Rectangle textRect = new Rectangle(1, 1, Width - 3, Height - 3); if (TextImageRelation == TextImageRelation.ImageBeforeText) { Int32 imgWidth; if (Image != null) { imgWidth = Image.Width; } else { imgWidth = 0; } textRect.X = 6 + (imgWidth); textRect.Width = Width - 6 - (imgWidth); } // Console.WriteLine(TextAlign); sf.HotkeyPrefix = System.Drawing.Text.HotkeyPrefix.Show; // ImageAli if ((blnPressed && Enabled && (!Stuck)) || Held) { g.FillRectangle(new SolidBrush(colLightBorder), new Rectangle(0, 0, Width, Height)); g.FillRectangle(Brushes.Black, new Rectangle(0, 0, Width - 1, Height - 1)); g.FillRectangle(new SolidBrush(colDarkBorder), new Rectangle(1, 1, Width - 2, Height - 2)); if (Held) { g.FillRectangle(new TextureBrush(AlphaTexture()), 2, 2, Width - 3, Height - 3); } else { g.FillRectangle(new SolidBrush(BackColor), new Rectangle(2, 2, Width - 3, Height - 3)); } textRect.Offset(1, 1); g.DrawString(Text, Font, new SolidBrush(ForeColor), textRect, sf); } else { g.FillRectangle(Brushes.Black, new Rectangle(0, 0, Width, Height)); g.FillRectangle(new SolidBrush(colLightBorder), new Rectangle(0, 0, Width - 1, Height - 1)); g.FillRectangle(new SolidBrush(colDarkBorder), new Rectangle(1, 1, Width - 2, Height - 2)); g.FillRectangle(new SolidBrush(BackColor), new Rectangle(1, 1, Width - 3, Height - 3)); if ((Enabled)) { g.DrawString(Text, Font, new SolidBrush(ForeColor), textRect, sf); } else { g.DrawString(Text, Font, new SolidBrush(colDarkBorder), textRect, sf); } } if (!(Image == null)) { if (TextImageRelation == TextImageRelation.Overlay) { g.DrawImage(Image, Convert.ToInt32((Width / (double)2) - (Image.Width / (double)2)), Convert.ToInt32((Height / (double)2) - Convert.ToInt32(Image.Height / (double)2))); } if (TextImageRelation == TextImageRelation.ImageBeforeText) { g.DrawImage(Image, 2, Convert.ToInt32((Height / (double)2) - Convert.ToInt32(Image.Height / (double)2))); } } if ((ShowFocusRectangle && Enabled && Focused)) { g.DrawRectangle(new Pen(Color.Black, 1) { DashPattern = new[] { 1f, 1f } }, new Rectangle(3, 3, Width - 7, Height - 7)); } }
protected override void OnPaintBackground(PaintEventArgs pevent) { base.OnPaintBackground(pevent); pevent.Graphics.Clear(mouseDown ? ControlPaint.Dark(BackColor) : BackColor); }
protected override void OnPaintAdornments(PaintEventArgs pe) { if (Control != null && Control.Visible && Control.BorderStyle == BorderStyle.None) { Color color = (Control.BackColor.GetBrightness() < 0.5) ? ControlPaint.Light(Control.BackColor) : ControlPaint.Dark(Control.BackColor); using (Pen pen = new Pen(color) { DashStyle = System.Drawing.Drawing2D.DashStyle.Dash }) { Rectangle clientRectangle = Control.ClientRectangle; clientRectangle.Width--; clientRectangle.Height--; pe.Graphics.DrawRectangle(pen, clientRectangle); } } base.OnPaintAdornments(pe); }
private void show_step_2() { // show Step 2 instructions this.step1Label.ForeColor = ControlPaint.LightLight(SystemColors.ActiveCaption); this.step2Label.ForeColor = ControlPaint.Dark(SystemColors.ActiveCaption); }
public MainForm() { InitializeComponent(); LoadConfiguration(); invalidOrNothingBrush = new SolidBrush(invalidOrNothingColor = Color.FromArgb(255, 224, 224)); notTranslatedBrush = new SolidBrush(notTranslatedColor = Color.FromArgb(255, 255, 224)); translatedBrush = new SolidBrush(translatedColor = Color.FromArgb(224, 255, 224)); ignoredBrush = new SolidBrush(ignoredColor = Color.FromArgb(224, 244, 255)); dataLoaded = false; fontsReady = false; substListsAssigned = false; enableCharacterOverridesToolStripMenuItem.CheckedChanged += (s, e) => { textEditorControl.Invalidate(); }; tvTextFiles.DrawNode += (s, e) => { if (e.Node == null || !e.Node.IsVisible) { return; } var selected = ((e.State & TreeNodeStates.Selected) == TreeNodeStates.Selected); var unfocused = (!e.Node.TreeView.Focused); var font = (e.Node.NodeFont ?? e.Node.TreeView.Font); var textFormatFlags = TextFormatFlags.GlyphOverhangPadding; var textBounds = new Rectangle(e.Bounds.X, e.Bounds.Y + 1, e.Bounds.Width, e.Bounds.Height); if (e.Node.Tag is ValueTuple <string, Translation> ) { (string path, Translation translation) = (ValueTuple <string, Translation>)e.Node.Tag; var translatedCount = translation.Entries.Count(x => x.ID != -1 && !x.IsIgnored && string.Compare(x.Original, x.Translation) != 0); var totalValidCount = translation.Entries.Count(x => x.ID != -1 && !x.IsIgnored); var countNoteText = $"[{translatedCount}/{totalValidCount}]"; var countNoteTextBounds = new Rectangle(textBounds.Right, textBounds.Top, TextRenderer.MeasureText(countNoteText, font).Width, textBounds.Height); var countNoteBackgroundBounds = new Rectangle(e.Node.Bounds.Right, e.Node.Bounds.Top, countNoteTextBounds.Width, e.Node.Bounds.Height); e.Graphics.FillRectangle(SystemBrushes.Window, countNoteBackgroundBounds); if (!selected) { e.Graphics.FillRectangle(((translatedCount == 0 && totalValidCount != 0) ? invalidOrNothingBrush : (translatedCount == totalValidCount ? translatedBrush : notTranslatedBrush)), e.Node.Bounds); TextRenderer.DrawText(e.Graphics, e.Node.Text, font, textBounds, SystemColors.ControlText, textFormatFlags); TextRenderer.DrawText(e.Graphics, countNoteText, font, countNoteTextBounds, ControlPaint.Dark((translatedCount == 0 && totalValidCount != 0) ? invalidOrNothingColor : (translatedCount == totalValidCount ? translatedColor : notTranslatedColor)), textFormatFlags); } else { e.Graphics.FillRectangle((unfocused ? SystemBrushes.Control : SystemBrushes.Highlight), e.Node.Bounds); TextRenderer.DrawText(e.Graphics, e.Node.Text, font, textBounds, (unfocused ? SystemColors.ControlText : SystemColors.HighlightText), textFormatFlags); TextRenderer.DrawText(e.Graphics, countNoteText, font, countNoteTextBounds, (unfocused ? ControlPaint.Dark(SystemColors.Control) : SystemColors.Highlight), textFormatFlags); } } else if (selected && unfocused) { e.Graphics.FillRectangle(SystemBrushes.Control, e.Node.Bounds); TextRenderer.DrawText(e.Graphics, e.Node.Text, font, textBounds, SystemColors.ControlText, textFormatFlags); } else if (!selected) { e.Graphics.FillRectangle(SystemBrushes.Window, e.Node.Bounds); TextRenderer.DrawText(e.Graphics, e.Node.Text, font, textBounds, SystemColors.WindowText, textFormatFlags); } else { e.Graphics.FillRectangle(SystemBrushes.Highlight, e.Node.Bounds); TextRenderer.DrawText(e.Graphics, e.Node.Text, font, textBounds, SystemColors.HighlightText, textFormatFlags); } if (selected) { ControlPaint.DrawFocusRectangle(e.Graphics, e.Node.Bounds); } }; lbMessages.SelectedIndexChanged += (s, e) => { if (lbMessages.SelectedItem != null) { (lbMessages.SelectedItem as TranslatableEntry).PropertyChanged -= MainForm_PropertyChanged; (lbMessages.SelectedItem as TranslatableEntry).PropertyChanged += MainForm_PropertyChanged; } UpdateTextEditor(); }; lbMessages.DrawItem += (s, e) => { if (e.Index == -1) { return; } var entry = ((s as ListBox).Items[e.Index] as TranslatableEntry); var selected = ((e.State & DrawItemState.Selected) == DrawItemState.Selected); var unfocused = (!(s as ListBox).Focused); var font = (e.Font ?? (s as ListBox).Font); var textFormatFlags = (TextFormatFlags.Left | TextFormatFlags.WordEllipsis); var label = ((entry.ID == -1) ? "(Invalid)" : $"#{entry.ID:D3}: {entry.Original.TrimEnd(Environment.NewLine.ToCharArray()).Replace(Environment.NewLine, " ")}"); if (!selected) { e.Graphics.FillRectangle(((entry.ID == -1) ? invalidOrNothingBrush : (entry.IsIgnored ? ignoredBrush : ((string.Compare(entry.Original, entry.Translation) == 0) ? notTranslatedBrush : translatedBrush))), e.Bounds); TextRenderer.DrawText(e.Graphics, label, e.Font, e.Bounds, SystemColors.ControlText, textFormatFlags); } else { e.Graphics.FillRectangle((unfocused ? SystemBrushes.Control : SystemBrushes.Highlight), e.Bounds); TextRenderer.DrawText(e.Graphics, label, font, e.Bounds, (unfocused ? SystemColors.ControlText : SystemColors.HighlightText), textFormatFlags); } if (selected) { ControlPaint.DrawFocusRectangle(e.Graphics, e.Bounds); } }; cmbFont.SelectedIndexChanged += (s, e) => { UpdateTextEditor(); }; cmbMarkerWidths.SelectedIndexChanged += (s, e) => { UpdateTextEditor(); }; cmbMarkerWidths.DataSource = new BindingSource(new Dictionary <string, int>() { { "[None]", 0 } }.Concat(config.TextMarkerWidths.OrderBy(x => x.Key)), null); cmbMarkerWidths.DisplayMember = "Key"; cmbMarkerWidths.ValueMember = "Value"; FormClosing += (s, e) => { config.SerializeToFile(programConfigPath); }; UpdateFormTitle(); tsslStatus.Text = "Ready"; }
private void DrawBars(Graphics graph) { SolidBrush brsFont = null; Font valFont = null; StringFormat sfFormat = null; try { brsFont = new SolidBrush(_fontColor); valFont = new Font(_fontFamily, _labelFontSize); sfFormat = new StringFormat(); sfFormat.Alignment = StringAlignment.Center; int i = 0; PointF[] linePoints = null; if (_renderMode == BarGraphRenderMode.Lines) { linePoints = new PointF[DataPoints.Count]; } int pointIndex = 0; // Draw bars and the value above each bar using (Pen pen = new Pen(_fontColor, 0.15f)) { using (SolidBrush whiteBrsh = new SolidBrush(Color.FromArgb(128, Color.White))) { foreach (DataItem item in DataPoints) { using (SolidBrush barBrush = new SolidBrush(item.ItemColor)) { float itemY = _yOrigin + _graphHeight - item.SweepSize; if (_renderMode == BarGraphRenderMode.Lines) { linePoints[pointIndex++] = new PointF(_xOrigin + item.StartPos + (_barWidth / 2), itemY); } else if (_renderMode == BarGraphRenderMode.Bars) { float ox = _xOrigin + item.StartPos; float oy = itemY; float ow = _barWidth; float oh = item.SweepSize; float of = 9.5f; PointF[] pts = new PointF[] { new PointF(ox, oy), new PointF(ox + ow, oy), new PointF(ox + of, oy + of), new PointF(ox + of + ow, oy + of), new PointF(ox, oy + oh), new PointF(ox + of, oy + of + oh), new PointF(ox + of + ow, oy + of + oh) }; graph.FillPolygon(barBrush, new PointF[] { pts[2], pts[3], pts[6], pts[5] }); using (SolidBrush ltBrsh = new SolidBrush(ControlPaint.Light(item.ItemColor, 0.1f))) graph.FillPolygon(ltBrsh, new PointF[] { pts[0], pts[2], pts[5], pts[4] }); using (SolidBrush drkBrush = new SolidBrush(ControlPaint.Dark(item.ItemColor, 0.05f))) graph.FillPolygon(drkBrush, new PointF[] { pts[0], pts[1], pts[3], pts[2] }); graph.DrawLine(pen, pts[0], pts[1]); graph.DrawLine(pen, pts[0], pts[2]); graph.DrawLine(pen, pts[1], pts[3]); graph.DrawLine(pen, pts[2], pts[3]); graph.DrawLine(pen, pts[2], pts[5]); graph.DrawLine(pen, pts[0], pts[4]); graph.DrawLine(pen, pts[4], pts[5]); graph.DrawLine(pen, pts[5], pts[6]); graph.DrawLine(pen, pts[3], pts[6]); // Draw data value if (_displayBarData && (i % _interval) == 0) { float sectionWidth = (_barWidth + _spaceBtwBars); float startX = _xOrigin + (i * sectionWidth) + (sectionWidth / 2); // This draws the value on center of the bar float startY = itemY - 2f - valFont.Height; // Positioned on top of each bar by 2 pixels RectangleF recVal = new RectangleF(startX - ((sectionWidth * _interval) / 2), startY, sectionWidth * _interval, valFont.Height); SizeF sz = graph.MeasureString(item.Value.ToString("#,###.##"), valFont, recVal.Size, sfFormat); //using ( SolidBrush brsh = new SolidBrush( Color.FromArgb( 180, 255, 255, 255 ) ) ) // graph.FillRectangle( brsh, new RectangleF(recVal.X+((recVal.Width-sz.Width)/2),recVal.Y+((recVal.Height-sz.Height)/2),sz.Width+4,sz.Height) ); //graph.DrawString(item.Value.ToString("#,###.##"), valFont, brsFont, recVal, sfFormat); for (int box = -1; box <= 1; ++box) { for (int boy = -1; boy <= 1; ++boy) { if (box == 0 && boy == 0) { continue; } RectangleF rco = new RectangleF(recVal.X + box, recVal.Y + boy, recVal.Width, recVal.Height); graph.DrawString(item.Value.ToString("#,###.##"), valFont, whiteBrsh, rco, sfFormat); } } graph.DrawString(item.Value.ToString("#,###.##"), valFont, brsFont, recVal, sfFormat); } } i++; } } if (_renderMode == BarGraphRenderMode.Lines) { if (linePoints.Length >= 2) { using (Pen linePen = new Pen(Color.FromArgb(220, Color.Red), 2.5f)) graph.DrawCurve(linePen, linePoints, 0.5f); } using (Pen linePen = new Pen(Color.FromArgb(40, _fontColor), 0.8f)) { for (int j = 0; j < linePoints.Length; ++j) { graph.DrawLine(linePen, linePoints[j], new PointF(linePoints[j].X, _yOrigin + _graphHeight)); DataItem item = DataPoints[j]; float itemY = _yOrigin + _graphHeight - item.SweepSize; // Draw data value if (_displayBarData && (j % _interval) == 0) { graph.FillEllipse(brsFont, new RectangleF(linePoints[j].X - 2.0f, linePoints[j].Y - 2.0f, 4.0f, 4.0f)); float sectionWidth = (_barWidth + _spaceBtwBars); float startX = _xOrigin + (j * sectionWidth) + (sectionWidth / 2); // This draws the value on center of the bar float startY = itemY - 2f - valFont.Height; // Positioned on top of each bar by 2 pixels RectangleF recVal = new RectangleF(startX - ((sectionWidth * _interval) / 2), startY, sectionWidth * _interval, valFont.Height); SizeF sz = graph.MeasureString(item.Value.ToString("#,###.##"), valFont, recVal.Size, sfFormat); //using ( SolidBrush brsh = new SolidBrush( Color.FromArgb( 48, 255, 255, 255 ) ) ) // graph.FillRectangle( brsh, new RectangleF(recVal.X+((recVal.Width-sz.Width)/2),recVal.Y+((recVal.Height-sz.Height)/2),sz.Width+4,sz.Height) ); for (int box = -1; box <= 1; ++box) { for (int boy = -1; boy <= 1; ++boy) { if (box == 0 && boy == 0) { continue; } RectangleF rco = new RectangleF(recVal.X + box, recVal.Y + boy, recVal.Width, recVal.Height); graph.DrawString(item.Value.ToString("#,###.##"), valFont, whiteBrsh, rco, sfFormat); } } graph.DrawString(item.Value.ToString("#,###.##"), valFont, brsFont, recVal, sfFormat); } } } } } } } finally { if (brsFont != null) { brsFont.Dispose(); } if (valFont != null) { valFont.Dispose(); } if (sfFormat != null) { sfFormat.Dispose(); } } }
void ResetColor(Label color, Control edit) { EditLineState newState = color.Tag as EditLineState; if (newState == null) { color.BackColor = this._tableLayoutPanel_main.BackColor; return; } if (newState.Active == true) { if (this.ContainsFocus == true) { color.BackColor = SystemColors.Highlight; Color focus_color = this.FocusedEditBackColor; if (edit != null && edit.BackColor != focus_color) { edit.BackColor = focus_color; } return; } else { if (this.m_bHideSelection == false) { color.BackColor = ControlPaint.Dark(SystemColors.Highlight); Color focus_color = ControlPaint.Light(this.FocusedEditBackColor); if (edit != null && edit.BackColor != focus_color) { edit.BackColor = focus_color; } return; } } } #if NO // 恢复原来的颜色 if (edit != null && edit.Tag != null) { Color back_color = (Color)edit.Tag; if (edit.BackColor != back_color) { edit.BackColor = back_color; } } #endif if (edit != null) { if (edit is TextBox) { TextBox textbox = edit as TextBox; if (textbox.ReadOnly == true && this.BackColor != Color.Transparent) { textbox.BackColor = this.BackColor; } else { edit.BackColor = _editBackColor; } } else { edit.BackColor = _editBackColor; } } if (newState.Changed == true) { color.BackColor = this.ColorChanged; } else { color.BackColor = this._tableLayoutPanel_main.BackColor; } }
private void Draw3DLine(Graphics g, Point x, Point y, BorderStyle3D style, Color baseColor, Color border) { Color color = ControlPaint.Light(baseColor, 0.4f); Color color2 = ControlPaint.LightLight(baseColor); Color color3 = ControlPaint.Dark(baseColor, 0.2f); Color color4 = ControlPaint.Dark(baseColor, 0.6f); Pen pen = new Pen(color); switch (style) { case BorderStyle3D.Default: case BorderStyle3D.Flat: pen.Color = (border == Color.Empty) ? baseColor : border; g.DrawLine(pen, x, y); break; case BorderStyle3D.Raised: Draw3DLine(g, x, y, BorderStyle3D.RaisedOuter, baseColor, border); x.Offset(-1, -1); y.Offset(-1, -1); Draw3DLine(g, x, y, BorderStyle3D.RaisedInner, baseColor, border); break; case BorderStyle3D.RaisedInner: if (x.X == y.Y) { g.DrawLine(pen, x, y); } else { pen.Color = color3; g.DrawLine(pen, x, y); } break; case BorderStyle3D.RaisedOuter: if (x.X == y.Y) { pen.Color = color2; g.DrawLine(pen, x, y); } else { pen.Color = color4; g.DrawLine(pen, x, y); } break; case BorderStyle3D.Sunken: Draw3DLine(g, x, y, BorderStyle3D.SunkenOuter, baseColor, border); x.Offset(-1, -1); y.Offset(-1, -1); Draw3DLine(g, x, y, BorderStyle3D.SunkenInner, baseColor, border); break; case BorderStyle3D.SunkenInner: if (x.X == y.Y) { pen.Color = color4; g.DrawLine(pen, x, y); } else { pen.Color = color; g.DrawLine(pen, x, y); } break; case BorderStyle3D.SunkenOuter: if (x.X == y.Y) { pen.Color = color3; g.DrawLine(pen, x, y); } else { pen.Color = color2; g.DrawLine(pen, x, y); } break; case BorderStyle3D.Etched: Draw3DLine(g, x, y, BorderStyle3D.SunkenOuter, baseColor, border); x.Offset(-1, -1); y.Offset(-1, -1); Draw3DLine(g, x, y, BorderStyle3D.RaisedInner, baseColor, border); break; case BorderStyle3D.Bump: Draw3DLine(g, x, y, BorderStyle3D.RaisedOuter, baseColor, border); x.Offset(-1, -1); y.Offset(-1, -1); Draw3DLine(g, x, y, BorderStyle3D.SunkenInner, baseColor, border); break; case BorderStyle3D.RaisedFrame: Draw3DLine(g, x, y, BorderStyle3D.Raised, baseColor, border); x.Offset(-2, -2); y.Offset(-2, -2); Draw3DLine(g, x, y, BorderStyle3D.Sunken, baseColor, border); break; } pen.Dispose(); }
protected override void OnPaint(PaintEventArgs e) { Size ourSize = this.ClientSize; Point[] light = new Point[4]; Point[] dark = new Point[4]; // Depends on orientation if (_dockLeft) { int iBottom = ourSize.Height - _inset - 1; int iRight = _offset + 2; int iTop = _inset + _buttonOffset; light[3].X = light[2].X = light[0].X = _offset; light[2].Y = light[1].Y = light[0].Y = iTop; light[1].X = _offset + 1; light[3].Y = iBottom; dark[2].X = dark[1].X = dark[0].X = iRight; dark[3].Y = dark[2].Y = dark[1].Y = iBottom; dark[0].Y = iTop; dark[3].X = iRight - 1; } else { int iBottom = _offset + 2; int iRight = ourSize.Width - (_inset + _buttonOffset); light[3].X = light[2].X = light[0].X = _inset; light[1].Y = light[2].Y = light[0].Y = _offset; light[1].X = iRight; light[3].Y = _offset + 1; dark[2].X = dark[1].X = dark[0].X = iRight; dark[3].Y = dark[2].Y = dark[1].Y = iBottom; dark[0].Y = _offset; dark[3].X = _inset; } using (Pen lightPen = new Pen(ControlPaint.LightLight(_manager.BackColor)), darkPen = new Pen(ControlPaint.Dark(_manager.BackColor))) { e.Graphics.DrawLine(lightPen, light[0], light[1]); e.Graphics.DrawLine(lightPen, light[2], light[3]); e.Graphics.DrawLine(darkPen, dark[0], dark[1]); e.Graphics.DrawLine(darkPen, dark[2], dark[3]); // Shift coordinates to draw section grab bar if (_dockLeft) { for (int i = 0; i < 4; i++) { light[i].X += 4; dark[i].X += 4; } } else { for (int i = 0; i < 4; i++) { light[i].Y += 4; dark[i].Y += 4; } } e.Graphics.DrawLine(lightPen, light[0], light[1]); e.Graphics.DrawLine(lightPen, light[2], light[3]); e.Graphics.DrawLine(darkPen, dark[0], dark[1]); e.Graphics.DrawLine(darkPen, dark[2], dark[3]); } base.OnPaint(e); }
///-------------------------------------------------------------------------------------------------- /// <summary> Paints the area. </summary> /// <remarks> Oscvic, 2016-01-18. </remarks> /// <param name="e"> Paint event information. </param> /// <param name="filter"> Specifies the filter. </param> /// <param name="StartColor"> The start color. </param> /// <param name="EndColor"> The end color. </param> /// <param name="invertDark"> true to invert dark. </param> ///-------------------------------------------------------------------------------------------------- private (Brush, Pen) GetBrushAndPen() { Pen pen = null; Brush brush = null; if (UseGradient) { /* Start and end color of the gradient */ Color StartColor = BackColor; Color EndColor = AltGradientColor; /* If pressed, we swap end and start, then we Dark/Light it because it represents the end of the linear and we want our color more near the center */ StartColor = (Pressed) ? ControlPaint.Dark(StartColor, PercentageOfDark) : StartColor; EndColor = (Pressed) ? ControlPaint.Light(StartColor, PercentageOfLight) : ControlPaint.Dark(EndColor, PercentageOfDark); /* If Hover, we Light it a bit. */ if (Hover) { StartColor = ControlUtils.ChangeColorBrightness(StartColor, PercentageForHover); EndColor = ControlUtils.ChangeColorBrightness(EndColor, PercentageForHover); } brush = new LinearGradientBrush( new Point(this.Width / 2, (Pressed) ? -(this.Height / 2) : 0), new Point(this.Width / 2, this.Height + ((Pressed) ? 0 : this.Height / 2)), StartColor, EndColor); pen = new Pen((Pressed) ? StartColor : EndColor); } else { Color color = BackColor; if (Pressed) { color = ControlUtils.ChangeColorBrightness(color, -PercentageForPressed); } else if (Hover) { color = ControlUtils.ChangeColorBrightness(color, PercentageForHover); } else { color = BackColor; } brush = new SolidBrush(color); pen = new Pen(color); } return(brush, pen); //using (LinearGradientBrush brush = ) // e.Graphics.FillRoundedRectangle(brush, 0, 0, this.Width - 1, this.Height, Radius, filter); //using (Pen pen = new Pen((invertDark) ? StartColor : EndColor)) // e.Graphics.DrawRoundedRectangle(pen, 0, 0, this.Width - 1, this.Height - 1, Radius, filter); }
protected override void OnDrawItem(int item, int column, Graphics g, Rectangle rec) { InterfaceFile file = (InterfaceFile)(Items[item].Tag); LinearGradientBrush chunkBrush; int xpos = rec.Left; Color b = Color.Red; Color end; if (file.UploadChunksAvaibility == null) { try { // calculate the new end color based on start color end = ControlPaint.Dark(b, 0.3F); // generate the linear brush chunkBrush = new LinearGradientBrush(new Rectangle(xpos, rec.Top, rec.Right - xpos, rec.Height), b, end, 90); g.FillRectangle(chunkBrush, xpos, rec.Top, rec.Right - xpos, rec.Height); //draw a backcolor margin g.FillRectangle(new SolidBrush(this.BackColor), rec.X, rec.Bottom - 1, rec.Width, 1); } catch (Exception e) { Debug.WriteLine(e.ToString()); } return; } int ChunkLength; for (int i = 0; i < file.UploadChunksAvaibility.Length; i++) { ChunkLength = (int)Decimal.Round((decimal)(this.HeaderRight[column] - xpos) / (decimal)(file.UploadChunksAvaibility.Length - i), 0); b = Color.Red; if ((file.UploadChunksAvaibility != null) && (file.UploadChunksAvaibility[i] > 0)) { int col = file.UploadChunksAvaibility[i] * 4; if (col > 200) { col = 200; } col = Math.Abs(200 - col); b = Color.FromArgb(255, col, col, 255); } try { // calculate the new end color based on start color if (ChunkLength <= 0) { continue; } end = ControlPaint.Dark(b, 0.3F); // generate the linear brush chunkBrush = new LinearGradientBrush(new Rectangle(xpos, rec.Top, ChunkLength, rec.Height), b, end, 90); g.FillRectangle(chunkBrush, xpos, rec.Top, ChunkLength, rec.Height); //draw a backcolor margin, TODO it produces some flickering g.FillRectangle(new SolidBrush(this.BackColor), rec.X, rec.Bottom - 1, rec.Width, 1); } catch (Exception e) { Debug.WriteLine(e.ToString()); } xpos += ChunkLength; } }
/// <summary> /// Lighten or darken a color, ratio + to lighten, - to darken /// </summary> public static string ModifyColorLuminosity(this string htmlColor, float ratio) { var color = ColorTranslator.FromHtml(htmlColor); return(ColorTranslator.ToHtml(ratio > 0 ? ControlPaint.Light(color, ratio) : ControlPaint.Dark(color, ratio))); /* * var isBlack = color.R == 0 && color.G == 0 && color.B == 0; * var red = (int)Math.Min(Math.Max(0, color.R + ((isBlack ? 255 : color.R) * ratio)), 255); * var green = (int)Math.Min(Math.Max(0, color.G + ((isBlack ? 255 : color.G) * ratio)), 255); * var blue = (int)Math.Min(Math.Max(0, color.B + ((isBlack ? 255 : color.B) * ratio)), 255); * return ColorTranslator.ToHtml(Color.FromArgb(red, green, blue)); */ }
/// <summary> /// Perform rendering before child elements are rendered. /// </summary> /// <param name="context">Rendering context.</param> public override void RenderBefore(RenderContext context) { // Office 2010 draws a shadow effect of the text if ((_ribbon.RibbonShape == PaletteRibbonShape.Office2010) && (_mementoContentShadow1 != null)) { PaletteState state = (_ribbon.Enabled ? PaletteState.Normal : PaletteState.Disabled); // Use renderer to draw the tab background _mementoBack = context.Renderer.RenderRibbon.DrawRibbonTabContextTitle(_ribbon.RibbonShape, context, ClientRectangle, _ribbon.StateCommon.RibbonGeneral, this, _mementoBack); Rectangle shadowTextRect1 = new Rectangle(_textRect.X - 1, _textRect.Y + 1, _textRect.Width, _textRect.Height); Rectangle shadowTextRect2 = new Rectangle(_textRect.X + 1, _textRect.Y + 1, _textRect.Width, _textRect.Height); _contentProvider.OverrideTextColor = Color.FromArgb(128, ControlPaint.Dark(GetRibbonBackColor1(PaletteState.Normal))); if (DrawOnComposition) { _contentProvider.OverrideTextHint = PaletteTextHint.SingleBitPerPixelGridFit; } context.Renderer.RenderStandardContent.DrawContent(context, shadowTextRect1, _contentProvider, _mementoContentShadow1, VisualOrientation.Top, state, false, true); context.Renderer.RenderStandardContent.DrawContent(context, shadowTextRect1, _contentProvider, _mementoContentShadow2, VisualOrientation.Top, state, false, true); _contentProvider.OverrideTextColor = Color.Empty; // Use renderer to draw the text content if (_mementoContentText != null) { context.Renderer.RenderStandardContent.DrawContent(context, _textRect, _contentProvider, _mementoContentText, VisualOrientation.Top, state, false, true); } _contentProvider.OverrideTextHint = PaletteTextHint.Inherit; } else { if (DrawOnComposition) { RenderOnComposition(context); } else { PaletteState state = (_ribbon.Enabled ? PaletteState.Normal : PaletteState.Disabled); // Use renderer to draw the tab background _mementoBack = context.Renderer.RenderRibbon.DrawRibbonTabContextTitle(_ribbon.RibbonShape, context, ClientRectangle, _ribbon.StateCommon.RibbonGeneral, this, _mementoBack); // Use renderer to draw the text content if (_mementoContentText != null) { context.Renderer.RenderStandardContent.DrawContent(context, _textRect, _contentProvider, _mementoContentText, VisualOrientation.Top, state, DrawOnComposition, true); } } } }
// Token: 0x06002DE4 RID: 11748 RVA: 0x00016150 File Offset: 0x00014350 private void method_0() { this.DarkColor = ControlPaint.Dark(this.color_0); this.DarkDarkColor = ControlPaint.DarkDark(this.color_0); }
protected override void OnPaint(System.Windows.Forms.PaintEventArgs e) { // // Calculate matching colors // Color darkColor = ControlPaint.Dark(_BarColor); Color bgColor = ControlPaint.Dark(_BarColor); // // Fill background // SolidBrush bgBrush = new SolidBrush(bgColor); e.Graphics.FillRectangle(bgBrush, this.ClientRectangle); bgBrush.Dispose(); // // Check for value // if (_Maximum == _Minimum || _Value == 0) { // Draw border only and exit; drawBorder(e.Graphics); return; } // // The following is the width of the bar. This will vary with each value. // int fillWidth = (this.Width * _Value) / (_Maximum - _Minimum); // // GDI+ doesn't like rectangles 0px wide or high // if (fillWidth == 0) { // Draw border only and exti; drawBorder(e.Graphics); return; } // // Rectangles for upper and lower half of bar // Rectangle topRect = new Rectangle(0, 0, fillWidth, this.Height / 2); Rectangle buttomRect = new Rectangle(0, this.Height / 2, fillWidth, this.Height / 2); // // The gradient brush // LinearGradientBrush brush; // // Paint upper half // brush = new LinearGradientBrush(new Point(0, 0), new Point(0, this.Height / 2), darkColor, _BarColor); e.Graphics.FillRectangle(brush, topRect); brush.Dispose(); // // Paint lower half // (this.Height/2 - 1 because there would be a dark line in the middle of the bar) // brush = new LinearGradientBrush(new Point(0, this.Height / 2 - 1), new Point(0, this.Height), _BarColor, darkColor); e.Graphics.FillRectangle(brush, buttomRect); brush.Dispose(); // // Calculate separator's setting // int sepWidth = (int)(this.Height * .67); int sepCount = (int)(fillWidth / sepWidth); Color sepColor = ControlPaint.LightLight(_BarColor); // // Paint separators // switch (_FillStyle) { case FillStyles.Dashed: // Draw each separator line for (int i = 1; i <= sepCount; i++) { e.Graphics.DrawLine(new Pen(sepColor, 1), sepWidth * i, 0, sepWidth * i, this.Height); } break; case FillStyles.Solid: // Draw nothing break; default: break; } // // Draw border and exit // drawBorder(e.Graphics); }
protected override void OnPaintAdornments(PaintEventArgs pe) { ZoomPictureBox pb = (ZoomPictureBox)base.Component; if (pb.BorderStyle == BorderStyle.None) { Graphics g = pe.Graphics; Rectangle clientRectangle = pb.ClientRectangle; Color color = pb.BackColor.GetBrightness() < 0.5 ? ControlPaint.Light(pb.BackColor) : ControlPaint.Dark(pb.BackColor); using (Pen pen = new Pen(color) { DashStyle = DashStyle.Dash }) { clientRectangle.Width--; clientRectangle.Height--; g.DrawRectangle(pen, clientRectangle); } } base.OnPaintAdornments(pe); }
public void ControlPaint_DrawBorder_OutSet_Rendering() { using var emf = new EmfScope(); DeviceContextState state = new DeviceContextState(emf); using Graphics graphics = Graphics.FromHdc((IntPtr)emf.HDC); Rectangle bounds = new Rectangle(10, 10, 10, 10); ControlPaint.DrawBorder(graphics, bounds, Color.PeachPuff, ButtonBorderStyle.Outset); string dump = emf.RecordsToStringWithState(state); // For whatever reason GDI+ renders as polylines scaled 16x with a 1/16th world transform applied. // For test readability we'll transform the points from our coordinates to the logical coordinates. Matrix3x2 oneSixteenth = Matrix3x2.CreateScale(0.0625f); Matrix3x2 times16 = Matrix3x2.CreateScale(16.0f); // This is the default pen style GDI+ renders polylines with Gdi32.PS penStyle = Gdi32.PS.SOLID | Gdi32.PS.JOIN_ROUND | Gdi32.PS.COSMETIC | Gdi32.PS.ENDCAP_FLAT | Gdi32.PS.JOIN_MITER | Gdi32.PS.GEOMETRIC; emf.Validate( state, // Top Validate.Polyline16( bounds: null, PointArray(times16, 10, 10, 19, 10), State.Pen(16, ControlPaint.LightLight(Color.PeachPuff), penStyle), State.Transform(oneSixteenth)), // Left Validate.Polyline16( bounds: null, PointArray(times16, 10, 10, 10, 19), State.Pen(16, ControlPaint.LightLight(Color.PeachPuff), penStyle), State.Transform(oneSixteenth)), // Bottom Validate.Polyline16( bounds: null, PointArray(times16, 10, 19, 19, 19), State.Pen(16, ControlPaint.DarkDark(Color.PeachPuff), penStyle), State.Transform(oneSixteenth)), // Right Validate.Polyline16( bounds: null, PointArray(times16, 19, 10, 19, 19), State.Pen(16, ControlPaint.DarkDark(Color.PeachPuff), penStyle), State.Transform(oneSixteenth)), // Top inset Validate.Polyline16( bounds: null, PointArray(times16, 11, 11, 18, 11), State.Pen(16, Color.PeachPuff, penStyle), State.Transform(oneSixteenth)), // Left inset Validate.Polyline16( bounds: null, PointArray(times16, 11, 11, 11, 18), State.Pen(16, Color.PeachPuff, penStyle), State.Transform(oneSixteenth)), // Bottom inset Validate.Polyline16( bounds: null, PointArray(times16, 11, 18, 18, 18), State.Pen(16, ControlPaint.Dark(Color.PeachPuff), penStyle), State.Transform(oneSixteenth)), // Right inset Validate.Polyline16( bounds: null, PointArray(times16, 18, 11, 18, 18), State.Pen(16, ControlPaint.Dark(Color.PeachPuff), penStyle), State.Transform(oneSixteenth))); }
static void Main(string[] args) { InitializeRulesAndAxioms(); Random rand = new Random(); var pathToNames = @"C:\Users\Ragnus\Desktop\PI\Fractal\FractalPro\Fractal\emails.csv"; using (TextFieldParser ParserCsv = new TextFieldParser(pathToNames)) { ParserCsv.CommentTokens = new string[] { "#" }; ParserCsv.SetDelimiters(new string[] { ",", "'", }); ParserCsv.HasFieldsEnclosedInQuotes = true; ParserCsv.ReadLine(); while (!ParserCsv.EndOfData) { string[] entites = ParserCsv.ReadFields(); //To make sure i will not get all 60000 records select only words starting with given words emails.Add(entites[0]); } } Stopwatch stopwatch = new Stopwatch(); stopwatch.Start(); decimal allpoints = 0; int ccounter = 0; StringBuilder sB = new StringBuilder(); foreach (var email in emails) { Console.WriteLine(ccounter); ccounter++; sB = new StringBuilder(); bool shouldGetFromRuleList = rand.NextDouble() < 0.3; //30% for user to get rule from list == nice image but repetable string emailOfUser = email; string hash = ""; using (MD5 md5 = MD5.Create()) { hash = GetMd5Hash(md5, emailOfUser); } var source = hash.GetHashCode(); int iterationOfFractal = source & 7; if (iterationOfFractal <= 1) { iterationOfFractal = 2; } string axiom = ""; string rule = ""; if (shouldGetFromRuleList) { int index = source & 15; if (index > 12) { index = 12; } int bitEle = (source >> 4) & 15; bitEle = bitEle > 10 ? 10 : bitEle; var getElement = axiomAndRules[bitEle]; axiom = getElement.Key; rule = getElement.Value; } else { int amountForAxiom = (source & 3) + 1; //get next 3 bits do & operation on it and add since (since number will be from 0 to 3 and we want from 1 to 4 int amountForRule = 0; switch (iterationOfFractal) { case 1: amountForRule = 30; break; case 2: amountForRule = 25; break; case 3: amountForRule = 21; break; case 4: amountForRule = 17; break; case 5: amountForRule = 11; break; case 6: amountForRule = 9; break; case 7: amountForRule = 7; break; } axiom = GenerateContent(axiom, amountForAxiom, rand); if (!axiom.Contains('F')) { if (axiom.Length >= 2) { axiom = axiom.Remove(1, 1).Insert(1, "F"); } else { axiom += "F"; } } //generate rule rule = GenerateContent(rule, amountForRule, rand); } for (int i = 0; i <= iterationOfFractal; i++) { for (int y = 0; y < axiom.Length; y++) { if (char.IsLetter(axiom[y])) { sB.Append(rule); } else { sB.Append(axiom[y]); } } axiom = sB.ToString(); if (axiom.Length >= 10000000) { break; } sB = new StringBuilder(); } if (axiom.Length >= 8500000) { //Take 7000000 from end to end - 700000 Random rnd = new Random(); int numToTake = rnd.Next(3000000, 6000000); var smallerInitialString = axiom.Substring(axiom.Length - numToTake, numToTake); axiom = smallerInitialString; } Bitmap mainImage = new Bitmap(1000, 1000); float currentX = 500; float currentY = 500; float iterate = 10; int longWidth = (source >> 8) & 1; if (longWidth > 1) { longWidth = rand.Next(20, 30); } else { longWidth = rand.Next(2, 13); } int widthOfPen = 3; GraphicsPath gP; var color1 = int.Parse(hash.Substring(0, 2), System.Globalization.NumberStyles.HexNumber); var color2 = int.Parse(hash.Substring(2, 2), System.Globalization.NumberStyles.HexNumber); var color3 = int.Parse(hash.Substring(4, 2), System.Globalization.NumberStyles.HexNumber); Color foreGround = Color.FromArgb(color1, color2, color3); foreGround = ControlPaint.Dark(foreGround, 50); var color4 = int.Parse(hash.Substring(6, 2), System.Globalization.NumberStyles.HexNumber); var color5 = int.Parse(hash.Substring(8, 2), System.Globalization.NumberStyles.HexNumber); var color6 = int.Parse(hash.Substring(10, 2), System.Globalization.NumberStyles.HexNumber); Color backGround = Color.FromArgb(color4, color5, color6); backGround = ControlPaint.Light(foreGround, 25); if (foreGround.ToArgb() == backGround.ToArgb()) { foreGround = Color.Red; backGround = Color.Black; } if (foreGround.R == backGround.R || foreGround.G == backGround.G || foreGround.B == backGround.B) { if (foreGround.R == backGround.R) { color2 = color2 - 50 < 0 ? 0 : color2 + 50; color3 = color3 - 50 < 0 ? 0 : color3 - 50; foreGround = Color.FromArgb(color1, color2, color3); foreGround = ControlPaint.Dark(foreGround, 50); color5 = color5 + 50 > 260 ? 260 : color5 + 50; color6 = color6 + 50 > 260 ? 260 : color6 + 50; backGround = Color.FromArgb(color4, color5, color6); backGround = ControlPaint.Light(foreGround, 25); } else if (foreGround.G == backGround.G) { color1 = color1 - 50 < 0 ? 0 : color1 + 50; color3 = color3 - 50 < 0 ? 0 : color3 - 50; foreGround = Color.FromArgb(color1, color2, color3); foreGround = ControlPaint.Dark(foreGround, 50); color4 = color4 + 50 > 260 ? 260 : color4 + 50; color6 = color6 + 50 > 260 ? 260 : color6 + 50; backGround = Color.FromArgb(color4, color5, color6); backGround = ControlPaint.Light(foreGround, 25); } else if (foreGround.B == backGround.B) { color1 = color1 - 50 < 0 ? 0 : color1 + 50; color2 = color2 - 50 < 0 ? 0 : color2 - 50; foreGround = Color.FromArgb(color1, color2, color3); foreGround = ControlPaint.Dark(foreGround, 50); color4 = color4 + 50 > 260 ? 260 : color4 + 50; color5 = color5 + 50 > 260 ? 260 : color5 + 50; backGround = Color.FromArgb(color4, color5, color6); backGround = ControlPaint.Light(foreGround, 25); } } gP = new GraphicsPath(); for (int i = 0; i < axiom.Length; i++) { if (char.IsLetter(axiom[i])) { for (int iA = 0; iA < iterateAxis.Length; iA++) { //up if (iA == 0 && iterateAxis[iA]) { gP.AddLine(currentX, currentY, currentX, currentY - iterate); currentY -= iterate; } //right else if (iA == 1 && iterateAxis[iA]) { gP.AddLine(currentX, currentY, currentX + iterate, currentY); currentX += iterate; } //down else if (iA == 2 && iterateAxis[iA]) { gP.AddLine(currentX, currentY, currentX, currentY + iterate); currentY += iterate; } //left else if (iA == 3 && iterateAxis[iA]) { gP.AddLine(currentX, currentY, currentX - iterate, currentY); currentX -= iterate; } } } else if (axiom[i] == '+') { changeAxis(false); } else if (axiom[i] == '-') { changeAxis(true); } } var T = GetMatrixFitRectInBounds(gP.GetBounds(), new RectangleF(0, 0, mainImage.Width, mainImage.Height)); gP.Transform(T); Console.WriteLine("amount of points is " + gP.PointCount); using (Graphics g = Graphics.FromImage(mainImage)) { g.Clear(backGround); g.DrawPath(new Pen(foreGround, widthOfPen), gP); } allpoints += gP.PointCount; mainImage.Save(@"C:\Users\Ragnus\Desktop\PI\Fractal\FractalPro\Fractal\" + ccounter + ".jpg"); } stopwatch.Stop(); Console.WriteLine("Time needed to generate " + emails.Count + " is " + stopwatch.Elapsed.Seconds + " seconds." + Environment.NewLine + " Amount of draw points was " + allpoints); }
///-------------------------------------------------------------------------------------------------- /// <summary> Paints the area. </summary> /// <remarks> Oscvic, 2016-01-18. </remarks> /// <param name="e"> Paint event information. </param> /// <param name="filter"> Specifies the filter. </param> /// <param name="StartColor"> The start color. </param> /// <param name="EndColor"> The end color. </param> /// <param name="invertDark"> true to invert dark. </param> ///-------------------------------------------------------------------------------------------------- private void PaintArea(PaintEventArgs e, RectangleEdgeFilter filter, Color StartColor, Color EndColor, Boolean invertDark) { StartColor = (invertDark) ? ControlPaint.Dark(StartColor, PercentageOfDark) : StartColor; EndColor = (invertDark) ? ControlPaint.Light(StartColor, PercentageOfLight) : ControlPaint.Dark(EndColor, PercentageOfDark); using (LinearGradientBrush brush = new LinearGradientBrush( new Point(this.Width / 2, (invertDark) ? -(this.Height / 2) : 0), new Point(this.Width / 2, this.Height + ((invertDark) ? 0 : this.Height / 2)), StartColor, EndColor)) e.Graphics.FillRoundedRectangle(brush, 0, 0, this.Width - 1, this.Height, Radius, filter); using (Pen pen = new Pen((invertDark) ? StartColor : EndColor)) e.Graphics.DrawRoundedRectangle(pen, 0, 0, this.Width - 1, this.Height - 1, Radius, filter); }
protected void DrawOutline(Graphics g, bool pre) { Rectangle borderRect = new Rectangle(0, 0, this.Width - 1, this.Height - 1); // Adjust for drawing area switch (_edge) { case Edge.Left: borderRect.Y += _beginGap; borderRect.Height -= _beginGap + _endGap - 1; borderRect.Width -= _sideGap; break; case Edge.Right: borderRect.Y += _beginGap; borderRect.Height -= _beginGap + _endGap - 1; borderRect.X += _sideGap; borderRect.Width -= _sideGap; break; case Edge.Bottom: borderRect.Y += _sideGap; borderRect.Height -= _sideGap; borderRect.X += _beginGap; borderRect.Width -= _beginGap + _endGap - 1; break; case Edge.Top: case Edge.None: default: borderRect.Height -= _sideGap; borderRect.X += _beginGap; borderRect.Width -= _beginGap + _endGap - 1; break; } // Remove unwated drawing edge AdjustRectForEdge(ref borderRect); if (pre) { if (_style == VisualStyle.IDE) { // Fill tab area in required color using (SolidBrush fillBrush = new SolidBrush(this.BackColor)) g.FillRectangle(fillBrush, borderRect); } } else { if (_style == VisualStyle.Plain) { using (Pen penL = new Pen(ControlPaint.LightLight(this.BackColor)), penD = new Pen(ControlPaint.Dark(this.BackColor))) { g.DrawLine(penL, borderRect.Left, borderRect.Top, borderRect.Right, borderRect.Top); g.DrawLine(penL, borderRect.Left, borderRect.Top, borderRect.Left, borderRect.Bottom); g.DrawLine(penD, borderRect.Right, borderRect.Top, borderRect.Right, borderRect.Bottom); g.DrawLine(penD, borderRect.Right, borderRect.Bottom, borderRect.Left, borderRect.Bottom); } } } }
/// <summary> /// Draws the colorslider control using passed colors. /// </summary> /// <param name="e">The <see cref="T:System.Windows.Forms.PaintEventArgs"/> instance containing the event data.</param> /// <param name="thumbOuterColorPaint">The thumb outer color paint.</param> /// <param name="thumbInnerColorPaint">The thumb inner color paint.</param> /// <param name="thumbPenColorPaint">The thumb pen color paint.</param> /// <param name="barOuterColorPaint">The bar outer color paint.</param> /// <param name="barInnerColorPaint">The bar inner color paint.</param> /// <param name="barPenColorPaint">The bar pen color paint.</param> /// <param name="elapsedOuterColorPaint">The elapsed outer color paint.</param> /// <param name="elapsedInnerColorPaint">The elapsed inner color paint.</param> private void DrawColorSlider(PaintEventArgs e, Color thumbOuterColorPaint, Color thumbInnerColorPaint, Color thumbPenColorPaint, Color barOuterColorPaint, Color barInnerColorPaint, Color barPenColorPaint, Color elapsedOuterColorPaint, Color elapsedInnerColorPaint) { try { //set up thumbRect aproprietly if (barOrientation == Orientation.Horizontal) { int TrackX = (((trackerValue - barMinimum) * (ClientRectangle.Width - thumbSize)) / (barMaximum - barMinimum)); thumbRect = new Rectangle(TrackX, 1, thumbSize - 1, ClientRectangle.Height - 3); } else { int TrackY = (((trackerValue - barMinimum) * (ClientRectangle.Height - thumbSize)) / (barMaximum - barMinimum)); thumbRect = new Rectangle(1, TrackY, ClientRectangle.Width - 3, thumbSize - 1); } //adjust drawing rects barRect = ClientRectangle; thumbHalfRect = thumbRect; LinearGradientMode gradientOrientation; if (barOrientation == Orientation.Horizontal) { barRect.Inflate(-1, -barRect.Height / 3); barHalfRect = barRect; barHalfRect.Height /= 2; gradientOrientation = LinearGradientMode.Vertical; thumbHalfRect.Height /= 2; elapsedRect = barRect; elapsedRect.Width = thumbRect.Left + thumbSize / 2; } else { barRect.Inflate(-barRect.Width / 3, -1); barHalfRect = barRect; barHalfRect.Width /= 2; gradientOrientation = LinearGradientMode.Horizontal; thumbHalfRect.Width /= 2; elapsedRect = barRect; elapsedRect.Height = thumbRect.Top + thumbSize / 2; } //get thumb shape path GraphicsPath thumbPath; if (thumbCustomShape == null) { thumbPath = CreateRoundRectPath(thumbRect, thumbRoundRectSize); } else { thumbPath = thumbCustomShape; Matrix m = new Matrix(); m.Translate(thumbRect.Left - thumbPath.GetBounds().Left, thumbRect.Top - thumbPath.GetBounds().Top); thumbPath.Transform(m); } //draw bar using ( LinearGradientBrush lgbBar = new LinearGradientBrush(barHalfRect, barOuterColorPaint, barInnerColorPaint, gradientOrientation) ) { lgbBar.WrapMode = WrapMode.TileFlipXY; e.Graphics.FillRectangle(lgbBar, barRect); //draw elapsed bar using ( LinearGradientBrush lgbElapsed = new LinearGradientBrush(barHalfRect, elapsedOuterColorPaint, elapsedInnerColorPaint, gradientOrientation)) { lgbElapsed.WrapMode = WrapMode.TileFlipXY; if (Capture && drawSemitransparentThumb) { Region elapsedReg = new Region(elapsedRect); elapsedReg.Exclude(thumbPath); e.Graphics.FillRegion(lgbElapsed, elapsedReg); } else { e.Graphics.FillRectangle(lgbElapsed, elapsedRect); } } //draw bar band using (Pen barPen = new Pen(barPenColorPaint, 0.5f)) { e.Graphics.DrawRectangle(barPen, barRect); } } //draw thumb Color newthumbOuterColorPaint = thumbOuterColorPaint, newthumbInnerColorPaint = thumbInnerColorPaint; if (Capture && drawSemitransparentThumb) { newthumbOuterColorPaint = Color.FromArgb(175, thumbOuterColorPaint); newthumbInnerColorPaint = Color.FromArgb(175, thumbInnerColorPaint); } using ( LinearGradientBrush lgbThumb = new LinearGradientBrush(thumbHalfRect, newthumbOuterColorPaint, newthumbInnerColorPaint, gradientOrientation)) { lgbThumb.WrapMode = WrapMode.TileFlipXY; e.Graphics.SmoothingMode = SmoothingMode.AntiAlias; e.Graphics.FillPath(lgbThumb, thumbPath); //draw thumb band Color newThumbPenColor = thumbPenColorPaint; if (mouseEffects && (Capture || mouseInThumbRegion)) { newThumbPenColor = ControlPaint.Dark(newThumbPenColor); } using (Pen thumbPen = new Pen(newThumbPenColor)) { e.Graphics.DrawPath(thumbPen, thumbPath); } //gp.Dispose(); /*if (Capture || mouseInThumbRegion) * using (LinearGradientBrush lgbThumb2 = new LinearGradientBrush(thumbHalfRect, Color.FromArgb(150, Color.Blue), Color.Transparent, gradientOrientation)) * { * lgbThumb2.WrapMode = WrapMode.TileFlipXY; * e.Graphics.FillPath(lgbThumb2, gp); * }*/ } //draw focusing rectangle if (Focused & drawFocusRectangle) { using (Pen p = new Pen(Color.FromArgb(200, barPenColorPaint))) { p.DashStyle = DashStyle.Dot; Rectangle r = ClientRectangle; r.Width -= 2; r.Height--; r.X++; //ControlPaint.DrawFocusRectangle(e.Graphics, r); using (GraphicsPath gpBorder = CreateRoundRectPath(r, borderRoundRectSize)) { e.Graphics.SmoothingMode = SmoothingMode.AntiAlias; e.Graphics.DrawPath(p, gpBorder); } } } } catch (Exception Err) { Console.WriteLine("DrawBackGround Error in " + Name + ":" + Err.Message); } finally { } }
//===================================================================== // Methods, etc /// <summary> /// This is overridden to draw the text and the dividing line /// </summary> /// <param name="e">The event arguments</param> protected override void OnPaint(PaintEventArgs e) { Point pt, pt2; Rectangle r = base.ClientRectangle; SizeF size; Graphics g = e.Graphics; using (StringFormat sf = new StringFormat()) { sf.Trimming = StringTrimming.Character; sf.Alignment = StringAlignment.Near; sf.LineAlignment = StringAlignment.Center; if (this.RightToLeft == RightToLeft.Yes) { sf.FormatFlags |= StringFormatFlags.DirectionRightToLeft; } if (this.UseMnemonic) { sf.HotkeyPrefix = HotkeyPrefix.Show; } size = g.MeasureString(this.Text, this.Font, (SizeF)r.Size, sf); if (base.Enabled) { using (Brush fb = new SolidBrush(this.ForeColor)) { g.DrawString(this.Text, this.Font, fb, (RectangleF)r, sf); } } else { ControlPaint.DrawStringDisabled(g, this.Text, this.Font, this.BackColor, (RectangleF)r, sf); } pt = new Point(r.Left, r.Top + r.Height / 2); pt2 = new Point(r.Right, pt.Y); if (this.RightToLeft == RightToLeft.Yes) { pt2.X -= (int)size.Width; } else { pt.X += (int)size.Width; } using (Pen pb = new Pen(ControlPaint.Dark(this.BackColor), (float)SystemInformation.BorderSize.Height)) { if (base.FlatStyle == FlatStyle.Flat) { g.DrawLine(pb, pt, pt2); } else { using (Pen pf = new Pen( ControlPaint.LightLight(this.BackColor), (float)SystemInformation.BorderSize.Height)) { g.DrawLine(pb, pt, pt2); int offset = (int)Math.Ceiling((double) SystemInformation.BorderSize.Height / 2.0); pt.Offset(0, offset); pt2.Offset(0, offset); g.DrawLine(pf, pt, pt2); } } } } }
/// <summary> /// Raises the Paint event. /// </summary> /// <param name="e">A PaintEventArgs structure contained event data.</param> protected override void OnPaint(PaintEventArgs e) { // Let base class do the standard stuff first base.OnPaint(e); if (_statusPanel != null) { PanelBorder border = _statusPanel.PanelBorder; // Paint border according to requested style switch (border) { case PanelBorder.Sunken: if ((_parent.Style == VisualStyle.Office2003) || (_parent.Style == VisualStyle.IDE2005)) { ControlPaint.DrawBorder(e.Graphics, ClientRectangle, _parent.ColorDetails.MenuSeparatorColor, ButtonBorderStyle.Inset); } else { ControlPaint.DrawBorder(e.Graphics, ClientRectangle, ControlPaint.Light(BackColor), ButtonBorderStyle.Inset); } break; case PanelBorder.Raised: if ((_parent.Style == VisualStyle.Office2003) || (_parent.Style == VisualStyle.IDE2005)) { ControlPaint.DrawBorder(e.Graphics, ClientRectangle, _parent.ColorDetails.MenuSeparatorColor, ButtonBorderStyle.Outset); } else { ControlPaint.DrawBorder(e.Graphics, ClientRectangle, ControlPaint.Light(BackColor), ButtonBorderStyle.Outset); } break; case PanelBorder.Dotted: if (_parent.Style == VisualStyle.IDE) { ControlPaint.DrawBorder(e.Graphics, ClientRectangle, ControlPaint.Light(ControlPaint.Dark(BackColor)), ButtonBorderStyle.Dotted); } else if ((_parent.Style == VisualStyle.Office2003) || (_parent.Style == VisualStyle.IDE2005)) { ControlPaint.DrawBorder(e.Graphics, ClientRectangle, _parent.ColorDetails.MenuSeparatorColor, ButtonBorderStyle.Dotted); } else { ControlPaint.DrawBorder(e.Graphics, ClientRectangle, ControlPaint.Dark(BackColor), ButtonBorderStyle.Dotted); } break; case PanelBorder.Dashed: if (_parent.Style == VisualStyle.IDE) { ControlPaint.DrawBorder(e.Graphics, ClientRectangle, ControlPaint.Light(ControlPaint.Dark(BackColor)), ButtonBorderStyle.Dashed); } else if ((_parent.Style == VisualStyle.Office2003) || (_parent.Style == VisualStyle.IDE2005)) { ControlPaint.DrawBorder(e.Graphics, ClientRectangle, _parent.ColorDetails.MenuSeparatorColor, ButtonBorderStyle.Dashed); } else { ControlPaint.DrawBorder(e.Graphics, ClientRectangle, ControlPaint.Dark(BackColor), ButtonBorderStyle.Dashed); } break; case PanelBorder.Solid: if (_parent.Style == VisualStyle.IDE) { using (Pen borderPen = new Pen(ControlPaint.Light(ControlPaint.Dark(BackColor)))) e.Graphics.DrawRectangle(borderPen, 0, 0, Width - 1, Height - 1); } else if ((_parent.Style == VisualStyle.Office2003) || (_parent.Style == VisualStyle.IDE2005)) { using (Pen borderPen = new Pen(_parent.ColorDetails.MenuSeparatorColor)) e.Graphics.DrawRectangle(borderPen, 0, 0, Width - 1, Height - 1); } else { ControlPaint.DrawBorder(e.Graphics, ClientRectangle, ControlPaint.Dark(BackColor), ButtonBorderStyle.Solid); } break; } } }
/// <summary> /// Event on format cell /// </summary> /// <param name="sender"></param> /// <param name="args"></param> private static void FastOlvOnFormatCell(object sender, FormatCellEventArgs args) { CodeExplorerItem obj = (CodeExplorerItem)args.Model; var curScope = ParserHandler.GetScopeOfLine(Npp.Line.CurrentLine); // currently selected block if (curScope != null && !obj.IsNotBlock && obj.DisplayText.Equals(curScope.Name)) { RowBorderDecoration rbd = new RowBorderDecoration { FillBrush = new SolidBrush(Color.FromArgb(50, ThemeManager.Current.MenuFocusedBack)), BorderPen = new Pen(Color.FromArgb(128, ThemeManager.Current.MenuFocusedBack.IsColorDark() ? ControlPaint.Light(ThemeManager.Current.MenuFocusedBack, 0.10f) : ControlPaint.Dark(ThemeManager.Current.MenuFocusedBack, 0.10f)), 1), BoundsPadding = new Size(-2, 0), CornerRounding = 6.0f }; args.SubItem.Decoration = rbd; } // display the flags int offset = -5; obj.DoForEachFlag((name, flag) => { Image tryImg = (Image)ImageResources.ResourceManager.GetObject(name); if (tryImg != null) { ImageDecoration decoration = new ImageDecoration(tryImg, 100, ContentAlignment.MiddleRight) { Offset = new Size(offset, 0) }; if (args.SubItem.Decoration == null) { args.SubItem.Decoration = decoration; } else { args.SubItem.Decorations.Add(decoration); } offset -= 20; } }); // display the sub string if (offset < -5) { offset -= 5; } if (!string.IsNullOrEmpty(obj.SubString)) { TextDecoration decoration = new TextDecoration(obj.SubString, 100) { Alignment = ContentAlignment.MiddleRight, Offset = new Size(offset, 0), Font = FontManager.GetFont(FontStyle.Bold, 10), TextColor = ThemeManager.Current.SubTextFore, CornerRounding = 1f, Rotation = 0, BorderWidth = 1, BorderColor = ThemeManager.Current.SubTextFore }; args.SubItem.Decorations.Add(decoration); } }