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