/// <summary> /// Occurs when the text of the tree node is drawn /// </summary> /// <param name="dt">Drawing tool</param> /// <param name="items">The current collection that needs to be drawn</param> /// <param name="rect">The rectangular area where the text field is located</param> protected virtual void OnDrawItemText(DrawingTools dt, STNodeTreeCollection items, Rectangle rect) { Graphics g = dt.Graphics; rect.Width -= 20; m_sf.FormatFlags = StringFormatFlags.NoWrap; if (!string.IsNullOrEmpty(m_str_search)) { int nIndex = items.NameLower.IndexOf(m_str_search); if (nIndex != -1) { CharacterRange[] chrs = { new CharacterRange(nIndex, m_str_search.Length) };//global m_sf.SetMeasurableCharacterRanges(chrs); Region[] regions = g.MeasureCharacterRanges(items.Name, this.Font, rect, m_sf); g.SetClip(regions[0], System.Drawing.Drawing2D.CombineMode.Intersect); m_brush.Color = this._HightLightTextColor; g.DrawString(items.Name, this.Font, m_brush, rect, m_sf); g.ResetClip(); g.SetClip(regions[0], System.Drawing.Drawing2D.CombineMode.Exclude); m_brush.Color = items.STNodeType == null?Color.FromArgb(this.ForeColor.A * 1 / 2, this.ForeColor) : this.ForeColor; g.DrawString(items.Name, this.Font, m_brush, rect, m_sf); g.ResetClip(); return; } } m_brush.Color = items.STNodeType == null?Color.FromArgb(this.ForeColor.A * 2 / 3, this.ForeColor) : this.ForeColor; g.DrawString(items.Name, this.Font, m_brush, rect, m_sf); }
/// <summary> /// Occurs when each node of the tree node is drawn /// </summary> /// <param name="dt">Drawing tool</param> /// <param name="items">The current collection that needs to be drawn</param> /// <param name="nCounter">Counter of drawn counts</param> /// <param name="nLevel">Currently located in the sub-collection of which level</param> protected virtual void OnDrawItem(DrawingTools dt, STNodeTreeCollection items, int nCounter, int nLevel) { Graphics g = dt.Graphics; m_brush.Color = nCounter % 2 == 0 ? m_clr_item_1 : m_clr_item_2; g.FillRectangle(m_brush, items.DisplayRectangle); if (items == m_item_hover) { m_brush.Color = this._ItemHoverColor; g.FillRectangle(m_brush, items.DisplayRectangle); } Rectangle rect = new Rectangle(45 + nLevel * 10, items.SwitchRectangle.Top, this.Width - 45 - nLevel * 10, m_nItemHeight); m_pen.Color = Color.FromArgb(100, 125, 125, 125); g.DrawLine(m_pen, 9, items.SwitchRectangle.Top + m_nItemHeight / 2, items.SwitchRectangle.Left + 19, items.SwitchRectangle.Top + m_nItemHeight / 2); if (nCounter != 0) { for (int i = 0; i <= nLevel; i++) { g.DrawLine(m_pen, 9 + i * 10, items.SwitchRectangle.Top - m_nItemHeight / 2, 9 + i * 10, items.SwitchRectangle.Top + m_nItemHeight / 2 - 1); } } this.OnDrawItemText(dt, items, rect); this.OnDrawItemIcon(dt, items, rect); }
/// <summary> /// Occurs when the retrieved text area is drawn /// </summary> /// <param name="dt">Drawing tool</param> protected virtual void OnDrawSearch(DrawingTools dt) { Graphics g = dt.Graphics; m_brush.Color = this._TitleColor; g.FillRectangle(m_brush, 0, 0, this.Width, m_nItemHeight); m_brush.Color = m_tbx.BackColor; g.FillRectangle(m_brush, 5, 5, this.Width - 10, m_nItemHeight - 10); m_pen.Color = this.ForeColor; if (string.IsNullOrEmpty(m_str_search)) { g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality; g.DrawEllipse(m_pen, this.Width - 17, 8, 8, 8); g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.None; g.DrawLine(m_pen, this.Width - 13, 17, this.Width - 13, m_nItemHeight - 9); } else { m_pen.Color = this.ForeColor; g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality; g.DrawEllipse(m_pen, this.Width - 20, 9, 10, 10); g.DrawLine(m_pen, this.Width - 18, 11, this.Width - 12, 17); g.DrawLine(m_pen, this.Width - 12, 11, this.Width - 18, 17); g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.None; } }
/// <summary> /// Occurs when drawing the property's value area on the property editor /// </summary> /// <param name="dt">Drawing tool</param> protected internal virtual void OnDrawValueRectangle(DrawingTools dt) { Graphics g = dt.Graphics; SolidBrush brush = dt.SolidBrush; STNodePropertyGrid ctrl = this.Control; //STNodePropertyItem item = this._PropertyItem; brush.Color = ctrl.ItemValueBackColor; g.FillRectangle(brush, this.RectangleR); Rectangle rect = this.RectangleR; rect.Width--; rect.Height--; brush.Color = this.Control.ForeColor; g.DrawString(this.GetStringFromValue(), ctrl.Font, brush, this.RectangleR, m_sf); if (this.PropertyInfo.PropertyType.IsEnum || this.PropertyInfo.PropertyType == m_t_bool) { g.FillPolygon(Brushes.Gray, new Point[] { new Point(rect.Right - 13, rect.Top + rect.Height / 2 - 2), new Point(rect.Right - 4, rect.Top + rect.Height / 2 - 2), new Point(rect.Right - 9, rect.Top + rect.Height / 2 + 3) }); } }
/// <summary> /// Occurs when the tree node icon is drawn /// </summary> /// <param name="dt">Drawing tool</param> /// <param name="items">The current collection that needs to be drawn</param> /// <param name="rect">The rectangular area where the text field is located</param> protected virtual void OnDrawItemIcon(DrawingTools dt, STNodeTreeCollection items, Rectangle rect) { Graphics g = dt.Graphics; if (items.STNodeType != null) { m_pen.Color = this._AutoColor ? items.STNodeTypeColor : Color.DarkCyan; m_brush.Color = Color.LightGray; g.DrawRectangle(m_pen, rect.Left - 15, rect.Top + m_nItemHeight / 2 - 5, 11, 10); g.FillRectangle(m_brush, rect.Left - 17, rect.Top + m_nItemHeight / 2 - 2, 5, 5); g.FillRectangle(m_brush, rect.Left - 6, rect.Top + m_nItemHeight / 2 - 2, 5, 5); if (m_item_hover == items && m_bHoverInfo) { m_brush.Color = this.BackColor; g.FillRectangle(m_brush, items.InfoRectangle); } m_pen.Color = this._AutoColor ? items.STNodeTypeColor : this._InfoButtonColor; m_pen.Width = 2; g.DrawLine(m_pen, items.InfoRectangle.X + 4, items.InfoRectangle.Y + 3, items.InfoRectangle.X + 10, items.InfoRectangle.Y + 3); g.DrawLine(m_pen, items.InfoRectangle.X + 4, items.InfoRectangle.Y + 6, items.InfoRectangle.X + 10, items.InfoRectangle.Y + 6); g.DrawLine(m_pen, items.InfoRectangle.X + 4, items.InfoRectangle.Y + 11, items.InfoRectangle.X + 10, items.InfoRectangle.Y + 11); g.DrawLine(m_pen, items.InfoRectangle.X + 7, items.InfoRectangle.Y + 7, items.InfoRectangle.X + 7, items.InfoRectangle.Y + 10); m_pen.Width = 1; g.DrawRectangle(m_pen, items.InfoRectangle.X, items.InfoRectangle.Y, items.InfoRectangle.Width - 1, items.InfoRectangle.Height - 1); } else { if (items.IsLibraryRoot) { Rectangle rect_box = new Rectangle(rect.Left - 15, rect.Top + m_nItemHeight / 2 - 5, 11, 10); g.DrawRectangle(Pens.Gray, rect_box); g.DrawLine(Pens.Cyan, rect_box.X - 2, rect_box.Top, rect_box.X + 2, rect_box.Top); g.DrawLine(Pens.Cyan, rect_box.X, rect_box.Y - 2, rect_box.X, rect_box.Y + 2); g.DrawLine(Pens.Cyan, rect_box.Right - 2, rect_box.Bottom, rect_box.Right + 2, rect_box.Bottom); g.DrawLine(Pens.Cyan, rect_box.Right, rect_box.Bottom - 2, rect_box.Right, rect_box.Bottom + 2); } else { g.DrawRectangle(Pens.Goldenrod, new Rectangle(rect.Left - 16, rect.Top + m_nItemHeight / 2 - 6, 8, 3)); g.DrawRectangle(Pens.Goldenrod, new Rectangle(rect.Left - 16, rect.Top + m_nItemHeight / 2 - 3, 13, 9)); } if (!this._ShowFolderCount) { return; } m_sf.Alignment = StringAlignment.Far; m_brush.Color = this._FolderCountColor; rect.X -= 4; g.DrawString("[" + items.STNodeCount.ToString() + "]", this.Font, m_brush, rect, m_sf); m_sf.Alignment = StringAlignment.Near; } }
/// <summary> /// Occurs when an error message needs to be drawn /// </summary> /// <param name="dt">Drawing tool</param> protected virtual void OnDrawErrorInfo(DrawingTools dt) { if (string.IsNullOrEmpty(m_str_err)) { return; } Graphics g = dt.Graphics; SizeF szf = g.MeasureString(m_str_err, this.Font, this.Width - 4); Rectangle rect_desc = new Rectangle(0, 0, this.Width, (int)szf.Height + 4); m_brush.Color = this._ErrorColor; g.FillRectangle(m_brush, rect_desc); m_pen.Color = this._ErrorColor; g.DrawRectangle(m_pen, 0, rect_desc.Top, rect_desc.Width - 1, rect_desc.Height - 1); rect_desc.Inflate(-4, 0); m_brush.Color = this.ForeColor; m_sf.Alignment = StringAlignment.Near; g.DrawString(m_str_err, this.Font, m_brush, rect_desc, m_sf); }
protected internal virtual void OnPaint(DrawingTools dt) { Graphics g = dt.Graphics; SolidBrush brush = dt.SolidBrush; g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.None; g.TextRenderingHint = System.Drawing.Text.TextRenderingHint.ClearTypeGridFit; brush.Color = this._BackColor; g.FillRectangle(brush, 0, 0, this.Width, this.Height); if (!string.IsNullOrEmpty(this._Text)) { brush.Color = this._ForeColor; g.DrawString(this._Text, this._Font, brush, this.ClientRectangle, m_sf); } if (this.Paint != null) { this.Paint(this, new STNodeControlPaintEventArgs(dt)); } }
/// <summary> /// Occurs when starting to draw each node of the tree node /// </summary> /// <param name="dt">Drawing tool</param> /// <param name="Items">The current collection that needs to be drawn</param> /// <param name="nCounter">Counter of drawn counts</param> /// <param name="nLevel">Currently located in the sub-collection of which level</param> /// <returns>Number of already drawn</returns> protected virtual int OnStartDrawItem(DrawingTools dt, STNodeTreeCollection Items, int nCounter, int nLevel) { Graphics g = dt.Graphics; Items.DisplayRectangle = new Rectangle(0, m_nItemHeight * (nCounter + 1), this.Width, m_nItemHeight); Items.SwitchRectangle = new Rectangle(5 + nLevel * 10, (nCounter + 1) * m_nItemHeight, 10, m_nItemHeight); if (this._ShowInfoButton && Items.STNodeType != null) { Items.InfoRectangle = new Rectangle(this.Width - 18, Items.DisplayRectangle.Top + (m_nItemHeight - 14) / 2, 14, 14); } else { Items.InfoRectangle = Rectangle.Empty; } this.OnDrawItem(dt, Items, nCounter++, nLevel); if (!Items.IsOpen) { return(nCounter); } foreach (STNodeTreeCollection n in Items) { if (n.STNodeType == null) { nCounter = this.OnStartDrawItem(dt, n, nCounter++, nLevel + 1); } } foreach (STNodeTreeCollection n in Items) { if (n.STNodeType != null) { nCounter = this.OnStartDrawItem(dt, n, nCounter++, nLevel + 1); } } foreach (STNodeTreeCollection v in Items) { this.OnDrawSwitch(dt, v); } return(nCounter); }
/// <summary> /// Occurs when drawing attribute options /// </summary> /// <param name="dt">Drawing tool</param> /// <param name="item">Target attribute option descriptor</param> /// <param name="nIndex">The index of the option</param> protected virtual void OnDrawPropertyItem(DrawingTools dt, STNodePropertyDescriptor item, int nIndex) { Graphics g = dt.Graphics; m_brush.Color = (nIndex % 2 == 0) ? m_clr_item_1 : m_clr_item_2; g.FillRectangle(m_brush, item.Rectangle); if (item == m_item_hover || item == m_item_selected) { m_brush.Color = this._ItemHoverColor; g.FillRectangle(m_brush, item.Rectangle); } if (m_item_selected == item) { g.FillRectangle(m_brush, item.Rectangle.X, item.Rectangle.Y, 5, item.Rectangle.Height); if (this._AutoColor && this._STNode != null) { m_brush.Color = this._STNode.TitleColor; } else { m_brush.Color = this._ItemSelectedColor; } g.FillRectangle(m_brush, item.Rectangle.X, item.Rectangle.Y + 4, 5, item.Rectangle.Height - 8); } m_sf.Alignment = StringAlignment.Far; m_brush.Color = this.ForeColor; g.DrawString(item.Name, this.Font, m_brush, item.RectangleL, m_sf); item.OnDrawValueRectangle(m_dt); if (this._ReadOnlyModel) { m_brush.Color = Color.FromArgb(125, 125, 125, 125); g.FillRectangle(m_brush, item.RectangleR); m_pen.Color = this.ForeColor; //g.DrawLine(m_pen, // item.RectangleR.Left - 2, item.RectangleR.Top + item.RectangleR.Height / 2, // item.RectangleR.Right + 1, item.RectangleR.Top + item.RectangleR.Height / 2); } }
/// <summary> /// Occurs when drawing the tree node expand and close switches /// </summary> /// <param name="dt">Drawing tool</param> /// <param name="items">The current collection that needs to be drawn</param> protected virtual void OnDrawSwitch(DrawingTools dt, STNodeTreeCollection items) { Graphics g = dt.Graphics; if (items.Count != 0) { m_pen.Color = this._SwitchColor; m_brush.Color = m_pen.Color; int nT = items.SwitchRectangle.Y + m_nItemHeight / 2 - 4; g.DrawRectangle(m_pen, items.SwitchRectangle.Left, nT, 8, 8); g.DrawLine(m_pen, items.SwitchRectangle.Left + 1, nT + 4, items.SwitchRectangle.Right - 3, nT + 4); if (items.IsOpen) { return; } g.DrawLine(m_pen, items.SwitchRectangle.Left + 4, nT + 1, items.SwitchRectangle.Left + 4, nT + 7); //if (items.IsOpen) { // //g.FillPolygon(m_brush, new Point[]{ // // new Point(items.DotRectangle.Left + 0, items.DotRectangle.Top + m_nItemHeight / 2 - 2), // // new Point(items.DotRectangle.Left + 9, items.DotRectangle.Top + m_nItemHeight / 2 - 2), // // new Point(items.DotRectangle.Left + 4, items.DotRectangle.Top + m_nItemHeight / 2 + 3) // //}); // g.DrawRectangle(m_pen, items.SwitchRectangle.Left, nT, 8, 8); // g.DrawLine(m_pen, items.SwitchRectangle.Left + 1, nT + 4, items.SwitchRectangle.Right - 3, nT + 4); //} else { // //g.FillPolygon(m_brush, new Point[]{ // // new Point(items.DotRectangle.Left + 2, items.DotRectangle.Top + m_nItemHeight / 2 - 5), // // new Point(items.DotRectangle.Left + 2, items.DotRectangle.Top + m_nItemHeight / 2 + 5), // // new Point(items.DotRectangle.Left + 7, items.DotRectangle.Top + m_nItemHeight / 2) // //}); // g.DrawRectangle(m_pen, items.SwitchRectangle.Left, nT, 8, 8); // g.DrawLine(m_pen, items.SwitchRectangle.Left + 1, nT + 4, items.SwitchRectangle.Right - 3, nT + 4); // g.DrawLine(m_pen, items.SwitchRectangle.Left + 4, nT + 1, items.SwitchRectangle.Left + 4, nT + 7); //} } }
/// <summary> /// Occurs when drawing node information /// </summary> /// <param name="dt">Drawing tool</param> protected virtual void OnDrawInfo(DrawingTools dt) { if (m_node_attribute == null) { return; } var attr = m_node_attribute; Graphics g = dt.Graphics; Color clr_r = Color.FromArgb(this.ForeColor.A / 2, this.ForeColor); m_sf.Alignment = StringAlignment.Near; Rectangle rect = new Rectangle(0, this._ShowTitle ? m_nTitleHeight : 0, this.Width, m_item_height); Rectangle rect_l = new Rectangle(2, rect.Top, m_nInfoLeft - 2, m_item_height); Rectangle rect_r = new Rectangle(m_nInfoLeft, rect.Top, this.Width - m_nInfoLeft, m_item_height); m_brush.Color = m_clr_item_2; g.FillRectangle(m_brush, rect); m_brush.Color = this.ForeColor; m_sf.FormatFlags = StringFormatFlags.NoWrap; m_sf.Alignment = StringAlignment.Near; g.DrawString(m_KeysString[0], this.Font, m_brush, rect_l, m_sf); //author m_brush.Color = clr_r; g.DrawString(attr.Author, this.Font, m_brush, rect_r, m_sf); rect.Y += m_item_height; rect_l.Y += m_item_height; rect_r.Y += m_item_height; m_brush.Color = m_clr_item_1; g.FillRectangle(m_brush, rect); m_brush.Color = this.ForeColor; g.DrawString(m_KeysString[1], this.Font, m_brush, rect_l, m_sf); //mail m_brush.Color = clr_r; g.DrawString(attr.Mail, this.Font, m_brush, rect_r, m_sf); rect.Y += m_item_height; rect_l.Y += m_item_height; rect_r.Y += m_item_height; m_brush.Color = m_clr_item_2; g.FillRectangle(m_brush, rect); m_brush.Color = this.ForeColor; g.DrawString(m_KeysString[2], this.Font, m_brush, rect_l, m_sf); //link_key m_brush.Color = clr_r; g.DrawString(attr.Link, this.Font, Brushes.CornflowerBlue, rect_r, m_sf); //link if (!string.IsNullOrEmpty(attr.Link)) { m_rect_link = rect_r; } //fill left m_brush.Color = Color.FromArgb(40, 125, 125, 125); g.FillRectangle(m_brush, 0, this._ShowTitle ? m_nTitleHeight : 0, m_nInfoLeft - 1, m_item_height * 3); rect.X = 5; rect.Y += m_item_height; rect.Width = this.Width - 10; if (!string.IsNullOrEmpty(m_node_attribute.Description)) { float h = g.MeasureString(m_node_attribute.Description, this.Font, rect.Width).Height; rect.Height = (int)Math.Ceiling(h / m_item_height) * m_item_height; m_brush.Color = clr_r; m_sf.FormatFlags = 0; g.DrawString(m_node_attribute.Description, this.Font, m_brush, rect, m_sf); } m_nInfoVHeight = rect.Bottom; bool bHasHelp = STNodeAttribute.GetHelpMethod(m_type) != null; rect.X = 5; rect.Y += rect.Height; rect.Height = m_item_height; m_sf.Alignment = StringAlignment.Center; m_brush.Color = Color.FromArgb(125, 125, 125, 125); g.FillRectangle(m_brush, rect); if (bHasHelp) { m_brush.Color = Color.CornflowerBlue; } g.DrawString(m_KeysString[3], this.Font, m_brush, rect, m_sf); if (bHasHelp) { m_rect_help = rect; } else { int w = (int)g.MeasureString(m_KeysString[3], this.Font).Width + 1; int x = rect.X + (rect.Width - w) / 2, y = rect.Y + rect.Height / 2; m_pen.Color = m_brush.Color; g.DrawLine(m_pen, x, y, x + w, y); } m_nInfoVHeight = rect.Bottom; }
/// <summary> /// Draw the property window title /// </summary> /// <param name="dt">Drawing tool</param> protected virtual void OnDrawTitle(DrawingTools dt) { Graphics g = dt.Graphics; if (this._AutoColor) { m_brush.Color = this._STNode == null ? this._TitleColor : this._STNode.TitleColor; } else { m_brush.Color = this._TitleColor; } g.FillRectangle(m_brush, m_rect_title); m_brush.Color = this._STNode == null ? this.ForeColor : this._STNode.ForeColor; m_sf.Alignment = StringAlignment.Center; g.DrawString(this._STNode == null ? this.Text : this._STNode.Title, this.Font, m_brush, m_rect_title, m_sf); if (this._ReadOnlyModel) { m_brush.Color = this.ForeColor; g.FillRectangle(dt.SolidBrush, 4, 5, 2, 4); g.FillRectangle(dt.SolidBrush, 6, 5, 2, 2); g.FillRectangle(dt.SolidBrush, 8, 5, 2, 4); g.FillRectangle(dt.SolidBrush, 3, 9, 8, 6); } //Whether to draw the panel switch button if (m_node_attribute == null || m_lst_item.Count == 0) { return; } if (m_b_hover_switch) { m_brush.Color = this.BackColor; g.FillRectangle(m_brush, m_rect_switch); } m_pen.Color = this._STNode == null ? this.ForeColor : this._STNode.ForeColor; m_brush.Color = m_pen.Color; int nT1 = m_rect_switch.Top + m_rect_switch.Height / 2 - 2; int nT2 = m_rect_switch.Top + m_rect_switch.Height / 2 + 1; g.DrawRectangle(m_pen, m_rect_switch.Left, m_rect_switch.Top, m_rect_switch.Width - 1, m_rect_switch.Height - 1); g.DrawLines(m_pen, new Point[] { new Point(m_rect_switch.Left + 2, nT1), new Point(m_rect_switch.Right - 3, nT1), new Point(m_rect_switch.Left + 3, nT1 - 1), new Point(m_rect_switch.Right - 3, nT1 - 1) }); g.DrawLines(m_pen, new Point[] { new Point(m_rect_switch.Left + 2, nT2), new Point(m_rect_switch.Right - 3, nT2), new Point(m_rect_switch.Left + 2, nT2 + 1), new Point(m_rect_switch.Right - 4, nT2 + 1), }); g.FillPolygon(m_brush, new Point[] { new Point(m_rect_switch.Left + 2, nT1), new Point(m_rect_switch.Left + 7, nT1), new Point(m_rect_switch.Left + 7, m_rect_switch.Top), }); g.FillPolygon(m_brush, new Point[] { new Point(m_rect_switch.Right - 2, nT2), new Point(m_rect_switch.Right - 7, nT2), new Point(m_rect_switch.Right - 7, m_rect_switch.Bottom - 2), }); }
public STNodeControlPaintEventArgs(DrawingTools dt) { this.DrawingTools = dt; }