Beispiel #1
0
 private void SetTextBoxFromProperty()
 {
     if (m_context != null && m_context.LastSelectedObject != null)
     {
         string propertyText = PropertyUtils.GetPropertyText(m_context.LastSelectedObject, m_descriptor);
         m_initialText       = propertyText;
         m_textBox.Text      = propertyText;
         m_textBox.Font      = Font;
         m_textBox.ReadOnly  = m_descriptor.IsReadOnly;
         m_textBox.ForeColor = (m_descriptor.IsReadOnly) ? SystemColors.GrayText : ForeColor;
     }
 }
Beispiel #2
0
        /// <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);
        }
        /// <summary>
        /// Gets property text for this property, possibly using a TypeConverter</summary>
        /// <returns>Property text for this property</returns>
        public string GetPropertyText()
        {
            string text = PropertyUtils.GetPropertyText(LastSelectedObject, m_descriptor);

            return(text);
        }