隐藏不需要的属性 [英] Hide unwanted properties.

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

问题描述

好的,我终于认定VB.NET有一个重要的事情(不是确定C#中存在同样的东西),这真的让我感到震惊。要么我在这里错过了这一点,要么我没有找到我需要的东西来实现我的需求。


我是创建一个Windows窗体用户控件,并继承自

System.Windows.Forms.UserControl。有几个属性是Usercontrol类的一部分,我不想暴露,所以我试图隐藏

它们如下所示:


<可浏览(错误),EditorBrowsable(EditorBrowsableState.Never)>公共

覆盖属性ContextMenu()As System.Windows.Forms.ContextMenu

获取


结束获取

Set(ByVal Value As System.Windows.Forms.ContextMenu)

结束集


结束物业


但是当我将控件放在一个表单上并查看我尝试过的属性时,通过IntelliSense仍然存在
隐藏。这不是

EditorBrowsable属性应该停止的吗?


-

Raymond R Cassick

CEO / CSA

Enterprocity Inc.
www.enterprocity .com

3380 Sheridan Drive,#143

Amherst,NY 14227

V:716-316-7537
博客: http://spaces.msn.com/members/ rcassick /

Ok, I have finally decided that there is ONE big thing about VB.NET (not
sure if this same thing exists in C# yet) that really ticks me off. Either I
am missing the point here or I have not found what I need to accomplish my
need.

I am creating a Windows forms user control and am inheriting from
System.Windows.Forms.UserControl. There are several properties that are part
of the Usercontrol class that I do not want to expose so I am trying to hide
them as shown below:

<Browsable(False), EditorBrowsable(EditorBrowsableState.Never)> Public
Overrides Property ContextMenu() As System.Windows.Forms.ContextMenu
Get

End Get
Set(ByVal Value As System.Windows.Forms.ContextMenu)
End Set

End Property

But when I place the control on a form and look the properties I have tried
to hide are still present through IntelliSense. Is this not what the
EditorBrowsable attribute is supposed to stop?

--
Raymond R Cassick
CEO / CSA
Enterprocity Inc.
www.enterprocity.com
3380 Sheridan Drive, #143
Amherst, NY 14227
V: 716-316-7537
Blog: http://spaces.msn.com/members/rcassick/

推荐答案

可浏览(错误)_

公共财产Bla Bla Bla()As Bla < br $> b $ b ....

结束财产


这只会从属性对话框中删除属性,但如果

你试着用代码压缩它们


Crouchie1998

BA(HONS)MCP MCSE
Browsable(False) _
Public Property Bla Bla Bla() As Bla
....
End Property

This will only remove the property from the properties dialog, but not if
you try to accress them in code

Crouchie1998
BA (HONS) MCP MCSE

是的,我知道......我不能相信没有办法隐藏这个

代码虽然。看起来我唯一可以做的就是抛出异常如果

我的一个用户试图使用我尚未实现的属性。


似乎对我来说很糟糕。


我已经阅读了一些理论,说隐藏了继承的属性

可用于基类是''糟糕的OO''但是我不认为是。怎么样?
polymorphisam?有些事情我希望我的控制能以不同的方式做。

我想完全控制MY usercontrol向MY用户公开的内容。我不想要实现一堆我不在乎的属性

只是因为我选择使用的基类。


UGH!


我不希望用户改变我的背景图片,所以为什么要这样?
我的房产清单上有这个吗?更重要的是,如果它可用

为什么当有人试图使用它时会抛出异常?


看起来非常混乱。


" Crouchie1998" < CR ********** @ spamcop.net>写在消息

新闻:uo ************** @ TK2MSFTNGP10.phx.gbl ...
Yeah, I know that... I can''t believe that there is no way to hide this from
code though. It looks like the only thing I can do it thrown an exception if
one of my users tries to use a property that I have not implemented.

Seems mighty messy to me.

I have read a few theories that say hiding inherited properties made
available form a base class is ''bad OO'' but I don''t think it is. What about
polymorphisam? There are some things I want my control to do differently.
I want to have full control over what MY usercontrol exposes to MY user. I
don''t want to have to implement a bunch of properties I don''t care about
just because of the base class I chose to use.

UGH!

I don''t want users to be bale to change my background picture so why should
I have that available on my list of properties? More so, if it is available
why would it throw an exception when someone tries to use it?

Just seems VERY messy tome.

"Crouchie1998" <cr**********@spamcop.net> wrote in message
news:uo**************@TK2MSFTNGP10.phx.gbl...
可浏览(错误)_
公共财产Bla Bla Bla()作为Bla
...
结束财产

这只会从属性对话框中删除属性,但如果不是/>你试着用代码压缩它们

Crouchie1998
BA(HONS)MCP MCSE
Browsable(False) _
Public Property Bla Bla Bla() As Bla
...
End Property

This will only remove the property from the properties dialog, but not if
you try to accress them in code

Crouchie1998
BA (HONS) MCP MCSE



只是一个想法,但如果你覆盖财产但是使它成为范围怎么办

私有?甚至不确定这是否可行,但它可能值得

检查......或者,你可以做一个例外,你可以做

财产什么也不做如果用户试图给它分配一个值 -

只要确保你记录该属性没有效果......


只需要几件事就可以了尝试。祝你好运。


" Ray Cassick(Home)" < RC ************ @ enterprocity.com>在消息中写道

新闻:eV ************** @ TK2MSFTNGP12.phx.gbl ...
Just a thought, but what if you override the property but make it''s scope
Private? Not even sure if this is possible, but it might be worth
checking... Alternatively, instead of throwing an exception, you could make
the property do nothing at all if a user tries to assign a value to it -
just make sure you document that the property has no effect...

Just a couple things to try. Good luck.

"Ray Cassick (Home)" <rc************@enterprocity.com> wrote in message
news:eV**************@TK2MSFTNGP12.phx.gbl...
是的,我知道......我无法相信没有办法从代码中隐藏这个
。如果我的一个用户试图使用我没有实现的属性,看起来我唯一可以做的就是抛出
异常。

对我来说似乎很混乱。

我已经阅读了一些理论,说隐藏继承的属性可以从基类中获得坏OO,但我不认为是。关于polymorphisam的内容是什么?有些事情我希望我的控制能够以不同的方式进行。
我希望完全控制MY usercontrol向MY用户公开的内容。我不想仅仅因为我选择使用的基类来实现一堆我不在乎的属性。

UGH!

我不希望用户打包改变我的背景图片,为什么我应该在我的属性列表中提供?更重要的是,如果它可用,为什么当有人试图使用它时会抛出异常?

看起来非常混乱。
Yeah, I know that... I can''t believe that there is no way to hide this
from code though. It looks like the only thing I can do it thrown an
exception if one of my users tries to use a property that I have not
implemented.

Seems mighty messy to me.

I have read a few theories that say hiding inherited properties made
available form a base class is ''bad OO'' but I don''t think it is. What
about polymorphisam? There are some things I want my control to do
differently.
I want to have full control over what MY usercontrol exposes to MY user. I
don''t want to have to implement a bunch of properties I don''t care about
just because of the base class I chose to use.

UGH!

I don''t want users to be bale to change my background picture so why
should I have that available on my list of properties? More so, if it is
available why would it throw an exception when someone tries to use it?

Just seems VERY messy tome.



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

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