Click here to Skip to main content
15,888,590 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi everybody,

I have coded a dll project but I cannot hide the classic properties of the control. When I load the control in another c# project, I can access to any methods or events of the control.

I would not like people could see all its properties, only those I have publicly initialized.

I have tried to declare the class as private... but that is not the solution cos I cannot construct it later. :S, I'm lost.

Thanks in advantage.
Posted
Comments
Afzaal Ahmad Zeeshan 19-Aug-15 8:01am    
Consider applying private modifier to them.
ars.1614 19-Aug-15 11:30am    
To any of them?


There are too many... Isn't there another way?
Afzaal Ahmad Zeeshan 19-Aug-15 11:38am    
No!
Ralf Meier 21-Aug-15 8:42am    
Take a look to my solution (3) ...

 
Share this answer
 
Comments
ars.1614 19-Aug-15 11:27am    
Thanks for answering but I cannot hide every of them, there are too many. (height, width, focus, enable...)

There has to be a way to hide them all but those I want.
OriginalGriff 19-Aug-15 11:47am    
Nope, sorry - that's not how the framework works.
If you want to hide them, you have to either hide them each individually, or not derive your class.
I know 3 ways to hide Properties from Controls :

1: You create them (all) as dummi-Properties and set it's Attribute like described by OG.

2: You build an own Designer-Class for your control (each). In this Designer-Class you have the ability to remove the Properties with (for example) overriding the method "PreFilterProperties" ...

3: You implement the "ICustomTypeDescriptor"-Interface and it's methods into your control (each). In the overriden methods "GetProperties" you call an own method which removes the unwanted Properties from the List.

For the Items 2 and/or 3 I could give you VB-Examples how to do. The VB-Code is not very complicated so you should (if interested) be able to convert it to C#.
 
Share this answer
 
v2
There is no point to do that...

However, if you want to limit access to a control or a set of them, you should put your control inside a user control. This could be particullary useful for complex controls like a grid or a chart when you want to only expose some properties.

You will still see "classic" properties of the user control like it size but you won't see properties of the nested control. You then add some properties to the iser control to give access to internal control properties of the nested control.
 
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