public override void PaintValue(object val, Graphics g, Rectangle rect, Rectangle clipRect, PaintValueFlags paintFlags) { base.PaintValue(val, g, rect, clipRect, paintFlags & ~PaintValueFlags.DrawSelected); // draw the line along the top if (parentPE.GetChildIndex(this) > 0) { using (Pen topLinePen = new Pen(ownerGrid.CategorySplitterColor, 1)) { g.DrawLine(topLinePen, rect.X - 2, rect.Y - 1, rect.Width + 1, rect.Y - 1); } } }
public override void PaintValue(object val, System.Drawing.Graphics g, Rectangle rect, Rectangle clipRect, PaintValueFlags paintFlags) { base.PaintValue(val, g, rect, clipRect, paintFlags & ~PaintValueFlags.DrawSelected); // draw the line along the top if (parentPE.GetChildIndex(this) > 0) { using (Pen topLinePen = new System.Drawing.Pen(ownerGrid.CategorySplitterColor, 1)) { g.DrawLine(topLinePen, rect.X - 2, rect.Y - 1, rect.Width + 1, rect.Y - 1); } } }
public virtual void PaintValue(object val, Graphics g, Rectangle rect, Rectangle clipRect, PaintValueFlags paintFlags) { string lastValueString; PropertyGridView gridEntryHost = this.GridEntryHost; int valuePaintIndent = 0; Color textColor = gridEntryHost.GetTextColor(); if (this.ShouldRenderReadOnly) { textColor = this.GridEntryHost.GrayTextColor; } if ((paintFlags & PaintValueFlags.FetchValue) != PaintValueFlags.None) { if ((this.cacheItems != null) && this.cacheItems.useValueString) { lastValueString = this.cacheItems.lastValueString; val = this.cacheItems.lastValue; } else { val = this.PropertyValue; lastValueString = this.GetPropertyTextValue(val); if (this.cacheItems == null) { this.cacheItems = new CacheItems(); } this.cacheItems.lastValueString = lastValueString; this.cacheItems.useValueString = true; this.cacheItems.lastValueTextWidth = -1; this.cacheItems.lastValueFont = null; this.cacheItems.lastValue = val; } } else { lastValueString = this.GetPropertyTextValue(val); } Brush backgroundBrush = this.GetBackgroundBrush(g); if ((paintFlags & PaintValueFlags.DrawSelected) != PaintValueFlags.None) { backgroundBrush = SystemBrushes.Highlight; textColor = SystemColors.HighlightText; } Brush brush = backgroundBrush; g.FillRectangle(brush, clipRect); if (this.IsCustomPaint) { valuePaintIndent = gridEntryHost.GetValuePaintIndent(); Rectangle a = new Rectangle(rect.X + 1, rect.Y + 1, gridEntryHost.GetValuePaintWidth(), gridEntryHost.GetGridEntryHeight() - 2); if (!Rectangle.Intersect(a, clipRect).IsEmpty) { System.Drawing.Design.UITypeEditor uITypeEditor = this.UITypeEditor; if (uITypeEditor != null) { uITypeEditor.PaintValue(new PaintValueEventArgs(this, val, g, a)); } a.Width--; a.Height--; g.DrawRectangle(SystemPens.WindowText, a); } } rect.X += valuePaintIndent + gridEntryHost.GetValueStringIndent(); rect.Width -= valuePaintIndent + (2 * gridEntryHost.GetValueStringIndent()); bool boldFont = ((paintFlags & PaintValueFlags.CheckShouldSerialize) != PaintValueFlags.None) && this.ShouldSerializePropertyValue(); if ((lastValueString != null) && (lastValueString.Length > 0)) { Font f = this.GetFont(boldFont); if (lastValueString.Length > 0x3e8) { lastValueString = lastValueString.Substring(0, 0x3e8); } int num2 = this.GetValueTextWidth(lastValueString, g, f); bool flag2 = false; if ((num2 >= rect.Width) || this.GetMultipleLines(lastValueString)) { flag2 = true; } if (!Rectangle.Intersect(rect, clipRect).IsEmpty) { if ((paintFlags & PaintValueFlags.PaintInPlace) != PaintValueFlags.None) { rect.Offset(1, 2); } else { rect.Offset(1, 1); } Matrix transform = g.Transform; IntPtr hdc = g.GetHdc(); IntNativeMethods.RECT lpRect = IntNativeMethods.RECT.FromXYWH((rect.X + ((int) transform.OffsetX)) + 2, (rect.Y + ((int) transform.OffsetY)) - 1, rect.Width - 4, rect.Height); IntPtr hfont = this.GetHfont(boldFont); int crColor = 0; int clr = 0; Color color2 = ((paintFlags & PaintValueFlags.DrawSelected) != PaintValueFlags.None) ? SystemColors.Highlight : this.GridEntryHost.BackColor; try { crColor = System.Windows.Forms.SafeNativeMethods.SetTextColor(new HandleRef(g, hdc), System.Windows.Forms.SafeNativeMethods.RGBToCOLORREF(textColor.ToArgb())); clr = System.Windows.Forms.SafeNativeMethods.SetBkColor(new HandleRef(g, hdc), System.Windows.Forms.SafeNativeMethods.RGBToCOLORREF(color2.ToArgb())); hfont = System.Windows.Forms.SafeNativeMethods.SelectObject(new HandleRef(g, hdc), new HandleRef(null, hfont)); int nFormat = 0x2960; if (gridEntryHost.DrawValuesRightToLeft) { nFormat |= 0x20002; } if (this.ShouldRenderPassword) { if (passwordReplaceChar == '\0') { if (Environment.OSVersion.Version.Major > 4) { passwordReplaceChar = '●'; } else { passwordReplaceChar = '*'; } } lastValueString = new string(passwordReplaceChar, lastValueString.Length); } IntUnsafeNativeMethods.DrawText(new HandleRef(g, hdc), lastValueString, ref lpRect, nFormat); } finally { System.Windows.Forms.SafeNativeMethods.SetTextColor(new HandleRef(g, hdc), crColor); System.Windows.Forms.SafeNativeMethods.SetBkColor(new HandleRef(g, hdc), clr); hfont = System.Windows.Forms.SafeNativeMethods.SelectObject(new HandleRef(g, hdc), new HandleRef(null, hfont)); g.ReleaseHdcInternal(hdc); } if (flag2) { this.ValueToolTipLocation = new Point(rect.X + 2, rect.Y - 1); } else { this.ValueToolTipLocation = InvalidPoint; } } } }
/// <include file='doc\GridEntry.uex' path='docs/doc[@for="GridEntry.PaintValue"]/*' /> /// <devdoc> /// Paints the value portion of this GridEntry into the given Graphics object. This /// is called by the GridEntry host (the PropertyGridView) when this GridEntry is /// to be painted. /// </devdoc> public virtual void PaintValue(object val, System.Drawing.Graphics g, Rectangle rect, Rectangle clipRect, PaintValueFlags paintFlags) { PropertyGridView gridHost = this.GridEntryHost; Debug.Assert(gridHost != null, "No propEntryHost"); int cPaint = 0; Color textColor = gridHost.GetTextColor(); if (this.ShouldRenderReadOnly) { textColor = GridEntryHost.GrayTextColor; } string strValue; if ((paintFlags & PaintValueFlags.FetchValue) != PaintValueFlags.None) { if (cacheItems != null && cacheItems.useValueString) { strValue = cacheItems.lastValueString; val = cacheItems.lastValue; } else { val = this.PropertyValue; strValue = GetPropertyTextValue(val); if (cacheItems == null) { cacheItems = new CacheItems(); } cacheItems.lastValueString = strValue; cacheItems.useValueString = true; cacheItems.lastValueTextWidth = -1; cacheItems.lastValueFont = null; cacheItems.lastValue = val; } } else { strValue = GetPropertyTextValue(val); } // paint out the main rect using the appropriate brush Brush bkBrush = this.GetBackgroundBrush(g); Debug.Assert(bkBrush != null, "We didn't find a good background brush for PaintValue"); if ((paintFlags & PaintValueFlags.DrawSelected) != PaintValueFlags.None) { bkBrush = gridHost.GetSelectedItemWithFocusBackBrush(g); textColor = gridHost.GetSelectedItemWithFocusForeColor(); } Brush blank = bkBrush; #if PBRS_PAINT_DEBUG blank = Brushes.Yellow; #endif //g.FillRectangle(blank, rect.X-1, rect.Y, rect.Width+1, rect.Height); g.FillRectangle(blank, clipRect); if (IsCustomPaint) { cPaint = gridHost.GetValuePaintIndent(); Rectangle rectPaint = new Rectangle(rect.X + 1, rect.Y + 1, gridHost.GetValuePaintWidth(), gridHost.GetGridEntryHeight() - 2); if (!Rectangle.Intersect(rectPaint, clipRect).IsEmpty) { UITypeEditor uie = UITypeEditor; if (uie != null) { uie.PaintValue(new PaintValueEventArgs(this, val, g, rectPaint)); } // paint a border around the area rectPaint.Width --; rectPaint.Height--; g.DrawRectangle(SystemPens.WindowText, rectPaint); } } rect.X += cPaint + gridHost.GetValueStringIndent(); rect.Width -= cPaint + 2 * gridHost.GetValueStringIndent(); // bold the property if we need to persist it (e.g. it's not the default value) bool valueModified = ((paintFlags & PaintValueFlags.CheckShouldSerialize) != PaintValueFlags.None) && ShouldSerializePropertyValue(); // If we have text to paint, paint it if (strValue != null && strValue.Length > 0) { Font f = GetFont(valueModified); if (strValue.Length > maximumLengthOfPropertyString) { strValue = strValue.Substring(0, maximumLengthOfPropertyString); } int textWidth = GetValueTextWidth(strValue, g, f); bool doToolTip = false; //subhag (66503) To check if text contains multiple lines // if (textWidth >= rect.Width || GetMultipleLines(strValue)) doToolTip = true; if (Rectangle.Intersect(rect, clipRect).IsEmpty) { return; } // Do actual drawing //strValue = ReplaceCRLF(strValue); // AS/URT 55015 // bump the text down 2 pixels and over 1 pixel. if ((paintFlags & PaintValueFlags.PaintInPlace) != PaintValueFlags.None) { rect.Offset(1, 2); } else { // only go down one pixel when we're painting in the listbox rect.Offset(1, 1); } Matrix m = g.Transform; IntPtr hdc = g.GetHdc(); IntNativeMethods.RECT lpRect = IntNativeMethods.RECT.FromXYWH(rect.X + (int)m.OffsetX + 2, rect.Y + (int)m.OffsetY - 1, rect.Width - 4, rect.Height); IntPtr hfont = GetHfont(valueModified); int oldTextColor = 0; int oldBkColor = 0; Color bkColor = ((paintFlags & PaintValueFlags.DrawSelected) != PaintValueFlags.None) ? GridEntryHost.GetSelectedItemWithFocusBackColor() : GridEntryHost.BackColor; try { oldTextColor = SafeNativeMethods.SetTextColor(new HandleRef(g, hdc), SafeNativeMethods.RGBToCOLORREF(textColor.ToArgb())); oldBkColor = SafeNativeMethods.SetBkColor(new HandleRef(g, hdc), SafeNativeMethods.RGBToCOLORREF(bkColor.ToArgb())); hfont = SafeNativeMethods.SelectObject(new HandleRef(g, hdc), new HandleRef(null, hfont)); int format = IntNativeMethods.DT_EDITCONTROL | IntNativeMethods.DT_EXPANDTABS | IntNativeMethods.DT_NOCLIP | IntNativeMethods.DT_SINGLELINE | IntNativeMethods.DT_NOPREFIX; if (gridHost.DrawValuesRightToLeft) { format |= IntNativeMethods.DT_RIGHT | IntNativeMethods.DT_RTLREADING; } // For password mode, Replace the string value either with * or a bullet, depending on the OS platform if (ShouldRenderPassword) { if (passwordReplaceChar == (char)0) { if (Environment.OSVersion.Version.Major > 4) { passwordReplaceChar = (char)0x25CF; // Bullet is 2022, but edit box uses round circle 25CF } else { passwordReplaceChar = '*'; } } strValue = new string(passwordReplaceChar, strValue.Length); } IntUnsafeNativeMethods.DrawText(new HandleRef(g, hdc), strValue, ref lpRect, format); } finally { SafeNativeMethods.SetTextColor(new HandleRef(g, hdc), oldTextColor); SafeNativeMethods.SetBkColor(new HandleRef(g, hdc), oldBkColor); hfont = SafeNativeMethods.SelectObject(new HandleRef(g, hdc), new HandleRef(null, hfont)); g.ReleaseHdcInternal(hdc); } #if PBRS_PAINT_DEBUG rect.Width --; rect.Height--; g.DrawRectangle(new Pen(Color.Purple), rect); #endif if (doToolTip) { this.ValueToolTipLocation = new Point(rect.X+2, rect.Y-1); } else { this.ValueToolTipLocation = InvalidPoint; } } return; }
public override void PaintValue(object val, System.Drawing.Graphics g, Rectangle rect, Rectangle clipRect, PaintValueFlags paintFlags) { base.PaintValue(val, g, rect, clipRect, paintFlags & ~PaintValueFlags.DrawSelected); // draw the line along the top if (parentPE.GetChildIndex(this) > 0) { g.DrawLine(SystemPens.Control, rect.X - 2, rect.Y - 1, rect.Width + 1, rect.Y - 1); } }