How can I make a property not show in the properties window?

  • Thread starter Thread starter Just Me
  • Start date Start date
J

Just Me

I made a Usercontrol that must have AutoScroll set to true when it is used.
So I set it to True in the Load event.

However the property still shows in the properties window when the control
is placed on a form.

That's confusing.

How can I make that property not show in the properties window?


Thanks in advance for any useful info
 
Use the browsable attribute. For example:

<Browsable(False)>_
Public Property Name() as String
Get ...
Set...
End Property

Ron
 
Just Me said:
I made a Usercontrol that must have AutoScroll set to true when it is used.
So I set it to True in the Load event.

However the property still shows in the properties window when the control
is placed on a form.
[...] How can I make that property not show in the properties window?


\\\
Imports System.ComponentModel
..
..
..
<Browsable(False)> _
Public Property...
///

If the property should not appear in the text editor too, add the
'EditorBrowsable' attribute too.
 
Am I missing something?
Where would I place <Browsable(False)>
The AutoScroll property comes with the UserControl.
I don't generate it.


Thanks
BTW will <Browsable(False)> keep the designer from assigning a value to the
property that <Browsable(False)> is assigned to?
 
Just Me said:
Am I missing something?
Where would I place <Browsable(False)>
The AutoScroll property comes with the UserControl.
I don't generate it.

Untested:

\\\
<Browsable(False)> _
Public Overrides Property AutoScroll() As Boolean
Get
Return MyBase.AutoScroll
End Get
Set(ByVal Value As Boolean)
MyBase.AutoScroll = Value
End Set
End Property
///
 
AutoScroll cannot be overridden!

Herfried K. Wagner said:
Untested:

\\\
<Browsable(False)> _
Public Overrides Property AutoScroll() As Boolean
Get
Return MyBase.AutoScroll
End Get
Set(ByVal Value As Boolean)
MyBase.AutoScroll = Value
End Set
End Property
///
 
Dennis,
If you want to "override" the *attributes* of a not overridable property.

You can Shadow the property.

Note: Shadowing a property to change the attributes is one of the few times
when you need to "design" with Shadows. Otherwise Shadows should be reserved
for version control...

However as Herfried suggests, Control.AutoScroll is overridable in VB.NET
2003.

Hope this helps
Jay
 
Otherwise Shadows should be reserved for version control...
Seems I remember wanting a control to have a MouseMove event so I Shadowed
the inherited event

Does that sound like I should have done something else?
 
Just Me,
Does that sound like I should have done something else?
Possibly, without more details I really can't answer this.

Control already has a MouseMove event, why were you shadowing it?

You can call Control.OnMouseMove to raise the Control.MouseMove event...


The "problem" with Shadowing is it is anti-polymophism, in that is
explicitly does not behave polymorphically. In other words it rarely behaves
the way you expect it to.

In Herfried's example, his shadowing property was simply calling the base
property, thus not needing polymorphism...

Hope this helps
Jay
 
Jay B. Harlow said:
Just Me,
Possibly, without more details I really can't answer this.

Control already has a MouseMove event, why were you shadowing it?
I don't remember, It may have been MouseUp or Down and maybe I wanted to
provide different data.

I was just cautious about your comment.


Thanks
 
Always a complication. I added the code below and built it. Created a new
form and added the revised control to it.
The two properties do not appear in the properties list - great.
However, AutoScroll does not appear in the code listing, why not?
Also, AutoScrollMargin does appear in the code listing, I thought
EditorBrowsable would supress it

<Browsable(False)> _
Public Overrides Property AutoScroll() As Boolean
Get
Return MyBase.AutoScroll
End Get
Set(ByVal value As Boolean)
MyBase.AutoScroll = value
End Set
End Property

<Browsable(False), EditorBrowsable(EditorBrowsableState.Never)> _
Public Shadows Property AutoScrollMargin() As Size
Get
Return MyBase.AutoScrollMargin
End Get
Set(ByVal value As Size)
MyBase.AutoScrollMargin = value
End Set
End Property
 
Just Me,
What specifically do you mean "appear in the code listing"?

Do you mean Intellisense or the "Windows Forms Generated Code" region?

EditorBrowsable controls Intellisense.

DefaultValue controls the "Windows Forms Generated Code" region.

It might be that Intellisense is not as intelligent as the Property Grid
when it comes to Shadows & properties.

Hope this helps
Jay
 
Jay B. Harlow said:
Just Me,
What specifically do you mean "appear in the code listing"?

Do you mean Intellisense or the


I meant this.
"Windows Forms Generated Code" region?
I was hoping to stop the code generation/apperance. Doesn't DefaultValue
only effect the value assigned in the code generated?
 
Just Me,
I meant this.
I was hoping to stop the code generation/appearance. Doesn't DefaultValue
only effect the value assigned in the code generated?

What is "this"? If you mean "Windows Forms Generated Code" region, then yes.
It effects the value assigned in the code generated.

Define exactly what you mean "stop the code generation/apperance" that is
different from "value assigned in the code generated". Remember we are
talking properties, not fields here.

You can use either ShouldSerialize* or DefaultValue to control if the
"setting the default" code is added to the "Windows Forms Generated Code"
region or not.

http://msdn.microsoft.com/library/d...guide/html/cpconshouldpersistresetmethods.asp

Something like:
Private Sub ResetAutoScrollMargin ()
... set AutoScrollMargin to "default" value
End Sub

Private Function ShouldSerializeAutoScrollMargin () As Boolean
... return True if you want value in "Windows Forms Generated Code"
region
End Function

Remember if you never change the value from the default, then no code is
added... Also remember that DefaultValue is a hint to the designer, you
still need to set the property's default value in the object's constructor.

You may want to ask in one of the Windows Forms newsgroups to double check,
some properties (such as Size) have other "special" properties & methods
(such as DefaultSize) that control their default value, I don't remember if
AutoScrollMargin has "special" related properties & methods.

Hope this helps
Jay
 
Define exactly what you mean "stop the code generation/apperance" that is
different from "value assigned in the code generated". Remember we are
talking properties, not fields here.


Simple. The Designer generates code like the following:
Me.ControlEditor1.AutoScrollMargin = New System.Drawing.Size(0, 0)
Me.ControlEditor1.AutoScrollMinSize = New System.Drawing.Size(0, 0)

I like to surpress that generation. I have a couple of situations when it is
more important that this example.
 
I think I found it:
<Browsable(False),DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)>

I need to test more but I thought I'd pass it on.



Thanks a lot
 
I tried the Shadows with Browsable False and it still shows up in the
Properties Window at Design time as well as in the Intell..sense.
 
Jay, as usual, you are correct. I was using Private. When I changed it to
Public, the properties did NOT appear in the Properties Window. Thanks.
 
Just one more question on Shadows (I know you don't like them) but If I
shadow a property and do NOT call MyBase.property in the sub, then I assume
MyBase.Property procedure will not be executed...is this correct?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top