Results 1 to 4 of 4

Thread: Custom Object Properties (C#)

  1. #1

    Thread Starter
    Member
    Join Date
    Sep 2012
    Location
    Sweden
    Posts
    44

    Custom Object Properties (C#)

    Hello all.

    I have created a custom control:
    Code:
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Windows.Forms;
    using System.ComponentModel;
    
    namespace NewApp
    {
        class Application : Panel
        {
            private bool isRunning = false;
    
            [Description("Is the application running?")]
            [Category("Super Stuff")]
            [DefaultValue(false)]
    
            public bool IsRunning
            {
                get { return isRunning; }
            }
    
        }
    }
    How can I set default values of this control, e.g width, height, backcolor, location?
    Since it's a panel, is there a way to add objects to the panel by default, e.g picturebox, textbox?

    Thanks!
    Last edited by ErikJohansson; Oct 18th, 2012 at 02:10 PM.

  2. #2
    Addicted Member
    Join Date
    Sep 2008
    Posts
    149

    Re: Custom Object Properties (C#)

    You can add controls to the panel through designer mode, just drop on the panel.
    For default values for height, backcolor, location etc. I think you need to override those properties and add default values to them.

  3. #3

    Thread Starter
    Member
    Join Date
    Sep 2012
    Location
    Sweden
    Posts
    44

    Re: Custom Object Properties (C#)

    Could you show me how to override the properties?

  4. #4
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,344

    Re: Custom Object Properties (C#)

    You don't override properties to set their values. You override a member to change its behaviour. If you want to set default values for some properties then do it in the constructor.

    By the way, 'Application' is a very bad name for a control. I'm not sure what it actually is supposed to be used for but maybe 'ApplicationPanel' would be appropriate.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width