Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
How to subclass control?
Message
From
09/04/2008 17:03:50
 
 
To
17/02/2007 00:43:23
General information
Forum:
ASP.NET
Category:
Coding, syntax and commands
Environment versions
Environment:
C# 2.0
OS:
Windows XP SP2
Network:
Windows 2000 Server
Database:
MS SQL Server
Miscellaneous
Thread ID:
01184867
Message ID:
01309533
Views:
23
In my custom class library, when sublassing the .NET base classes to use in my project, can you not just hard-code property values at the class level?

Something like this:

public class MyTextBox : TextBox
{
this.forecolor = //-- color stuff here--//;
this.font = //--font stuff here --//;
this.size = //-- Size stuff here --//;;

}

It does not like the "this." and I tried "base.", but no luck either.

The "getter" and "setter" example you gave (copied below) just seems like a ton of code just to set a few properties.

I want to set the visual properties of my custom base classes so that I when I change them in my class library, it will make every form in my app automatically update the labels and texboxes to the new font and forecolor, backcolor etc. I want visual inheretence for these controls at the class lib level, not the propery sheet level.

I am coming from a VFP background where this matter was VERY easy.




>Holger,
>
>Here's the syntax for overriding properties and giving them the ability to be re-set to a Default in the Property Sheet:
>
>
>public class MyTextBox : TextBox
>{
>    private string m_MyProperty;
>
>    public MyTextBox
>    {
>        this.m_MyProperty = "";
>    }
>
>    [DefaultValue("")]
>    public string MyProperty
>    {
>        get {return this.m_MyProperty;}
>        set {this.m_MyProperty = value;}
>    }
>    [DefaultValue(typeof(Color), "Window")]
>    public override Color BackColor
>    {
>        get {return base.BackColor;}
>        set {base.BackColor = value;}
>    }
>    [DefaultValue(typeof(Color), "WindowText")]
>    public override Color ForeColor
>    {
>        get {return base.ForeColor;}
>        set {base.ForeColor= value;}
>    }
>}
>
>
>Setting some of these properties doesn't always work as you would expect them to ... one that comes to mind is "Text" ... you may or may not have problems setting a default for that one, depending on which control you're sub-classing. Also, some properties aren't virtual and can't be overridden. For those properties, you can use "new" instead of "override".
>
>>And another question: Would the changes, made to these properties, appear in the formdesigner, if you drop the control there?
>
>Yes!!
>
>~~Bonnie
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform