Click here to Skip to main content
15,939,960 members
Please Sign up or sign in to vote.
4.50/5 (6 votes)
See more:

I have a Class named "A" and this class inherits from Windows.Forms.PictureBox

"A" has public properties

if we name properties of A as below:
A1

A2
A3

we can set values of A1, A2, A3 and All inherited properties from pictureBox

I create an instance of A in runtime and name it MyA

and then I have a PropertyGrid name Pr1

C#
Pr1.selectedObject = MyA 


Pr1 is showing all properties of MyA including all inheritec from PictureBox

I want Pr1 to show only A1,A2 and A3 and hide the rest. how can I do that????

Posted
Updated 27-Aug-09 16:57pm
v2

This is against OOP principals. All properties etc of the base object shold be present in the deriving object.

However, Microsoft do this themselves all the time! The PictureBox is a good example. It has no browsable Text property in the property grid or in the code editor via intellisense, but it's still there as it derives from System.Windows.Forms.Control which has the Text property.

The way to achieve this is to do something like this with properties, events and methods that you don't want to be visible.
using System;<br />using System.ComponentModel;<br />using System.Drawing;<br />using System.Windows.Forms;<br /><br />public class MyPictureBox : PictureBox<br />{<br />    [Browsable(false)]<br />    [EditorBrowsable(EditorBrowsableState.Never)]<br />    [Obsolete("This property is obselete", true)]<br />    public new Color BackColor<br />    {<br />        get { return base.BackColor; }<br />        set { base.BackColor = value; }<br />    }<br />}
This will make the BackColor property 'disappear' IF MyPictureBox is in a seperate assembly. It will not work if in the same assembly, or added as a project reference to another project - it must be a reference to a seperate dll.

 
Share this answer
 
Probably the best way to approach this is to use a wrapper class that only displays the properties you want to show
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900