-
Oct 18th, 2012, 01:50 PM
#1
Thread Starter
Member
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.
-
Oct 19th, 2012, 03:17 AM
#2
Addicted Member
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.
-
Oct 19th, 2012, 04:28 AM
#3
Thread Starter
Member
Re: Custom Object Properties (C#)
Could you show me how to override the properties?
-
Oct 19th, 2012, 05:48 AM
#4
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|