在dll控件中隐藏类属性 [英] Hide class properties in dll control

查看:61
本文介绍了在dll控件中隐藏类属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,



我编写了一个dll项目,但我无法隐藏控件的经典属性。当我在另一个c#项目中加载控件时,我可以访问控件的任何方法或事件。



我不希望人们看到它的所有属性,只有那些我公开初始化的。



我试图将该类声明为私有......但这不是解决方案因为我以后无法构建它。 :S,我输了。



非常感谢。

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.

推荐答案

见这里:隐藏继承的属性 [ ^ ]


我知道3种隐藏控件属性的方法:



1:你创建它们(全部)作为dummi-Properties并设置它的属性就像OG所描述的那样。



2 :您为您的控件(每个)构建一个自己的Designer-Class。在此Designer-Class中,您可以删除属性(例如)覆盖方法PreFilterProperties...



3:您实现ICustomTypeDescriptor -Interface和它的方法进入你的控制(每个)。在重写方法GetProperties中,您调用一个自己的方法,从列表中删除不需要的属性。



对于项目2和/或3,我可以给你VB - 示例怎么做。 VB代码不是很复杂,所以你应该(如果有兴趣)将它转换为C#。
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#.


没有必要这样做......



但是,如果要限制对控件或其中一组控件的访问,则应将控件置于用户控件中。当您只想公开某些属性时,这可能对网格或图表等复杂控件特别有用。



你仍会看到用户控件的经典属性,就像它的大小一样,但你不会看到嵌套控件的属性。然后,您可以向iser控件添加一些属性,以访问嵌套控件的内部控件属性。
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.


这篇关于在dll控件中隐藏类属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆