User control does not provide image properties in constructor

I made my own control of the trackbar, mainly as an exercise. I know that I could / should simply inherit what I need, and not reinvent the wheel, but I learned a lot during my efforts. Now I have many properties, and they all appear in the designer, except for a few image properties. This is what I have, modeled on other working properties (these are ints and Colors, and what not, and they all work as expected ...), so maybe I should do Images in a different way. Bottom line, I don't know what I'm doing :)

EDIT: My user control is in a Windows Forms solution (VC # 2008 Express), and to clarify, my problem is that some of my control properties (image properties) do not appear in the properties tab at design time.

EDIT 2: After reading DependencyProperty, I did not fully understand this concept (do I really want in programmin tez codez or what do you gurus call this black magic voodoo?). I used to let the IDE fix all my problems, and I was pleased to see that the IDE happily displays my other properties, such as Color BarColor, int Valueetc. Etc. Why it Image LeftImagewill be different, many standard controls have image properties, and it may be naive of me to think that the IDE can understand all my errors, but, of course, the guys from Microsoft did not create a new editor every time they had to set the property images in their control. My bet is that they reused something that I also have to do.

I am stuck: (

Here is my crappy CoD3Z anyway:

private Image _LeftImage;

    /// <summary>
    /// Sets the small image appearing to the left of the trackbar
    /// </summary>

    [Description("The small image appearing to the left of the trackbar"),
    Category("Appearance"),
    DefaultValue(typeof(Image),"null"),
    Browsable(true), EditorBrowsable(EditorBrowsableState.Always)]

    public Image LeftImage
    {
        private get { return _LeftImage; }
        set
        {
            if (value.Height != 16 || value.Width != 16)
            {
                _LeftImage = new Bitmap(value,new Size(16,16));
            }
            else _LeftImage = value;
            Invalidate();
        }
    }

, DefaultValue DefaultValueAttribute?

! /

+3
3

OnPaint, .

DefaultValue DefaultValueAttribute. .NET , System.Attribute, - - Name * Attribute *, Attribute . "DefaultValue" .

0

Your example does not show what exactly your problem is, but if you create your own control and want to access its properties from the designer, you should use smth:

        public static readonly DependencyProperty ValueProperty =
        DependencyProperty.Register("Value", typeof(object), typeof(CustomControl),
        new FrameworkPropertyMetadata(null, ValueChanged));

hope this helps you

0
source

All Articles