1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110
|
//A jouter une ref à System.Design.dll
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.ComponentModel;
using System.Drawing;
using System.ComponentModel.Design;
namespace HeritageControlCSHARP
{
public abstract class A:Control
{
public abstract void MethodeBase();
public abstract double D { get; set; }
public abstract string myStr { get; set; }
}
[DesignTimeVisible(false)]
public class B : A
{
public override void MethodeBase()
{
System.Console.WriteLine("MethodeBase.");
}
//proprietes de base implementees par N
//non browsable dans B et aussi ...dans C
[Browsable(false)]
[Description ("Propriete Largeur:Type Double")]
public override double D { get; set; }
[Browsable(false)]
[Description("Propriete Nom:Type string")]
public override string myStr { get; set; }
//1 nouvelles propriete propre -B- non browsable dans B =>egalement dans .....C
[Browsable(false)]
[Description("Propriete Number:Type int")]
public int Number { get; set; }
//1 nouvelles propriete de -B- browsable dans B =>egalement dans .....C
[Browsable(true)]
[Description("Propriete Size:Type Size")]
public Size CSize { get; set; }
}
[DesignTimeVisible(true)]
[DesignerAttribute(typeof(ClasseC_ControlDesigner), typeof(IDesigner))]
public class C : B
{
//1 nouvelles propriete propre à -C- browsable dans C
[Browsable(true)]
[Description("Propriete newProp:Type double")]
public double NewProp { get; set; }
}
//simple controldesigner pour la classe C
[System.Security.Permissions.PermissionSet(System.Security.Permissions.SecurityAction.Demand, Name = "FullTrust")]
public class ClasseC_ControlDesigner : System.Windows.Forms.Design.ControlDesigner
{
// In this implementation, the AccessibleDescription, AccessibleName and Dock
//property is hidden from any PropertyGrid or Properties window. This is done by
// creating a copy of the existing PropertyDescriptor and
// attaching two new Attributes: Browsable and EditorBrowsable.
protected override void PostFilterProperties(System.Collections.IDictionary properties)
{
PropertyDescriptor pd;
//3-prop AccessibleDescription
pd = properties["AccessibleDescription"] as PropertyDescriptor;
pd = TypeDescriptor.CreateProperty(
pd.ComponentType,
pd,
new Attribute[2] {
new BrowsableAttribute(false),
new EditorBrowsableAttribute(EditorBrowsableState.Never)});
properties[pd.Name] = pd;
//3-prop AccessibleName
pd = properties["AccessibleName"] as PropertyDescriptor;
pd = TypeDescriptor.CreateProperty(
pd.ComponentType,
pd,
new Attribute[2] {
new BrowsableAttribute(false),
new EditorBrowsableAttribute(EditorBrowsableState.Never)});
properties[pd.Name] = pd;
//3-prop Dock
pd = properties["Dock"] as PropertyDescriptor;
pd = TypeDescriptor.CreateProperty(
pd.ComponentType,
pd,
new Attribute[2] {
new BrowsableAttribute(false),
new EditorBrowsableAttribute(EditorBrowsableState.Never)});
properties[pd.Name] = pd;
// Always call the base PostFilterProperties implementation
// after you modify the properties collection.
base.PostFilterProperties(properties);
}
}
} |
Partager