By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,259 Members | 1,708 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,259 IT Pros & Developers. It's quick & easy.

Inheritance and teaching old dogs new tricks...

P: n/a
I guess there is someting that I am really missing about Inheritance. I
really thought that this was going to be easy, but ....
I am converting on old app. and the users expect certain behavior. One of
these things is for the focus to move when the enter key is pressed. I have
a number of forms, so I thought I would generate a base form for all my data
entry forms to inherit from. So the first thing I put in the base form is a
Key_Down handler with the following code:
If e.KeyCode = Keys.Enter Then
If e.Shift Then
End If
e.SuppressKeyPress = True
Exit Sub
End If
Ok so far... the derived forms worked as I had expected. Now, sometimes I
want to turn this behavior off, like when I am in a multi-line textbox.
So I figured to add a protected Property to the base class as follows:

Private _CvtEnter As Boolean = False
Protected Property CvtEnter() As Boolean
Return _CvtEnter
End Get
Set(ByVal value As Boolean)
_CvtEnter = value
Debug.Print("CvtEnter changed to {0}", _CvtEnter.ToString)
End Set
End Property
and surround the KeyDown code with an
If CvtEnter Then
For debuging I also added this as the first line in the Key Press event.
Debug.Print("KeyDown: CvtEnter is {0}.", CvtEnter.ToString)

In the Derived forms Load event I put
CvtEnter = True
I run the app.. I see the value changed to True. I press the enter key and I
KeyDown: CvtEnter is False.
I don't get it! So the base class acts like it has its own 'copy' of
_CvtEnter that I can't change from the derived class. Please someone,
explain this to this old dog....

Sep 16 '07 #1
Share this question for a faster answer!
Share on Google+

This discussion thread is closed

Replies have been disabled for this discussion.