How Do You Turn of Standard Properties

Merchand

Well-known member
Joined
Dec 28, 2005
Messages
73
Location
USA Eastcoast
Programming Experience
10+
In UserControls?

I'm creating this user control and would like to only make the docking work for top and bottom. But in my test project I can set the dock value to top, bottom and left and right. I'd like to turn off other properies like size, etc...
 
This is how:
VB.NET:
Public Overrides Property Dock() As DockStyle
Get
Return MyBase.Dock
End Get
Set(ByVal ds As DockStyle)
Select Case ds
Case DockStyle.Top, DockStyle.Bottom
MyBase.Dock = ds
Invalidate()
End Select
End Set
End Property
You can't change read/write mode for a overridable property, but you can prevent it from being changed by doing nothing in the set part.
 
Great Tip! I was on board with you...

Here is my code...

'<Category("Layout"), Description("Specifies the Docking of Control.")> _
Public Overrides Property Dock() As DockStyle
Get
mDock = MyBase.Dock()
Dock = mDock
End Get
Set(ByVal Value As DockStyle)
Select Case Value
Case DockStyle.Top
mDock = DockStyle.Top
MyBase.Dock = mDock
Case DockStyle.Bottom
mDock = DockStyle.Bottom
MyBase.Dock = mDock
Case Else
mDock = DockStyle.Bottom
MyBase.Dock = mDock
End Select
End Set
End Property

However, I don't understand your Invalidate() method call.

I can't get the attributes to work either? I added an imports statement for system.attribute and both of my attributes are not recognized. I tryed to add a reference to system.attributes but it was not in my list. Any Ideas?

Thanks bunches!!!
 
1. the 'Invalidate()' shouldn't have been there, don't know how it got there.
2. to use the attributes (correct as you have written) Imports System.ComponentModel
3. your property Get is very suspiciuos...
 
JohnH: Thanks for the import info!

I am trying to keep a private mDock in sync with the MyBase.Dock() property. However, I probably don't need this.

Is there a way to make your properties in usercontrol dynamic or do they have to be made dynamic in the testing application? Right now I have my properties setup as dynamic in my test project but I'd like to persist these value beteen application runs. [???]
 
I have stripped out the private member variable (mDock)...

PublicOverridesProperty Dock() As DockStyle
Get
Dock = MyBase.Dock()
EndGet
Set(ByVal Value As DockStyle)
SelectCase Value
Case DockStyle.Top
MyBase.Dock = DockStyle.Top
Case DockStyle.Bottom
MyBase.Dock = DockStyle.Bottom
CaseElse
MyBase.Dock = DockStyle.Bottom
EndSelect
EndSet
EndProperty

However, I can't get this property to show up in my test project so I can make it a dynamic property???

How do I prevent a user from using the Size property just override it too and not do anything? I hate to show a user a property in the properties window and not allow them to changed the size. But I don't want them to resize this user control. :confused:
 
Shadows.... only the Shadow knows....

VB.NET:
    Public Shadows ReadOnly Property size() As System.Drawing.Size
        Get

        End Get
    End Property

This seems to work....

Still testing it out though.

-tg
 
OK, here's what I found. When I use the above code for the Size property of an inherited TextBox.... it doesn't stop me from changing it's size... But it won't let me compile it if I do. I then had to go into the form designer code and remove the usercontrol1.Size lines. Then it reshaped my text box back to it's original size and ran. Clunky but at least it keeps the control the same size as I originaly painted it.

-tg
 
tg, thanks for the Shadow Tip! It seems logical if you want to hide it to use the Shadow! I just figured I'd never have a major need to hide anything. :)
 
tg, I followed your suggestion and it worked for a minute or two...

I commented out the .size line in the designer code becaused it flagged as an error since the .sized property is hidden (Shadow) now. However I manually changed the .size property in the properties window and the designer removed my commented out line of code and re-added the line of code with the new size and flagged as an error again.

I have my user control setup as a 2 statusbars one with several panels and one for a message area that can be toggle on and off by the user (another programmer).

I'm trying to make the user control act like a control that would be a professional control from a third-party vendor.

I'm looking for a good vb.net (2003 or 2005) book on how to built controls. There is a few books but most have bad reviews.

Without the Shadow code the .size property is visible to the user and they can change the size values but it has no effect since I'm docking to the buttom and anchored to the left and right sides.

I can't believe M$ has not perfected contorl development by now... its been a few years on the street now???

I appreciate the help! I did learn more about the shadow keyword.
 
TechGNome,

I started think about is problem some more and I think I figured out how to hide this .Size for my user control! Based on what you said about the shadows keyword and me playing with the code this morning all I could do was get an error with your example.

So I started thinking about attributes (And I don't know much about them!!!) but I remembered we have one called Browsable so I thought how about turning it off...

<Browsable(False)> _
PublicOverloadsProperty Size() As Size
Get

EndGet
Set(ByVal Value As Size)

EndSet
EndProperty


So I created the above "Overloads Property for Size()" and added the <Browsable(False)> attribute and I did not get any errors and it compiled and ran fine. I tried to "Override" this Size() property using the same attribute and the keyword Overrides and I received an swiggle saying I can't override this property because the base class property is not Overridable.


Anyway, this seems to work to hide a .Size property that makes no since to change anyway, because the user can set a Dock property to top or bottom and thats all they really need. I'm trying to keep it simple.


TechGNome Thanks again for the Shadows Tip! It set me on the right path! :)
 
Back
Top