|
-
Dec 31st, 2005, 06:17 AM
#1
[Resolved]Possible to make Interval ReadOnly in Timer?
I have a class that is derived from the System.Windows.Forms.Timer class and I would like to make Interval ReadOnly.
Is this possible?
Last edited by Kasracer; Jan 2nd, 2006 at 08:07 AM.
-
Dec 31st, 2005, 07:49 AM
#2
Re: Possible to make Interval ReadOnly in Timer?
if you inherit the timer ( as a custom class )
declare Interval as a Shadows Property, like this ...
VB Code:
Public Class tmr
Inherits Timer
Public Shadows ReadOnly Property Interval() As Integer
Get
End Get
End Property
End Class
~
if a post is resolved, please mark it as [Resolved]
protected string get_Signature(){return Censored;}
[vbcode][php] please use code tags when posting any code [/php][/vbcode]
-
Jan 1st, 2006, 11:58 AM
#3
Re: Possible to make Interval ReadOnly in Timer?
Because the Interval property is not declared Overridable, Shadowing is the only possibility. Just note though that while Shadowing is similar to Overriding, a Shadowed member is tied to the type, while an Overridden member is tied to the object. This means that if you have member A in a base class and you Override it in a derived class, casting a reference to a derived object as the base type will still only give you access to the derived implementation of member A. If you have member B in the same base class and you Shadow it in the same derived class, casting the same reference will actually give you access to the base implementation of member B. Try the following code to see what I mean:
VB Code:
Public Class Class1
Public Overridable Sub MemberA()
MessageBox.Show("Base implementation of MemberA.")
End Sub
Public Sub MemberB()
MessageBox.Show("Base implementation of MemberB.")
End Sub
End Class
Public Class Class2
Inherits Class1
Public Overrides Sub MemberA()
MessageBox.Show("Derived implementation of MemberA.")
End Sub
Public Shadows Sub MemberB()
MessageBox.Show("Derived implementation of MemberB.")
End Sub
End Class
VB Code:
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim myClass2 As New Class2
myClass2.MemberA()
myClass2.MemberB()
Dim myClass1 As Class1 = CType(myClass2, Class1)
myClass1.MemberA()
myClass1.MemberB()
End Sub
Also note that Overriding only affects the member with the same signature, i.e. a single overload if there are multiple, while Shadowing affects all members with that name. This doesn't mean that you should not use Shadows, but it is good to know what the implications are.
-
Jan 2nd, 2006, 08:06 AM
#4
Re: Possible to make Interval ReadOnly in Timer?
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|