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! :)
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.
Re: Custom Object Properties (C#)
Could you show me how to override the properties?
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.