开发者

Custom control doesn't expose image properties in the Designer

开发者 https://www.devze.com 2023-03-04 15:24 出处:网络
I have made a custom trackbar control, mostly as an exercise. I know i could/should have just inherited what i needed instead of reinventing the wheel, but i have learn开发者_如何学Pythoned a lot duri

I have made a custom trackbar control, mostly as an exercise. I know i could/should have just inherited what i needed instead of reinventing the wheel, but i have learn开发者_如何学Pythoned a lot during my endeavour. Now, i have a lot of properties, and all of them shows up in the designer apart from a couple of image properties. This is what i have, modelled on the other working properties (those are ints and Colors and what not, and they all work as expected...), so maybe i should be doing Images in some other way. Bottom line, i don't know what i'm doing :)

EDIT : My custom control is in a Windows Forms solution (VC# 2008 Express), and to clarify, my problem is that some of my control's properties (the Image properties) isn't showing in the properties-tab during design-time.

EDIT 2 : After reading up on DependencyProperty and totally failed to understand that concept (I'm very noob at programmin teh codez or what you gurus call this black voodoo magic??). I have gotten used to letting the IDE fix all my troubles, and i was pleased to see the IDE happily showing my other properties, such as Color BarColor, int Value etc. etc. Why would Image LeftImage be any different, a lot of the standard controls have Image properties and maybe it's naïve of me to think that the IDE can figure all of my mistakes out, but surely the guys at Microsoft did not construct a new editor every time they had to set an image property in their controls. My bet is that they reused something, which i should be able to do as well.

I'm stuck :(

Here's 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();
        }
    }

By the way, what is the difference between DefaultValue and DefaultValueAttribute?

Thanks for any pointers and help! /Mikael


I have found something here: http://msdn.microsoft.com/en-us/library/system.drawing.design.imageeditor.aspx

Consider this solved.


For Show the Image in the Designer you need to overrides the OnPaint Method drawing it.

DefaultValue is the same that DefaultValueAttribute. All Attributes in .NET are clases that inherits from System.Attribute, and all those class are something like Name*Attribute* where Attribute is fixed. Then "DefaultValue" is like an Alias.


Your example doesn't show what exactly is your problem but if you create custom control and want to access its properties from designer you should use smth like that:

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

hope this helps you

0

精彩评论

暂无评论...
验证码 换一张
取 消