public override Control ShowControl(Rectangle valueRect, PropertyEnumerator propEnum) { PropInPlaceRadioButton radioButton; if (mInPlaceCtrl == null) { radioButton = new PropInPlaceRadioButton(); radioButton.Visible = false; radioButton.Parent = mParentWnd; mInPlaceCtrl = radioButton; } else { radioButton = (PropInPlaceRadioButton)mInPlaceCtrl; } NotifyInPlaceControlCreated(propEnum); // radioButton.Text = propEnum.Property.Value.DisplayString; radioButton.OwnerPropertyEnumerator = propEnum; radioButton.Font = propEnum.Property.Value.Font; MoveControl(valueRect, propEnum); return(base.ShowControl(valueRect, propEnum)); }
public override Control ShowControl(Rectangle valueRect, PropertyEnumerator propEnum) { // if (propEnum.Property.Value.IsReadOnly(propEnum)) // return null; PropInPlaceUITypeEditor inPlaceCtrl; if (mInPlaceCtrl == null) { inPlaceCtrl = new PropInPlaceUITypeEditor(_editor, true); inPlaceCtrl.Visible = false; inPlaceCtrl.Parent = mParentWnd; mInPlaceCtrl = inPlaceCtrl; } else inPlaceCtrl = (PropInPlaceUITypeEditor)mInPlaceCtrl; NotifyInPlaceControlCreated(propEnum); /* if (propEnum.Property.Value.HasMultipleValues) inPlaceCtrl.Text = ""; else inPlaceCtrl.Text = propEnum.Property.Value.DisplayString; */ inPlaceCtrl.OwnerPropertyEnumerator = propEnum; inPlaceCtrl.Font = propEnum.Property.Value.Font; MoveControl(valueRect, propEnum); return base.ShowControl(valueRect, propEnum); }
public override Control ShowControl(Rectangle valueRect, PropertyEnumerator propEnum) { if (DontShowInPlaceCtrl(propEnum)) { return(null); } PropInPlaceList list; if (mInPlaceCtrl == null) { list = new PropInPlaceList(_editable); list.Visible = false; list.Parent = mParentWnd; mInPlaceCtrl = list; } else { list = (PropInPlaceList)mInPlaceCtrl; } NotifyInPlaceControlCreated(propEnum); // list.Text = propEnum.Property.Value.DisplayString; list.OwnerPropertyEnumerator = propEnum; list.Font = propEnum.Property.Value.Font; MoveControl(valueRect, propEnum); return(base.ShowControl(valueRect, propEnum)); }
public override Control ShowControl(Rectangle valueRect, PropertyEnumerator propEnum) { if ((propEnum.Property.Value.IsReadOnly(propEnum)) && !_editable) { return(null); } PropInPlaceButton button; if (mInPlaceCtrl == null) { button = new PropInPlaceButton(_editable); button.Visible = false; button.Parent = mParentWnd; mInPlaceCtrl = button; } else { button = (PropInPlaceButton)mInPlaceCtrl; } NotifyInPlaceControlCreated(propEnum); // button.Text = propEnum.Property.Value.DisplayString; button.OwnerPropertyEnumerator = propEnum; button.Font = propEnum.Property.Value.Font; MoveControl(valueRect, propEnum); return(base.ShowControl(valueRect, propEnum)); }
public override void DrawCategoryLabelBackground(Graphics graphics, Rectangle rect, PropertyEnumerator enumSelf) { Rectangle fillRect = Rectangle.Intersect(rect, Rectangle.Round(graphics.ClipBounds)); if (fillRect.IsEmpty) return; Rectangle labelRect = enumSelf.Property.GetLabelColumnRect(rect, enumSelf); rect.Y++; rect.Height -= 3; fillRect = rect; int margin = enumSelf.Property.ParentGrid.GlobalTextMargin; fillRect.X = labelRect.Left + margin / 2; fillRect.Width = rect.Right - fillRect.Left; Brush brush; if (enumSelf.Property.Selected) // if selected brush = new SolidBrush(Grid.GridContainsFocus ? Grid.SelectedBackColor : Grid.SelectedNotFocusedBackColor); else brush = new LinearGradientBrush(fillRect, _categoryBkgColor1, _categoryBkgColor2, 0.0f); graphics.FillRectangle(brush, fillRect); brush.Dispose(); }
public override void DrawCategoryLabelBackground(Graphics graphics, Rectangle rect, PropertyEnumerator enumSelf) { Rectangle fillRect = Rectangle.Intersect(rect, Rectangle.Round(graphics.ClipBounds)); if (fillRect.IsEmpty) return; Brush brush; if (enumSelf.Property.Selected) // if selected { Color bkgColor; if (Grid.GridContainsFocus) bkgColor = Grid.SelectedBackColor; else { // If the control has not the focus, the background is light bkgColor = Grid.SelectedNotFocusedBackColor; } brush = new SolidBrush(bkgColor); } else brush = new SolidBrush(Grid.GridBackColor); graphics.FillRectangle(brush, rect); }
public override Control ShowControl(Rectangle valueRect, PropertyEnumerator propEnum) { // if (propEnum.Property.Value.IsReadOnly(propEnum)) // return null; PropInPlaceUITypeEditor inPlaceCtrl; if (mInPlaceCtrl == null) { inPlaceCtrl = new PropInPlaceUITypeEditor(_editor, true); inPlaceCtrl.Visible = false; inPlaceCtrl.Parent = mParentWnd; mInPlaceCtrl = inPlaceCtrl; } else { inPlaceCtrl = (PropInPlaceUITypeEditor)mInPlaceCtrl; } NotifyInPlaceControlCreated(propEnum); /* * if (propEnum.Property.Value.HasMultipleValues) * inPlaceCtrl.Text = ""; * else * inPlaceCtrl.Text = propEnum.Property.Value.DisplayString; */ inPlaceCtrl.OwnerPropertyEnumerator = propEnum; inPlaceCtrl.Font = propEnum.Property.Value.Font; MoveControl(valueRect, propEnum); return(base.ShowControl(valueRect, propEnum)); }
public ValueValidationEventArgs(PropertyEnumerator propEnum, PropertyEnumerator invalidPropEnum, object value, PropertyValue.ValueValidationResult result) : base(propEnum) { _valueValidationResult = result; _valueToValidate = value; _invalidPropEnum = invalidPropEnum; }
public override void OnDraw(Graphics graphics, Rectangle valueRect, Color textColor, PropertyEnumerator propEnum, string drawAnotherString) { valueRect.Height++; Rectangle colorRect = GetColorRect(valueRect); // Draw the color box Color color; try { color = (Color)Value.GetActualValue(drawAnotherString); } catch (Exception) { color = (Color)Value.GetValue(); } Brush brush = new SolidBrush(color); graphics.FillRectangle(brush, colorRect); if (propEnum.Property.Value.HasMultipleValues) graphics.DrawLine(SystemPens.GrayText, colorRect.Left, colorRect.Bottom, colorRect.Right, colorRect.Top); // Draw a black frame around Pen pen = new Pen(Color.Black); graphics.DrawRectangle(pen, colorRect); pen.Dispose(); Rectangle strRect = GetDisplayStringRect(graphics, valueRect, Point.Empty /* not used */); strRect.Width = valueRect.Right - strRect.Left; Win32Calls.DrawText(graphics, (drawAnotherString == null ? DisplayString : drawAnotherString), ref strRect, Value.Font, textColor, Win32Calls.DT_VCENTER | Win32Calls.DT_SINGLELINE | Win32Calls.DT_END_ELLIPSIS | Win32Calls.DT_NOPREFIX); }
public override Control ShowControl(Rectangle valueRect, PropertyEnumerator propEnum) { PropInPlaceUnit unit; if (mInPlaceCtrl == null) { unit = new PropInPlaceUnit(); unit.Visible = false; unit.Parent = mParentWnd; mInPlaceCtrl = unit; } else { unit = (PropInPlaceUnit)mInPlaceCtrl; } NotifyInPlaceControlCreated(propEnum); // unit.Text = propEnum.Property.Value.DisplayString; unit.OwnerPropertyEnumerator = propEnum; unit.Font = propEnum.Property.Value.Font; MoveControl(valueRect, propEnum); return(base.ShowControl(valueRect, propEnum)); }
public override bool IsReadOnly(PropertyEnumerator selfEnum) { if (!Grid.Grid.Enabled && (Grid.DisableMode == PropertyGrid.DisableModes.Simple)) { return(true); } if ((selfEnum.Parent.Property != null) && (selfEnum.Parent.Property.Value != null)) { if (!selfEnum.Parent.Property.Value.NoLinkWithChildren && (selfEnum.Parent.Property.Value.IsReadOnly(selfEnum.Parent))) { return(true); } } // Check if a UITypeEditor has been found. Even if the property is marked Readonly (has only a get // accessor for example), the presence of an editor makes it editable (this is the case for collections // for example in the .net framework) ReadOnlyAttribute manualReadOnlyAttr = (ReadOnlyAttribute)base.GetAttribute(typeof(ReadOnlyAttribute)); if ((mFeel is PropertyUITypeEditorFeel) && ((manualReadOnlyAttr == null) || !manualReadOnlyAttr.IsReadOnly)) { return(false); } ReadOnlyAttribute attr = (ReadOnlyAttribute)GetAttribute(typeof(ReadOnlyAttribute)); return((attr != null) && attr.IsReadOnly); }
public override void MoveControl(Rectangle valueRect, PropertyEnumerator propEnum) { if (mInPlaceCtrl == null) return; mInPlaceCtrl.BackColor = propEnum.Property.Value.BackColor; // Find where the string is actually displayed (a look instance could place it anywhere) Graphics graphics = mParentWnd.CreateGraphics(); Rectangle strRect = propEnum.Property.Value.GetStringValueRect(graphics, valueRect, Point.Empty /* not used */); strRect.X -= (propEnum.Property.Value.EditboxLeftMargin == -1 ? propEnum.Property.ParentGrid.GlobalTextMargin : propEnum.Property.Value.EditboxLeftMargin); strRect.Width = valueRect.Right - strRect.Left; // Calculate the height of the editbox, based on the font height Rectangle editRect = strRect; editRect.Inflate(0,-1); Win32Calls.TEXTMETRIC tm = new Win32Calls.TEXTMETRIC(); Win32Calls.GetTextMetrics(graphics, mInPlaceCtrl.Font, ref tm); graphics.Dispose(); int extraHeight = editRect.Height - tm.tmHeight; editRect.Y += extraHeight / 2; editRect.Height -= extraHeight; if (mInPlaceCtrl.Bounds != editRect) mInPlaceCtrl.Bounds = editRect; }
public override Control ShowControl(Rectangle valueRect, PropertyEnumerator propEnum) { if ((propEnum.Property.Value.IsReadOnly(propEnum)) && !_editable) { return(null); } PropInPlaceTrackbar trackbar; if (mInPlaceCtrl == null) { trackbar = new PropInPlaceTrackbar(_editable); trackbar.Visible = false; trackbar.Parent = mParentWnd; mInPlaceCtrl = trackbar; } else { trackbar = (PropInPlaceTrackbar)mInPlaceCtrl; } NotifyInPlaceControlCreated(propEnum); trackbar.OwnerPropertyEnumerator = propEnum; trackbar.Font = propEnum.Property.Value.Font; MoveControl(valueRect, propEnum); return(base.ShowControl(valueRect, propEnum)); }
public override Rectangle GetManuallyDisableRect(Rectangle itemRect, PropertyEnumerator enumSelf) { if (CanBeDisabledManually == false) { return(Rectangle.Empty); } Rectangle frameRect = itemRect; Rectangle signRect = GetSignRect(itemRect, enumSelf); if (signRect != Rectangle.Empty) { frameRect.X = ParentGrid.GlobalTextMargin + signRect.Right; } else { frameRect.X = ParentGrid.GlobalTextMargin + ParentGrid.LeftColumnWidth + 1 + (enumSelf.Depth - 1) * (ParentGrid.GlobalTextMargin + TreeGlyphWidth); } // Size it based on the row height frameRect.Y += 2; frameRect.Height = ParentGrid.BasicPropertyHeight - 4; frameRect.Width = frameRect.Height; return(frameRect); }
public override Rectangle GetLabelTextRect(Rectangle itemRect, PropertyEnumerator enumSelf) { Font underlinedFont = new Font(Font, FontStyle.Underline); Graphics graphics = ParentGrid.CreateGraphics(); Size textSize = Win32Calls.GetTextExtent(graphics, DisplayName, underlinedFont); Rectangle labelColumnRect = GetLabelColumnRect(itemRect, enumSelf); labelColumnRect.Inflate(-ParentGrid.GlobalTextMargin, 0); Rectangle labelRect = labelColumnRect; if (textSize.Width <= labelColumnRect.Width) { labelRect.X = labelColumnRect.Right - textSize.Width; labelRect.Width = textSize.Width; } else { labelRect.Width = labelColumnRect.Right - labelRect.Left; } graphics.Dispose(); underlinedFont.Dispose(); return(labelRect); }
public override Control ShowControl(Rectangle valueRect, PropertyEnumerator propEnum) { if (DontShowInPlaceCtrl(propEnum)) return null; PropInPlaceList list; if (mInPlaceCtrl == null) { list = new PropInPlaceList(_editable); list.Visible = false; list.Parent = mParentWnd; mInPlaceCtrl = list; } else list = (PropInPlaceList)mInPlaceCtrl; NotifyInPlaceControlCreated(propEnum); // list.Text = propEnum.Property.Value.DisplayString; list.OwnerPropertyEnumerator = propEnum; list.Font = propEnum.Property.Value.Font; MoveControl(valueRect, propEnum); return base.ShowControl(valueRect, propEnum); }
/// <summary> /// Removes a property from the tree. /// </summary> /// <param name="propEnum">An enumerator pointing to the property to remove from the tree.</param> /// <returns>A deep enumerator on the property that would be naturally selected if the deleted /// item was selected.</returns> public PropertyEnumerator Delete(PropertyEnumerator propEnum) { // Store the previous property (deep) PropertyDeepEnumerator dEnumerator = new PropertyDeepEnumerator(propEnum.Node); dEnumerator.MovePrev(); // Remove the property propEnum.Node.Owner.Remove(propEnum.Node); // Determine the next property of the property that was deleted if (dEnumerator.MoveNext() == dEnumerator.RightBound) { dEnumerator.MovePrev(); } if (dEnumerator == dEnumerator.LeftBound) { dEnumerator = dEnumerator.RightBound.GetDeepEnumerator(); } // Since the enumerator passed in argument now points to an invalid property, // we make it point to the next property (the previous one if no next exists) propEnum.Node = dEnumerator.Node; return(dEnumerator); }
public override System.Windows.Forms.Control ShowControl(Rectangle valueRect, PropertyEnumerator propEnum) { if ((propEnum.Property.Value.IsReadOnly(propEnum)) && !_editable) return null; PropInPlaceUpDown upDown; if (mInPlaceCtrl == null) { upDown = new PropInPlaceUpDown(_editable); upDown.Visible = false; upDown.Parent = mParentWnd; mInPlaceCtrl = upDown; } else upDown = (PropInPlaceUpDown)mInPlaceCtrl; NotifyInPlaceControlCreated(propEnum); // upDown.Text = propEnum.Property.Value.DisplayString; upDown.OwnerPropertyEnumerator = propEnum; upDown.Font = propEnum.Property.Value.Font; MoveControl(valueRect, propEnum); return base.ShowControl(valueRect, propEnum); }
public override Control ShowControl(Rectangle valueRect, PropertyEnumerator propEnum) { if ((propEnum.Property.Value.IsReadOnly(propEnum)) && !_editable) return null; PropInPlaceButton button; if (mInPlaceCtrl == null) { button = new PropInPlaceButton(_editable); button.Visible = false; button.Parent = mParentWnd; mInPlaceCtrl = button; } else button = (PropInPlaceButton)mInPlaceCtrl; NotifyInPlaceControlCreated(propEnum); // button.Text = propEnum.Property.Value.DisplayString; button.OwnerPropertyEnumerator = propEnum; button.Font = propEnum.Property.Value.Font; MoveControl(valueRect, propEnum); return base.ShowControl(valueRect, propEnum); }
public override Rectangle GetImageRect(Rectangle itemRect, PropertyEnumerator enumSelf) { if (ImageIndex == -1) { return(Rectangle.Empty); } Rectangle imgRect = itemRect; imgRect.X = ParentGrid.LeftColumnWidth + 1 + ParentGrid.GlobalTextMargin; try { Image img = ParentGrid.ImageList.Images[ImageIndex]; imgRect.Width = img.Width; imgRect.Height = img.Height; } catch (Exception) { return(Rectangle.Empty); } imgRect.Y = itemRect.Top + itemRect.Height / 2 - 8; return(imgRect); }
public virtual System.Windows.Forms.Control ShowControl(Rectangle valueRect, PropertyEnumerator propEnum) { if (mInPlaceCtrl != null) { mInPlaceCtrl.Visible = true; mInPlaceCtrl.BackColor = propEnum.Property.Value.BackColor; if (propEnum.Property.Value.ReadOnly) { if ((mPropCtrl.Enabled == false) && (mPropCtrl.DisableMode != PropertyGrid.DisableModes.None) && mPropCtrl.DisableModeGrayedOut) { mInPlaceCtrl.ForeColor = mPropCtrl.DisabledForeColor; } else { mInPlaceCtrl.ForeColor = propEnum.Property.Value.ReadOnlyForeColor; } } else { mInPlaceCtrl.ForeColor = propEnum.Property.Value.ForeColor; } } mPropCtrl.OnInPlaceCtrlVisible(new InPlaceCtrlVisibleEventArgs(propEnum, mInPlaceCtrl)); return(mInPlaceCtrl); }
public override Control ShowControl(Rectangle valueRect, PropertyEnumerator propEnum) { if ((propEnum.Property.Value.IsReadOnly(propEnum)) && !_editable) { return(null); } PropInPlaceColorChooser colorChooser; if (mInPlaceCtrl == null) { colorChooser = new PropInPlaceColorChooser(_editable); colorChooser.Visible = false; colorChooser.Parent = mParentWnd; mInPlaceCtrl = colorChooser; } else { colorChooser = (PropInPlaceColorChooser)mInPlaceCtrl; } colorChooser.Font = propEnum.Property.Value.Font; colorChooser.Text = propEnum.Property.Value.DisplayString; MoveControl(valueRect, propEnum, false); colorChooser.OwnerPropertyEnumerator = propEnum; return(base.ShowControl(valueRect, propEnum)); }
public override System.Windows.Forms.Control ShowControl(Rectangle valueRect, PropertyEnumerator propEnum) { PropInPlaceTextbox edit = null; if (mInPlaceCtrl == null) { edit = new PropInPlaceTextbox(false); edit.Visible = false; edit.Parent = mParentWnd; edit.Multiline = true; mInPlaceCtrl = edit; } else edit = (PropInPlaceTextbox)mInPlaceCtrl; NotifyInPlaceControlCreated(propEnum); edit.OwnerPropertyEnumerator = propEnum; edit.Font = propEnum.Property.Value.Font; MoveControl(valueRect, propEnum); if (edit.Focused == false) // are we already being editing ? If yes, don't touch the edit content { if (edit.Text != propEnum.Property.Value.DisplayString) edit.Text = propEnum.Property.Value.DisplayString; } return base.ShowControl(valueRect, propEnum); }
public override Control ShowControl(Rectangle valueRect, PropertyEnumerator propEnum) { if ((propEnum.Property.Value.IsReadOnly(propEnum)) && !_editable) return null; PropInPlaceColorChooser colorChooser; if (mInPlaceCtrl == null) { colorChooser = new PropInPlaceColorChooser(_editable); colorChooser.Visible = false; colorChooser.Parent = mParentWnd; mInPlaceCtrl = colorChooser; } else colorChooser = (PropInPlaceColorChooser)mInPlaceCtrl; colorChooser.Font = propEnum.Property.Value.Font; colorChooser.Text = propEnum.Property.Value.DisplayString; MoveControl(valueRect, propEnum, false); colorChooser.OwnerPropertyEnumerator = propEnum; return base.ShowControl(valueRect, propEnum); }
public override Control ShowControl(Rectangle valueRect, PropertyEnumerator propEnum) { if ((propEnum.Property.Value.IsReadOnly(propEnum)) && !_editable) return null; PropInPlaceTrackbar trackbar; if (mInPlaceCtrl == null) { trackbar = new PropInPlaceTrackbar(_editable); trackbar.Visible = false; trackbar.Parent = mParentWnd; mInPlaceCtrl = trackbar; } else trackbar = (PropInPlaceTrackbar)mInPlaceCtrl; NotifyInPlaceControlCreated(propEnum); trackbar.OwnerPropertyEnumerator = propEnum; trackbar.Font = propEnum.Property.Value.Font; MoveControl(valueRect, propEnum); return base.ShowControl(valueRect, propEnum); }
public override Control ShowControl(Rectangle valueRect, PropertyEnumerator propEnum) { PropInPlaceCheckbox checkboxes; if (mInPlaceCtrl == null) { checkboxes = new PropInPlaceCheckbox(); checkboxes.Visible = false; checkboxes.Parent = mParentWnd; mInPlaceCtrl = checkboxes; } else { checkboxes = (PropInPlaceCheckbox)mInPlaceCtrl; } NotifyInPlaceControlCreated(propEnum); // checkboxes.Text = propEnum.Property.Value.DisplayString; checkboxes.OwnerPropertyEnumerator = propEnum; checkboxes.Font = propEnum.Property.Value.Font; MoveControl(valueRect, propEnum); return(base.ShowControl(valueRect, propEnum)); }
protected override bool SetValueInternal(object value, ValueUpdateSource updateSource) { bool result = false; #if _DOTNET2 NullableConverter nc = TypeConverter as NullableConverter; if ((value == null) || ((value != null) && UnderlyingType.IsInstanceOfType(value)) || ((nc != null) && ((value == null) || nc.UnderlyingType.IsInstanceOfType(value)))) #else if ((value != null) && UnderlyingType.IsInstanceOfType(value)) #endif { UnderlyingValue = value; result = true; } if (updateSource != ValueUpdateSource.FromChild) { if ((mOwnerEnumerator != null) && // mOwnerEnumerator could be null for the boolean of Property._enabledVariable !mOwnerEnumerator.Property.Value.NoLinkWithChildren) { PropertyTypeDescriptorContext context = GetTypeDescriptorContext(OwnerEnumerator); if (TypeConverter.GetPropertiesSupported(context) == false) { PropertyEnumerator childEnum = mOwnerEnumerator.Children; if (childEnum.Count > 0) { string masterStr = mOwnerEnumerator.Property.Value.GetStringValue(); char separator = mOwnerEnumerator.Property.Value.GroupedValueSeparator; while (childEnum != childEnum.RightBound) { masterStr.TrimStart(null); int count = masterStr.IndexOf(separator); if (count != -1) { childEnum.Property.Value.SetValue(masterStr.Substring(0, count)); if (count + 2 < masterStr.Length) { masterStr = masterStr.Substring(count + 2); // advance after the separator and the leading space } } else { childEnum.Property.Value.SetValue(masterStr); break; } childEnum.MoveNext(); } } } } } return(result); }
public void UpdateInPlaceControlFromValue(PropertyEnumerator propEnum) { if (mInPlaceCtrl != null) { (mInPlaceCtrl as IInPlaceControl).OwnerPropertyEnumerator = propEnum; mInPlaceCtrl.Refresh(); } }
public PropertyTypeDescriptorContext(PropertyDescriptor descriptor, object instance, PropertyEnumerator propEnum, PropertyGrid propGrid) { _descriptor = descriptor; _targetInstance = instance; _propEnum = propEnum; _propertyGrid = propGrid; }
public override Rectangle GetLabelColumnRect(Rectangle itemRect, PropertyEnumerator enumerator) { Rectangle labelRect = itemRect; labelRect.X = ParentGrid.LeftColumnWidth + 1; labelRect.Width = itemRect.Right - labelRect.Left; return labelRect; }
public override void MoveControl(Rectangle valueRect, PropertyEnumerator propEnum) { if (mInPlaceCtrl == null) { return; } if (mInPlaceCtrl is PropInPlaceDateTime) { valueRect.Height--; Win32Calls.RECT rect = new Win32Calls.RECT(); Win32Calls.GetWindowRect(mInPlaceCtrl.Handle, ref rect); Rectangle bounds = Rectangle.FromLTRB(rect.Left, rect.Top, rect.Right, rect.Bottom); bounds = mInPlaceCtrl.Parent.RectangleToClient(bounds); if (bounds != valueRect) { mInPlaceCtrl.Invalidate(); // Bounds doesn't work because of DateTimePicker.PreferredHeight Win32Calls.SetWindowPos(mInPlaceCtrl.Handle, IntPtr.Zero, valueRect.Left, valueRect.Top, valueRect.Width, valueRect.Height, Win32Calls.SWP_NOZORDER | Win32Calls.SWP_NOACTIVATE | Win32Calls.SWP_NOREDRAW); // Causes WM_NCPAINT Win32Calls.RedrawWindow(mInPlaceCtrl.Handle, IntPtr.Zero, IntPtr.Zero, 0x0561); } } else { // Find where the string is actually displayed (a look instance could place it anywhere) Graphics graphics = mParentWnd.CreateGraphics(); Rectangle strRect = propEnum.Property.Value.GetStringValueRect(graphics, valueRect, Point.Empty /* not used */); strRect.X -= (propEnum.Property.Value.EditboxLeftMargin == -1 ? propEnum.Property.ParentGrid.GlobalTextMargin : propEnum.Property.Value.EditboxLeftMargin); strRect.Width = valueRect.Right - strRect.Left; // Calculate the height of the editbox, based on the font height Rectangle editRect = strRect; editRect.Inflate(0, -1); Win32Calls.TEXTMETRIC tm = new Win32Calls.TEXTMETRIC(); Win32Calls.GetTextMetrics(graphics, mInPlaceCtrl.Font, ref tm); graphics.Dispose(); int extraHeight = editRect.Height - tm.tmHeight; editRect.Y += extraHeight / 2; editRect.Height -= extraHeight; if (mInPlaceCtrl.Bounds != editRect) { mInPlaceCtrl.Bounds = editRect; } } }
public virtual Rectangle GetLabelColumnRect(Rectangle itemRect, PropertyEnumerator enumerator) { Rectangle labelRect = itemRect; labelRect.X = ParentGrid.LeftColumnWidth + 1; labelRect.Width = ParentGrid.LabelColumnWidth; return(labelRect); }
protected internal override bool ValidateSelfValueFromModifiedChild(PropertyEnumerator modifiedChildEnum, object value) { if (Validator != null) { if (modifiedChildEnum.Property.Value is PropertyValueSimulated) { try { PropertyTypeDescriptorContext context = GetTypeDescriptorContext(modifiedChildEnum); PropertyDescriptorCollection collection = TypeConverter.GetProperties(context, GetValue()); PropertyValue childValue = modifiedChildEnum.Property.Value; if (collection != null) { IDictionary dictionary = new Hashtable(collection.Count); foreach (PropertyDescriptor propertyDescriptor in collection) { if (modifiedChildEnum.Property.Name.Equals(propertyDescriptor.Name)) { if (value is string) { dictionary[propertyDescriptor.Name] = childValue.TypeConverter.ConvertFromString( context, childValue.CultureInfo, childValue.GetActualString(value as string)); } else { dictionary[propertyDescriptor.Name] = value; } } else { dictionary[propertyDescriptor.Name] = propertyDescriptor.GetValue(childValue.TargetInstance); } } // Create the parent value from all the sibling values object newParentValue = TypeConverter.CreateInstance(context, dictionary); // Validate the parent value PropertyEnumerator invalidPropEnum; if (ValidateValue(newParentValue, out invalidPropEnum)) { return(true); } } } catch (Exception) { return(false); } return(true); } } return(true); }
public override Rectangle GetLabelColumnRect(Rectangle itemRect, PropertyEnumerator enumerator) { Rectangle labelRect = itemRect; labelRect.X = ParentGrid.LeftColumnWidth + 1; labelRect.Width = itemRect.Right - labelRect.Left; return(labelRect); }
public override void DrawLeftColumnBackground(Graphics graphics, Rectangle rect, PropertyEnumerator propEnum) { Rectangle fillRect = Rectangle.Intersect(rect, Rectangle.Round(graphics.ClipBounds)); if (fillRect.IsEmpty) return; using(SolidBrush brush = new SolidBrush(Grid.GridColor)) graphics.FillRectangle(brush, fillRect); }
public override bool ValidateValue(object value, out PropertyEnumerator invalidPropertyEnum) { invalidPropertyEnum = Grid.RightBound; // Validate the underlying value if (Validator != null) { if (Validator.Check(value, false) == false) { invalidPropertyEnum = mOwnerEnumerator; return(false); } } // Validate children if any if (mOwnerEnumerator != null) { PropertyEnumerator childEnum = mOwnerEnumerator.Children; while (childEnum != childEnum.RightBound) { if (childEnum.Property.Value != null) { PropertyValidatorBase validator = childEnum.Property.Value.Validator; if (validator != null) { object childValue = childEnum.Property.Value.PropertyDescriptor.GetValue(value); if (validator.Check(childValue, false) == false) { invalidPropertyEnum = childEnum; return(false); } } } childEnum.MoveNext(); } } // Validate parent if any if (mOwnerEnumerator != null) { PropertyEnumerator parentEnum = mOwnerEnumerator.Parent; if ((parentEnum.Property != null) && (parentEnum.Property.Value != null)) { bool valid = parentEnum.Property.Value.ValidateSelfValueFromModifiedChild(mOwnerEnumerator, value); if (!valid) { invalidPropertyEnum = parentEnum; } return(valid); } } return(true); }
public virtual void DrawPropertyValueBackground(Graphics graphics, Rectangle rect, PropertyEnumerator enumerator) { Rectangle fillRect = Rectangle.Intersect(rect, Rectangle.Round(graphics.ClipBounds)); if (fillRect.IsEmpty) return; Brush brush = new SolidBrush(enumerator.Property.Value.BackColor); graphics.FillRectangle(brush, fillRect); brush.Dispose(); }
public override bool IsReadOnly(PropertyEnumerator selfEnum) { if (!Grid.Grid.Enabled && (Grid.DisableMode == PropertyGrid.DisableModes.Simple)) return true; if (ParentValue.IsReadOnly(selfEnum.Parent)) return true; return false; }
public override bool IsReadOnly(PropertyEnumerator selfEnum) { if (!Grid.Grid.Enabled && ((Grid.DisableMode & PropertyGrid.DisableModes.Simple) != 0)) { return(true); } ReadOnlyAttribute attr = (ReadOnlyAttribute)GetAttribute(typeof(ReadOnlyAttribute)); return((attr != null) && attr.IsReadOnly); }
public override void MoveControl(Rectangle valueRect, PropertyEnumerator propEnum) { if (mInPlaceCtrl == null) return; if (mInPlaceCtrl is PropInPlaceDateTime) { valueRect.Height--; Win32Calls.RECT rect = new Win32Calls.RECT(); Win32Calls.GetWindowRect(mInPlaceCtrl.Handle, ref rect); Rectangle bounds = Rectangle.FromLTRB(rect.Left, rect.Top, rect.Right, rect.Bottom); bounds = mInPlaceCtrl.Parent.RectangleToClient(bounds); if (bounds != valueRect) { mInPlaceCtrl.Invalidate(); // Bounds doesn't work because of DateTimePicker.PreferredHeight Win32Calls.SetWindowPos(mInPlaceCtrl.Handle, IntPtr.Zero, valueRect.Left, valueRect.Top, valueRect.Width, valueRect.Height, Win32Calls.SWP_NOZORDER | Win32Calls.SWP_NOACTIVATE | Win32Calls.SWP_NOREDRAW); // Causes WM_NCPAINT Win32Calls.RedrawWindow(mInPlaceCtrl.Handle, IntPtr.Zero, IntPtr.Zero, 0x0561); } } else { // Find where the string is actually displayed (a look instance could place it anywhere) Graphics graphics = mParentWnd.CreateGraphics(); Rectangle strRect = propEnum.Property.Value.GetStringValueRect(graphics, valueRect, Point.Empty /* not used */); strRect.X -= (propEnum.Property.Value.EditboxLeftMargin == -1 ? propEnum.Property.ParentGrid.GlobalTextMargin : propEnum.Property.Value.EditboxLeftMargin); strRect.Width = valueRect.Right - strRect.Left; // Calculate the height of the editbox, based on the font height Rectangle editRect = strRect; editRect.Inflate(0, -1); Win32Calls.TEXTMETRIC tm = new Win32Calls.TEXTMETRIC(); Win32Calls.GetTextMetrics(graphics, mInPlaceCtrl.Font, ref tm); graphics.Dispose(); int extraHeight = editRect.Height - tm.tmHeight; editRect.Y += extraHeight / 2; editRect.Height -= extraHeight; if (mInPlaceCtrl.Bounds != editRect) mInPlaceCtrl.Bounds = editRect; } }
public override void OnDraw(Graphics graphics, Rectangle valueRect, Color textColor, PropertyEnumerator propEnum, string drawAnotherString) { if ((drawAnotherString != null) && (drawAnotherString.Length == 0)) return; Rectangle strRect = GetDisplayStringRect(graphics, valueRect, Point.Empty /* not used */); strRect.Y += 2; strRect.Height = valueRect.Bottom - 2 - strRect.Y; Win32Calls.DrawText(graphics, DisplayString, ref strRect, Value.Font, textColor, Win32Calls.DT_WORDBREAK | Win32Calls.DT_EDITCONTROL | Win32Calls.DT_NOPREFIX); }
/// <summary> /// Searches a property given its ID inside the whole property tree but only from a given enumerator and beyond. /// The enumerator can be sibling or deep and will restrict the search accordingly. /// </summary> /// <param name="afterEnumerator">The enumerator from which the property will be searched.</param> /// <param name="propertyId">The ID of the property being searched.</param> /// <returns>A deep enumerator pointing to the found property. If not found it will point to RightBound.</returns> public PropertyEnumerator FindAfter(PropertyEnumerator afterEnumerator, int propertyId) { PropertyEnumerator propEnum = new PropertyDeepEnumerator(afterEnumerator.Node); while (propEnum.MoveNext() != propEnum.RightBound) { if (propEnum.Property.Id == propertyId) break; } // If the element is not found, the enumerator will point to RightBound return propEnum; }
public virtual Rectangle GetLabelTextRect(Rectangle itemRect, PropertyEnumerator enumSelf) { Rectangle labelRect = itemRect; Rectangle imgRect = GetImageRect(itemRect, enumSelf); if (imgRect != Rectangle.Empty) { labelRect.X = imgRect.Right; } else { Rectangle checkboxRect = GetManuallyDisableRect(itemRect, enumSelf); if (checkboxRect != Rectangle.Empty) { labelRect.X = checkboxRect.Right; } else { Rectangle signRect = GetSignRect(itemRect, enumSelf); if (signRect != Rectangle.Empty) { labelRect.X = signRect.Right; } else { labelRect.X = ParentGrid.LeftColumnWidth + 1 + (enumSelf.Depth - 1) * (_grid.GlobalTextMargin + TreeGlyphWidth); } } } labelRect.X += _grid.GlobalTextMargin; Graphics graphics = ParentGrid.CreateGraphics(); labelRect.Width = Win32Calls.GetTextExtent(graphics, DisplayName, Font).Width; graphics.Dispose(); int maxRight = ParentGrid.LeftColumnWidth + 1 + ParentGrid.LabelColumnWidth; if ((ParentGrid.EllipsisMode & PropertyGrid.EllipsisModes.EllipsisOnLabels) != 0) { maxRight -= _grid.GlobalTextMargin; } if (labelRect.Right > maxRight) { labelRect.Width = maxRight - labelRect.Left; } return(labelRect); }
public override Control ShowControl(Rectangle valueRect, PropertyEnumerator propEnum) { if (propEnum.Property.Value.ReadOnly) { PropInPlaceTextbox edit; if ((mInPlaceCtrl == null) || !(mInPlaceCtrl is PropInPlaceTextbox)) { edit = new PropInPlaceTextbox(false); edit.Visible = false; edit.Parent = mParentWnd; mInPlaceCtrl = edit; } else { edit = (PropInPlaceTextbox)mInPlaceCtrl; } NotifyInPlaceControlCreated(propEnum); edit.OwnerPropertyEnumerator = propEnum; edit.Font = propEnum.Property.Value.Font; // if (edit.Text != propEnum.Property.Value.DisplayString) // edit.Text = propEnum.Property.Value.DisplayString; } else { PropInPlaceDateTime dateTime; if ((mInPlaceCtrl == null) || !(mInPlaceCtrl is PropInPlaceDateTime)) { dateTime = new PropInPlaceDateTime(); dateTime.Visible = false; dateTime.Parent = mParentWnd; #if _DOTNET2 dateTime.AutoSize = false; #endif mInPlaceCtrl = dateTime; } else { dateTime = (PropInPlaceDateTime)mInPlaceCtrl; } dateTime.OwnerPropertyEnumerator = propEnum; dateTime.Font = propEnum.Property.Value.Font; // dateTime.Value = (DateTime)propEnum.Property.Value.GetValue(); } MoveControl(valueRect, propEnum); return(base.ShowControl(valueRect, propEnum)); }
private void GetSubProperties(PropertyEnumerator rootProperty, String propertyPath) { ArrayList propertyList = new ArrayList(); state.GetSubTags(out requestId, propertyPath, out propertyList); foreach (ModelProperty modelProperty in propertyList) { PropertyEnumerator propertyEnum = AppendManagedProperty(rootProperty, id++, modelProperty.Path, modelProperty.State.GetType(), modelProperty.State, ""); AppendManagedProperty(propertyEnum, -1, "", typeof(dummyType), new dummyType(), ""); ExpandProperty(propertyEnum, false); } }
internal override void OnPropertyClicked(PropertyEnumerator enumSelf, Point point, Rectangle itemRect) { if ((ParentGrid.Enabled == false) && (ParentGrid.DisableMode != PropertyGrid.DisableModes.None)) return; Rectangle labelRect = GetLabelTextRect(itemRect, enumSelf); if (labelRect.Contains(point)) { PropertyHyperLinkClickedEventArgs ev = new PropertyHyperLinkClickedEventArgs(enumSelf, HyperLink); ParentGrid.OnHyperLinkPropertyClicked(ev); } }
public void SetText(string text, PropertyEnumerator enumerator) { if ((_title != text) || (_enumerator != enumerator)) { _title = ""; Win32Calls.SendMessage(Handle, Win32Calls.TTM_UPDATETIPTEXT, 0, GetTOOLINFO()); _title = text; Win32Calls.SendMessage(Handle, Win32Calls.TTM_UPDATETIPTEXT, 0, GetTOOLINFO()); } _enumerator = enumerator; }
public virtual Rectangle GetImageRect(Rectangle itemRect, PropertyEnumerator enumSelf) { if (ImageIndex == -1) { return(Rectangle.Empty); } Rectangle imgRect = itemRect; Rectangle checkboxRect = GetManuallyDisableRect(itemRect, enumSelf); if (checkboxRect != Rectangle.Empty) { imgRect.X = checkboxRect.Right + _grid.GlobalTextMargin; } else { Rectangle signRect = GetSignRect(itemRect, enumSelf); if (signRect != Rectangle.Empty) { imgRect.X = signRect.Right + _grid.GlobalTextMargin; } else { if (enumSelf.Depth == 0) { imgRect.X = ParentGrid.LeftColumnWidth + 1 + _grid.GlobalTextMargin; } else { imgRect.X = ParentGrid.LeftColumnWidth + 1 + _grid.GlobalTextMargin + (enumSelf.Depth - 1) * (_grid.GlobalTextMargin + TreeGlyphWidth); } } } try { Image img = ParentGrid.ImageList.Images[ImageIndex]; imgRect.Width = img.Width; imgRect.Height = img.Height; } catch (Exception) { return(Rectangle.Empty); } imgRect.Y = itemRect.Top + ParentGrid.BasicPropertyHeight / 2 - 8; return(imgRect); }
internal void SetManuallyDisabled(PropertyEnumerator propEnum, object containerInstance, string memberName) { if (containerInstance != null) { _canBeDisabledManually = true; _enabledVariable = new PropertyValueIndirect(_grid, null, containerInstance, TypeDescriptor.GetProperties(containerInstance)[memberName], null); _enabledVariable.Grid = ParentGrid; ParentGrid.EnableProperty(propEnum, (GetManuallyDisabledVariable() && !ParentGrid.Grid.IsAncestorDisabled(propEnum))); // _enabled = (GetManuallyDisabledVariable() && !ParentGrid.Grid.IsAncestorDisabled(propEnum)); // if (_grid != null) // _grid.Grid.Invalidate(); } }
//private TriStateBool _readonlyByPropertyDescriptor = TriStateBool.tsUndefined; public override bool IsReadOnly(PropertyEnumerator selfEnum) { if (!Grid.Grid.Enabled && (Grid.DisableMode == PropertyGrid.DisableModes.Simple)) { return(true); } if ((selfEnum.Parent.Property != null) && (selfEnum.Parent.Property.Value != null)) { if (!selfEnum.Parent.Property.Value.NoLinkWithChildren && (selfEnum.Parent.Property.Value.IsReadOnly(selfEnum.Parent))) { return(true); } } // Check if a UITypeEditor has been found. Even if the property is marked Readonly (has only a get // accessor for example), the presence of an editor makes it editable (this is the case for collections // for example in the .net framework) ReadOnlyAttribute manualReadOnlyAttr = (ReadOnlyAttribute)base.GetAttribute(typeof(ReadOnlyAttribute)); if ((mFeel is PropertyUITypeEditorFeel) && ((manualReadOnlyAttr == null) || !manualReadOnlyAttr.IsReadOnly)) { return(false); } bool readonlyPd = ((PropertyDescriptor)((Utilities.KeyValuePair)_targets[0]).Key).IsReadOnly; ReadOnlyAttribute attr = (ReadOnlyAttribute)selfEnum.Property.Value.GetAttribute(typeof(ReadOnlyAttribute)); bool readonlyByAttribute = (attr != null && attr.IsReadOnly); bool ro = (readonlyPd || readonlyByAttribute); /* * // Some checks on the readonly state (it could have been changed by a PropertyDescriptor) * if (_readonlyByPropertyDescriptor != TriStateBool.tsUndefined) * { * if ((readonlyPd && (_readonlyByPropertyDescriptor == TriStateBool.tsFalse)) || * (!readonlyPd && (_readonlyByPropertyDescriptor == TriStateBool.tsTrue))) * { * if (ro && (selfEnum.Property.ParentGrid.ReadOnlyVisual == PropertyGrid.ReadOnlyVisuals.Disabled) && * selfEnum.Property.Enabled) * selfEnum.Property.ParentGrid.EnableProperty(selfEnum, false); * else if (!ro && !selfEnum.Property.Enabled) * selfEnum.Property.ParentGrid.EnableProperty(selfEnum, true); * } * } * * _readonlyByPropertyDescriptor = (readonlyPd ? TriStateBool.tsTrue : TriStateBool.tsFalse); */ return(ro); }
public override Control ShowControl(Rectangle valueRect, PropertyEnumerator propEnum) { if (propEnum.Property.Value.ReadOnly) { PropInPlaceTextbox edit; if ((mInPlaceCtrl == null) || !(mInPlaceCtrl is PropInPlaceTextbox)) { edit = new PropInPlaceTextbox(false); edit.Visible = false; edit.Parent = mParentWnd; mInPlaceCtrl = edit; } else edit = (PropInPlaceTextbox)mInPlaceCtrl; NotifyInPlaceControlCreated(propEnum); edit.OwnerPropertyEnumerator = propEnum; edit.Font = propEnum.Property.Value.Font; // if (edit.Text != propEnum.Property.Value.DisplayString) // edit.Text = propEnum.Property.Value.DisplayString; } else { PropInPlaceDateTime dateTime; if ((mInPlaceCtrl == null) || !(mInPlaceCtrl is PropInPlaceDateTime)) { dateTime = new PropInPlaceDateTime(); dateTime.Visible = false; dateTime.Parent = mParentWnd; #if _DOTNET2 dateTime.AutoSize = false; #endif mInPlaceCtrl = dateTime; } else dateTime = (PropInPlaceDateTime)mInPlaceCtrl; dateTime.OwnerPropertyEnumerator = propEnum; dateTime.Font = propEnum.Property.Value.Font; // dateTime.Value = (DateTime)propEnum.Property.Value.GetValue(); } MoveControl(valueRect, propEnum); return base.ShowControl(valueRect, propEnum); }
public override bool OverrideCursor(Point mouseLocation, Rectangle itemRect, PropertyEnumerator propEnum) { if ((ParentGrid.Enabled == false) && (ParentGrid.DisableMode != PropertyGrid.DisableModes.None)) return false; Rectangle labelRect = GetLabelTextRect(itemRect, propEnum); if (labelRect.Contains(mouseLocation) && Enabled) { ParentGrid.Grid.Cursor = Cursors.Hand; return true; } return false; }
public override void OnDraw(Graphics graphics, Rectangle valueRect, Color textColor, PropertyEnumerator propEnum, string drawAnotherString) { if ((drawAnotherString != null) && (drawAnotherString.Length == 0)) return; valueRect.Height++; Rectangle strRect = GetDisplayStringRect(graphics, valueRect, Point.Empty); strRect.Width = valueRect.Right - strRect.Left; Win32Calls.DrawText(graphics, (drawAnotherString == null ? GetDisplayStringInternal() : drawAnotherString), ref strRect, Value.Font, textColor, Win32Calls.DT_VCENTER | Win32Calls.DT_SINGLELINE | Win32Calls.DT_NOPREFIX | ((Value.Grid.EllipsisMode & PropertyGrid.EllipsisModes.EllipsisOnValues) != 0 ? Win32Calls.DT_END_ELLIPSIS : 0)); }
public override void OnDraw(Graphics graphics, Rectangle valueRect, Color textColor, PropertyEnumerator propEnum, string drawAnotherString) { if ((drawAnotherString != null) && (drawAnotherString.Length == 0)) return; Pen pen = (Pen)propEnum.Property.Value.GetValue(); if (pen.Width > valueRect.Height - 2) { pen = (Pen)pen.Clone(); pen.Width = valueRect.Height - 2; } int margin = Value.Grid.GlobalTextMargin; graphics.DrawLine(pen, valueRect.Left + margin, valueRect.Top + valueRect.Height / 2, valueRect.Right - margin, valueRect.Top + valueRect.Height / 2); }
public override void OnDraw(Graphics graphics, Rectangle valueRect, Color textColor, PropertyEnumerator propEnum, string drawAnotherString) { if ((drawAnotherString != null) && (drawAnotherString.Length == 0)) return; valueRect.Height++; Rectangle strRect = GetDisplayStringRect(graphics, valueRect, Point.Empty /* not used */); strRect.Y += (Value.Grid.PropertyVerticalMargin % 2 == 0 ? 1 : 0); strRect.X -= Value.Grid.GlobalTextMargin - 3; strRect.Width = valueRect.Right - strRect.Left; StringFormat stringFormat = (StringFormat)StringFormat.GenericDefault.Clone(); stringFormat.FormatFlags = StringFormatFlags.NoWrap; stringFormat.LineAlignment = StringAlignment.Center; graphics.DrawString(DisplayString, Value.Font, new SolidBrush(textColor), strRect, stringFormat); }
public override void MoveControl(Rectangle valueRect, PropertyEnumerator propEnum) { if (mInPlaceCtrl == null) return; Graphics graphics = mParentWnd.CreateGraphics(); Rectangle strRect = propEnum.Property.Value.GetStringValueRect(graphics, valueRect, Point.Empty /* not used */); graphics.Dispose(); int margin = propEnum.Property.ParentGrid.GlobalTextMargin; strRect.X -= (propEnum.Property.Value.EditboxLeftMargin == -1 ? margin : propEnum.Property.Value.EditboxLeftMargin); strRect.Width = valueRect.Right - strRect.Left - margin; strRect.Y += 2; strRect.Height = valueRect.Bottom - strRect.Y - 1; if (mInPlaceCtrl.Bounds != strRect) mInPlaceCtrl.Bounds = strRect; }
public override void OnDraw(Graphics graphics, Rectangle valueRect, Color textColor, PropertyEnumerator propEnum, string drawAnotherString) { if ((drawAnotherString != null) && (drawAnotherString.Length == 0)) return; if (propEnum.Property.Value.HasMultipleValues) return; Rectangle colorRect = valueRect; colorRect.Y += 4; colorRect.Height -= 9; int margin = propEnum.Property.ParentGrid.GlobalTextMargin; colorRect.X += margin; colorRect.Width -= 2 * margin; Brush whiteBrush = new SolidBrush(Color.White); Brush grayBrush = new SolidBrush(Color.Gray); for (int y = colorRect.Top + 1; y < colorRect.Bottom; y += 4) { int height = (y + 4 > colorRect.Bottom ? colorRect.Bottom - y : 4); for (int x = colorRect.Left + 1; x < colorRect.Right; x += 5) { int width = (x + 5 > colorRect.Right ? colorRect.Right - x : 5); if (((x - (colorRect.Left + 1)) % 10 == ((y - (colorRect.Top + 1)) % 8 == 0 ? 0 : 5))) graphics.FillRectangle(whiteBrush, x, y, width, height); else graphics.FillRectangle(grayBrush, x, y, width, height); } } whiteBrush.Dispose(); grayBrush.Dispose(); // Draw the color with alpha Brush brush = new SolidBrush((Color)Value.GetActualValue(drawAnotherString)); graphics.FillRectangle(brush, colorRect); brush.Dispose(); // Draw a black frame around Pen blackPen = new Pen(Color.Black); graphics.DrawRectangle(blackPen, colorRect); blackPen.Dispose(); }