Hi all
I'm developing a control, and I need to hide some properties to the
user. For example, suppose I need Text property to be completely
inacessible (from a Form/Code that is into another project/assembly).
I tried with attributes:
<Browsable(Fals e), _
EditorBrowsable (EditorBrowsabl eState.Never), _
RefreshProperti es(RefreshPrope rties.Repaint), _
Description("Ge ts or sets the control's Text value.")_
Public Shadows Property Text() As String
Get
Return MyBase.Text
End Get
Set(ByVal Value As String)
If MyBase.Text <Value Then
MyBase.Text = Value
End If
End Set
End Property
but I discovered that Text property is invisible by the property
browser, but it is still accessible through IntelliSense.
Then, I tried associating a designer:
Protected Overrides Sub PostFilterPrope rties(ByVal properties As
IDictionary)
properties.Remo ve("Text")
MyBase.PostFilt erProperties(pr operties)
End Sub
but, again, the Text property is accessible by IntelliSense.
What's wrong?
Thank you.
Dom 14 2423
You might consider private property`s
you can also choose to declare only the get or set private
regards
Michel Posseth
"Dom" <do************ *****@gmail.com schreef in bericht
news:u3******** ******@TK2MSFTN GP06.phx.gbl...
Hi all
I'm developing a control, and I need to hide some properties to the user.
For example, suppose I need Text property to be completely inacessible
(from a Form/Code that is into another project/assembly).
I tried with attributes:
<Browsable(Fals e), _
EditorBrowsable (EditorBrowsabl eState.Never), _
RefreshProperti es(RefreshPrope rties.Repaint), _
Description("Ge ts or sets the control's Text value.")_
Public Shadows Property Text() As String
Get
Return MyBase.Text
End Get
Set(ByVal Value As String)
If MyBase.Text <Value Then
MyBase.Text = Value
End If
End Set
End Property
but I discovered that Text property is invisible by the property browser,
but it is still accessible through IntelliSense.
Then, I tried associating a designer:
Protected Overrides Sub PostFilterPrope rties(ByVal properties As
IDictionary)
properties.Remo ve("Text")
MyBase.PostFilt erProperties(pr operties)
End Sub
but, again, the Text property is accessible by IntelliSense.
What's wrong?
Thank you.
Dom
Michel Posseth [MCP] said the following On 08/09/2006 16.07:
You might consider private property`s
This does not seems to solve my problem: in case of an inherited
property (such as Text) a private property declaration simply make
IntelliSense show the parent property.
you can also choose to declare only the get or set private
Sorry, I don't understand what you mean...
Thank you for reply.
Dom
I have the same problem and have not found any solution to force Intell... to
not show it. What I do is shadow the property in my control then if the user
tries to set it, just ignore it or force an error. However, I think the user
can actually set the property in the base control thru reflection.
--
Dennis in Houston
"Dom" wrote:
Michel Posseth [MCP] said the following On 08/09/2006 16.07:
You might consider private property`s
This does not seems to solve my problem: in case of an inherited
property (such as Text) a private property declaration simply make
IntelliSense show the parent property.
you can also choose to declare only the get or set private
Sorry, I don't understand what you mean...
Thank you for reply.
Dom
Dennis said the following On 08/09/2006 17.56:
I have the same problem and have not found any solution to force Intell... to
not show it. What I do is shadow the property in my control then if the user
tries to set it, just ignore it or force an error. However, I think the user
can actually set the property in the base control thru reflection.
With this approach the first problem is that an exception can be raised
at run-time only, not at design time, and the property remains accesible
like others.
What I need is make a property invisible, not just unusable.
Today I tried to convert my project to VS2005, and I've seen that
IntelliSense DOES NOT expose the property despite it remains usable.
Maybe the problem is a bug of VS2003?
Anybody have any solution for hiding an inherited property/member?
Thanks!
Dom
"Dom" <do************ *****@gmail.com wrote in message
news:%2******** ********@TK2MSF TNGP06.phx.gbl. ..
Dennis said the following On 08/09/2006 17.56:
>I have the same problem and have not found any solution to force Intell... to not show it. What I do is shadow the property in my control then if the user tries to set it, just ignore it or force an error. However, I think the user can actually set the property in the base control thru reflection.
With this approach the first problem is that an exception can be raised at
run-time only, not at design time, and the property remains accesible like
others.
What I need is make a property invisible, not just unusable.
Today I tried to convert my project to VS2005, and I've seen that
IntelliSense DOES NOT expose the property despite it remains usable. Maybe
the problem is a bug of VS2003?
Anybody have any solution for hiding an inherited property/member?
Thanks!
Dom
Because of the OOP principles, you cannot "hide" a property. If you inherit
from an object that has a "Text" property, the derived class will contain a
Text property. Even if you could hide the "Text" property, all the
developer would have to do is cast the derived instance into the base class
instance and access the Text property from there.
There are alternatives to what you are trying to achieve though. One is
encapsulating the base object completely within the derived class. Instead
of inheriting the base class, you create an instance of the class and store
the reference in a member variable inside the class you are creating. Any
properties/methods you would like to expose of the private instance you
would expose via properties/methods of your class. This can be a pain for
large classes where you would like to expose large numbers of
properties/methods, but it works most of the time. And lastly, the last
alternative would be to inherit from the class, override the property you
don't want the developers to use, and throw an NotImplementedE xception
exception. This way, if the developer does access it, at runtime an
exception that specifically states what the problem is, is thrown. This is
actually really simple to do. If the developer casts to base class and
accesses the property, the exception is still thrown.
Oh, for shadowing methods. If you shadow a method and changes it's accessor
to not be visible (private, friend) then when the classes property is called
at runtime, the shadowed property/method is not called. Instead, the base
classes property/method is ... I believe ... correct me if I'm wrong...but I
believe that's the way it is.
HTH,
Mythran
Well maybe i understood you wrong
i understood that you have a property that you do not want to be accessible
outside your assembly .
well you can do this through the scope qualifiers in VS.net 2005 you can
even mix the get and set qualifiers ( Private , Friend , Public differ for
get and set )
Now i understand that you want your property to be fully functional to the
outside world however you do not want to show that it is actually there .
well i do not believe this confirms to OOP ,,, if i may ask why do you want
this behavior ?
regards
Michel
"Dom" wrote:
Michel Posseth [MCP] said the following On 08/09/2006 16.07:
You might consider private property`s
This does not seems to solve my problem: in case of an inherited
property (such as Text) a private property declaration simply make
IntelliSense show the parent property.
you can also choose to declare only the get or set private
Sorry, I don't understand what you mean...
Thank you for reply.
Dom
Dom,
In my opinion you cannot. The same is with the background from the
picturebox. It is there but does nothing, Herfried does not agreed this with
me, he can be right, but I never saw a working sample from him about this.
Cor
"Dom" <do************ *****@gmail.com schreef in bericht
news:u3******** ******@TK2MSFTN GP06.phx.gbl...
Hi all
I'm developing a control, and I need to hide some properties to the user.
For example, suppose I need Text property to be completely inacessible
(from a Form/Code that is into another project/assembly).
I tried with attributes:
<Browsable(Fals e), _
EditorBrowsable (EditorBrowsabl eState.Never), _
RefreshProperti es(RefreshPrope rties.Repaint), _
Description("Ge ts or sets the control's Text value.")_
Public Shadows Property Text() As String
Get
Return MyBase.Text
End Get
Set(ByVal Value As String)
If MyBase.Text <Value Then
MyBase.Text = Value
End If
End Set
End Property
but I discovered that Text property is invisible by the property browser,
but it is still accessible through IntelliSense.
Then, I tried associating a designer:
Protected Overrides Sub PostFilterPrope rties(ByVal properties As
IDictionary)
properties.Remo ve("Text")
MyBase.PostFilt erProperties(pr operties)
End Sub
but, again, the Text property is accessible by IntelliSense.
What's wrong?
Thank you.
Dom
Can you override any properties or only certain ones. What about inherited
methods...how do you hide them?
--
Dennis in Houston
"Mythran" wrote:
>
"Dom" <do************ *****@gmail.com wrote in message
news:%2******** ********@TK2MSF TNGP06.phx.gbl. ..
Dennis said the following On 08/09/2006 17.56:
I have the same problem and have not found any solution to force
Intell... to not show it. What I do is shadow the property in my control
then if the user tries to set it, just ignore it or force an error.
However, I think the user can actually set the property in the base
control thru reflection.
With this approach the first problem is that an exception can be raised at
run-time only, not at design time, and the property remains accesible like
others.
What I need is make a property invisible, not just unusable.
Today I tried to convert my project to VS2005, and I've seen that
IntelliSense DOES NOT expose the property despite it remains usable. Maybe
the problem is a bug of VS2003?
Anybody have any solution for hiding an inherited property/member?
Thanks!
Dom
Because of the OOP principles, you cannot "hide" a property. If you inherit
from an object that has a "Text" property, the derived class will contain a
Text property. Even if you could hide the "Text" property, all the
developer would have to do is cast the derived instance into the base class
instance and access the Text property from there.
There are alternatives to what you are trying to achieve though. One is
encapsulating the base object completely within the derived class. Instead
of inheriting the base class, you create an instance of the class and store
the reference in a member variable inside the class you are creating. Any
properties/methods you would like to expose of the private instance you
would expose via properties/methods of your class. This can be a pain for
large classes where you would like to expose large numbers of
properties/methods, but it works most of the time. And lastly, the last
alternative would be to inherit from the class, override the property you
don't want the developers to use, and throw an NotImplementedE xception
exception. This way, if the developer does access it, at runtime an
exception that specifically states what the problem is, is thrown. This is
actually really simple to do. If the developer casts to base class and
accesses the property, the exception is still thrown.
Oh, for shadowing methods. If you shadow a method and changes it's accessor
to not be visible (private, friend) then when the classes property is called
at runtime, the shadowed property/method is not called. Instead, the base
classes property/method is ... I believe ... correct me if I'm wrong...but I
believe that's the way it is.
HTH,
Mythran
Hello Mythran,
Because of the OOP principles, you cannot "hide" a property.
If this is true, and I cannot doubt is it, what is the pourpose of
PreFilterProper ties and PostFilterPrope rties?
And, again, what it the pourpose of the statement
EditorBrowsable (EditorBrowsabl eState.Never)??
I understand that hiding a property/method does actually not hides the
same base property/method, but I think is not difficult a case (like
mine) where some properties are really useless.
In my case, I have lot of controls derived from
Windows.System. Windows.Forms.C ontrol, but not all controls make use of
Text property. Also I have a lot of controls derived from
ContainerContro l, but my controls are not designed to be scrollable, and
this is why I need to hide "AutoScroll " property.
There are alternatives to what you are trying to achieve though. One is
encapsulating the base object completely within the derived class. Instead
of inheriting the base class, you create an instance of the class and store
the reference in a member variable inside the class you are creating.
You are right. This is an approach I actually use for some of my custom
classes. But I cannot use this method when i derive from a class like
Windows.System. Windows.Forms.C ontrol.
And lastly, the last
alternative would be to inherit from the class, override the property you
don't want the developers to use, and throw an NotImplementedE xception
exception.
This is a very good approach. But, however, the property/method is still
exposed by IntelliSense.
BTW: I just discovered that using
EditorBrowsable (EditorBrowsabl eState.Never)
make a property is STILL visible in VS2003, but correctly NOT visible
with VS2005 (same project).
Oh, for shadowing methods. If you shadow a method and changes it's accessor
to not be visible (private, friend) then when the classes property is called
at runtime, the shadowed property/method is not called. Instead, the base
classes property/method is ... I believe ... correct me if I'm wrong...but I
believe that's the way it is.
You are absolutely right: the parent propery/method is colled instead.
Thank you for your comments!
I should greately appreciate your comment about PostFilterPrope rties
method and EditorBrowsable attribute.
Thanks!
Dom This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Jeroen Smits |
last post by:
To Microsoft or other people who are interested, I have a feature request:
I would really like to have an option to 'hide' a property or method from an
inherited class. For example when I create a subclass and supply a default
value for a property. Currently I create a new property, using the new
keyword, and only supply the get accessor witch will always return the
predefined value. But I would really like to be able to hide it...
|
by: Microsoft |
last post by:
Base class:
class AssetBase
{
string _clli;
public string CLLI
{
get
|
by: Baski |
last post by:
Base class:
class AssetBase
{
string _clli;
public string CLLI
{
get
|
by: Bob Weiner |
last post by:
What is the purpose of hiding intead of overriding a method? I have googled
the question but haven't found anything that makes any sense of it.
In the code below, the only difference is that when the Poodle is upcast to
the Dog (in its wildest dreams) it then says "bow wow" where the bernard
always says "woof" (see code). Basically, it appears that I'm hiding the
poodle's speak method from everything except the poodle.
Why would I...
|
by: Amber |
last post by:
The DataGrid allows you to make columns visible or invisible on demand
- even edit and other special columns. This article will show you how
it is done.
Some developers have reported problems controlling the visibility of
columns in the DataGrid control. The problem usually comes down to one
fact. The DataGrid has a property called AutoGenerateColumns. The
default value is "True". This means that when AutoGenerateColumns is
set to True,...
| |
by: Dennis |
last post by:
I have a class named myclass that inheirits from "baseclass". There is a
property of "baseclass" that I don't want exposed in the IDE. The MSDN
documentation says"
"A derived type can hide an inherited member by defining a new member with
the same signature. This might be done to make a previously public member
private or to define new behavior for an inherited method that is marked as
final. "
However, this does not hide the...
|
by: Steven Nagy |
last post by:
Hi all,
How would I go about hiding an inherited property?
In particular, I want to hide the 'BackColor' property of the
UserControl class.
I will then implement my own back color related properties and
collections.
I can do all the latter, but I don't want to build this nice designable
properties and have this big ugly 'BackColor' property available to the
user of my components, which will need to be set to Transparent all the
|
by: Ste |
last post by:
Hi there,
I've got a website with a list of Frequently Asked Questions, so
there's a question and answer in a long list down the page.
Can anyone recommend a simple script that would allow me to hide each
answer when the page loaded, but then made them individually
appear/disappear when clicking the question?
I'm after a solution that will degrade gracefully if a page doesn't
|
by: =?Utf-8?B?SHVleQ==?= |
last post by:
I need to hide the new window started from the code below. If I run as is,
the window is visible. If I comment out the code that sets a different user,
domain, and password the window is hidden as desired. Does anyone know if
there is a known issue with hiding a process window when you run it as a
different user? Do you have any suggestions to work around this problem?
Thank you.
Process proc = new Process();...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
| |
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |