Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Subclassing a subclass
Message
De
08/10/2007 00:36:02
 
 
À
07/10/2007 22:34:15
Information générale
Forum:
ASP.NET
Catégorie:
Conception classe
Divers
Thread ID:
01256172
Message ID:
01259328
Vues:
18
Sarosh,

Everyone has different needs for their base classes. I suggest that to start out, you simply create a class library that contains the common controls you might need. You don't even have to put any code in them initially, but use those base classes instead of the .NET classes on your Forms and UserControls. As you progress with your development process, you'll discover code that you want to include at the base class level and you can go ahead and add it in then.

You don't have to include every control. Just start out with a few basic ones. As you develop your app, when you come across a control that you'd like to use that you haven't put it in your base classes yet, go ahead and stub it in now and use it. You can always add more code to it later, as you see how you'd like it to behave.

Nothing *has* to be overridden and I certainly don't know what kind of DefaultValues you might want ... that's why I can't post much, example-wise ... as I said, I have not had the time to make any kind of "simplified" version of base classes. You want a starting point? Here's one:
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;

namespace MyCompany.MyFramework.WinUI.MyClasses
{
	public class MyComboBox : System.Windows.Forms.ComboBox
	{
		// code here
	}

	public class MyTextBox : System.Windows.Forms.TextBox
	{
		// code here
	}

	public class MyButton : System.Windows.Forms.Button
	{
		// code here
	}
}
<g>

All the basic controls can be sub-classed in one class library file, since these can not be visually sub-classed.

~~Bonnie


>Hi!
>
>Sorry I did not mean to say that you should post your framework here, just the bare bones of a class e.g. TextBox, Combobox with the typical overrides like Default value etc. which could be a starting point.
>
>Sarosh
>
>>Sarosh,
>>
>>>>Do you have something that you can share with all of us there on UT?
>>e.g. A base class library with all the basic controls (TextBox, ComboBox etc) with the correct/required overrides etc.

>>
>>Nope, afraid not. Some of our Framework classes are pretty complicated and I have never taken the time to make a simplified version for public consumption, other than in bits and pieces in answer to some posts here.
>>
>>I can guarantee you that the company I work for would not like me posting our Framework classes, in their entirety, anywhere. <g>
>>
>>~~Bonnie
>>
>>
>>>Hi!
>>>
>>>Do you have something that you can share with all of us there on UT?
>>>
>>>e.g. A base class library with all the basic controls (TextBox, ComboBox etc) with the correct/required overrides etc.
>>>
>>>Thanks
>>>
>>>Sarosh
>>>
>>>>
>>>>So, here's how you avoid that:
>>>>
>>>>
>>>>public class MyTextBox : System.Windows.Forms.TextBox
>>>>{
>>>>	public MyTextBox()
>>>>	{
>>>>		this.BackColor = Color.Firebrick; ;
>>>>	}
>>>>	[DefaultValue(typeof(System.Drawing.Color), "Firebrick")]
>>>>	public override System.Drawing.Color BackColor
>>>>	{
>>>>		get { return base.BackColor; }
>>>>		set { base.BackColor= value; }
>>>>	}
>>>>}
>>>>
>>>>With the DefaultValue attribute in place, when this TextBox is dropped on a design surface, the line of code:
>>>>
>>>>
>>>>this.BackColor = Color.FireBrick;
>>>>
>>>>
>>>>will *NOT* be generated. Without the DefaultValue attribute, it *WILL* be generated.
>>>>
>>>>~~Bonnie
>>>>
>>>>
>>>>
>>>>
>>>>
>>>>
>>>>>Hi Bonnie,
>>>>>
>>>>>>No, this particular problem that you had with the .Text property of a control is kind of special and that's because the IDE sets it when you drop the control on a design surface. You wouldn't normally handle it this way for other properties. Normally, all you need to do is set it in the constructor.
>>>>>
>>>>>I understand now. Thanks for the explanation.
>>>>>
>>>>>Alan
Bonnie Berent DeWitt
NET/C# MVP since 2003

http://geek-goddess-bonnie.blogspot.com
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform