public void DefaultValues() { Assert.AreSame(graphics, editor.EditValue(null, graphics), "EditValue(2)"); Assert.AreSame(graphics, editor.EditValue(null, null, graphics), "EditValue(3)"); Assert.AreEqual(UITypeEditorEditStyle.None, editor.GetEditStyle(), "GetEditStyle()"); Assert.AreEqual(UITypeEditorEditStyle.None, editor.GetEditStyle(null), "GetEditStyle(null)"); Assert.IsFalse(editor.GetPaintValueSupported(), "GetPaintValueSupported()"); Assert.IsFalse(editor.GetPaintValueSupported(null), "GetPaintValueSupported(null)"); Assert.IsFalse(editor.IsDropDownResizable, "IsDropDownResizable"); }
/// <summary> /// Performs custom actions and raises the <see cref="E:System.Windows.Forms.Control.Layout"></see> event</summary> /// <param name="levent">A <see cref="T:System.Windows.Forms.LayoutEventArgs"></see> that contains the event data</param> protected override void OnLayout(LayoutEventArgs levent) { if (m_context != null) { int x = 1; int width = base.Width; UITypeEditor editor = WinFormsPropertyUtils.GetUITypeEditor(m_descriptor, this); if (editor != null) { if (editor.GetPaintValueSupported(this)) { x += PaintRectTextOffset; } m_textBox.Left = x; m_textBox.Width = width - x - m_editButton.Width; } else { // no editor, use text box and type converters m_textBox.Left = x; m_textBox.Width = width - x; } } base.OnLayout(levent); }
protected override void OnPropertyTaskItemUpdated(ToolTip toolTip, ref int currentTabIndex) { _editor = (UITypeEditor)PropertyDescriptor.GetEditor(typeof(UITypeEditor)); base.OnPropertyTaskItemUpdated(toolTip, ref currentTabIndex); if (_editor != null) { _button.Ellipsis = (_editor.GetEditStyle(TypeDescriptorContext) == UITypeEditorEditStyle.Modal); _hasSwatch = _editor.GetPaintValueSupported(TypeDescriptorContext); } else { _button.Ellipsis = false; } if (_button.Ellipsis) { EditControl.AccessibleRole = (IsReadOnly() ? AccessibleRole.StaticText : AccessibleRole.Text); } else { EditControl.AccessibleRole = (IsReadOnly() ? AccessibleRole.DropList : AccessibleRole.ComboBox); } _button.TabStop = _button.Ellipsis; _button.TabIndex = currentTabIndex++; _button.AccessibleRole = (_button.Ellipsis ? AccessibleRole.PushButton : AccessibleRole.ButtonDropDown); _button.AccessibleDescription = EditControl.AccessibleDescription; _button.AccessibleName = EditControl.AccessibleName; }
/* * GetPaintValueSupported */ /// <summary> /// Indicates whether the specified context supports painting a representation of an object's value within the specified context. /// </summary> /// <param name="context">An <see cref="T:System.ComponentModel.ITypeDescriptorContext"></see> that can be used to gain additional context information.</param> /// <returns> /// true if <see cref="M:System.Drawing.Design.UITypeEditor.PaintValue(System.Object,System.Drawing.Graphics,System.Drawing.Rectangle)"></see> is implemented; otherwise, false. /// </returns> public override bool GetPaintValueSupported(ITypeDescriptorContext context) { if (_imageEditor != null) { return(_imageEditor.GetPaintValueSupported(context)); } return(false); }
public override bool GetPaintValueSupported(ITypeDescriptorContext context) { UITypeEditor editor = lookUpEditor(context); if (editor != null) { return(editor.GetPaintValueSupported(context)); } return(base.GetPaintValueSupported(context)); }
protected override void OnPaint(PaintEventArgs e) { if (!IsEditing) { Graphics g = e.Graphics; Rectangle r = ClientRectangle; r.Inflate(-2, -2); int rh = r.Height; if (rh < 19) { rh = 19; } Rectangle rr = new Rectangle(r.X, r.Y, r.Width - rh, r.Height); Rectangle rrr = new Rectangle(r.X + rr.Width, r.Y, rh, r.Height); //do the custom rendering process here, albeit call it if (typeconv.CanConvertTo(typeof(double))) { sf.Alignment = StringAlignment.Far; } else { sf.Alignment = StringAlignment.Near; } if (Focused) { Rectangle cr = ClientRectangle; Drawing.Utils.PaintLineHighlight(null, SystemPens.Highlight, g, r.X - 1, r.Y - 1, r.Width + 1, r.Height + 1, false); } if (Value == null) { sf.Alignment = StringAlignment.Center; g.DrawString("Press F2 or double-click to edit", Font, Drawing.Factory.SolidBrush(SystemColors.GrayText), r, sf); } else { if (uieditor != null && uieditor.GetPaintValueSupported()) { uieditor.PaintValue(Value, g, rrr); g.DrawRectangle(SystemPens.WindowFrame, rrr); g.DrawString(typeconv.ConvertToString(Value), Font, SystemBrushes.ControlText, rr, sf); } else { g.DrawString(typeconv.ConvertToString(Value), Font, SystemBrushes.ControlText, r, sf); } } } base.OnPaint(e); }
/// <summary> /// Draws the property editing representation, in the same way that the control /// presents the property in the GUI. Use this method to draw inactive properties /// when multitasking a single PropertyEditingControl.</summary> /// <param name="descriptor">Property descriptor</param> /// <param name="context">Type descriptor context</param> /// <param name="bounds">Bounds containing graphics</param> /// <param name="font">Font to use for rendering property text</param> /// <param name="brush">Brush for rendering property text</param> /// <param name="g">Graphics object</param> public static void DrawProperty( PropertyDescriptor descriptor, ITypeDescriptorContext context, Rectangle bounds, Font font, Brush brush, Graphics g) { object owner = context.Instance; if (owner == null) { return; } UITypeEditor editor = WinFormsPropertyUtils.GetUITypeEditor(descriptor, context); if (editor != null) { if (editor.GetPaintValueSupported(context)) { object value = descriptor.GetValue(owner); Rectangle paintRect = new Rectangle( bounds.Left + 1, bounds.Top + 1, PaintRectWidth, PaintRectHeight); editor.PaintValue(new PaintValueEventArgs(context, value, g, paintRect)); bounds.X += PaintRectTextOffset; bounds.Width -= PaintRectTextOffset; g.DrawRectangle(SystemPens.ControlDark, paintRect); } } string valueString = PropertyUtils.GetPropertyText(owner, descriptor); bounds.Height = font.Height; if (s_textFormat.CustomFlags == CustomStringFormatFlags.TrimLeftWithEllipses) { valueString = TrimStringLeftWithEllipses(valueString, bounds, font, g); } g.DrawString(valueString, font, brush, bounds, s_textFormat.Format); }
protected override void DrawRowValueCellCore(CustomDrawRowValueCellEventArgs e, BaseEditPainter pb, BaseEditViewInfo bvi, BaseViewInfo vi) { MyPropertyGridControl grid = (MyPropertyGridControl)vi.Grid; RowProperties properties = e.Row.GetRowProperties(e.CellIndex); DescriptorContext context = grid.GetDescriptorContext(properties); UITypeEditor editor = grid.GetUITypeEditor(context); if (editor != null && editor.GetPaintValueSupported()) { int indent = 1; Size size = new Size(e.Bounds.Size.Height - 2 * indent, e.Bounds.Size.Height - 2 * indent); Rectangle bounds = new Rectangle(e.Bounds.X + indent, e.Bounds.Y + indent, size.Width, size.Height); PaintValueEventArgs args = new PaintValueEventArgs(context, grid.GetCellValue(properties.Row, 0), e.Cache.Graphics, bounds); editor.PaintValue(args); e.Cache.DrawRectangle(Pens.DarkGray, bounds); Rectangle textBounds = new Rectangle(e.Bounds.X + bounds.Width + 2 * indent + indent, e.Bounds.Y, e.Bounds.Width - bounds.Width + 2 * indent, e.Bounds.Height); grid.Appearance.RecordValue.DrawString(e.Cache, grid.GetCellDisplayText(properties.Row, 0), textBounds); } else { base.DrawRowValueCellCore(e, pb, bvi, vi); } }
public override bool GetPaintValueSupported(ITypeDescriptorContext context) { //todo: fix this for dialog editor // if (context == null) // { // return true; // } if (delegateEditor != null) { return(delegateEditor.GetPaintValueSupported(context)); } PropertyModelView.OptionItemPropertyDescriptor desc = context.PropertyDescriptor as PropertyModelView.OptionItemPropertyDescriptor; if (desc != null) { object value = desc.GetValue(null); if (value == OptionItem.VALUE_UNDEFINED) { return(true); } } return(false); }
public void UITypeEditor_GetPaintValueSupported_Invoke_ReturnsFalse(ITypeDescriptorContext context) { var editor = new UITypeEditor(); Assert.False(editor.GetPaintValueSupported(context)); }
public void UITypeEditor_GetPaintValueSupported_Invoke_ReturnsFalse() { var editor = new UITypeEditor(); Assert.False(editor.GetPaintValueSupported(null)); }
/// <inheritdoc /> public override bool GetPaintValueSupported(ITypeDescriptorContext context) => _imageEditor?.GetPaintValueSupported(context) ?? false;
public override bool GetPaintValueSupported(ITypeDescriptorContext context) { return(_parentEditor.GetPaintValueSupported(CreateContext(context))); }
public override bool GetPaintValueSupported(ITypeDescriptorContext context) { ITypeDescriptorContext wrappedContext = new TypeDescriptorContext(context, actualInstance); return(uiTypeEditor.GetPaintValueSupported(wrappedContext)); }