473,387 Members | 1,790 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Overriding .Enabled

Here's a knotty little problem.

I have some nasty little controls that needs to behave in a non-
windows-Standard way - don't ask why; it's a large application being
converted from some [much] older code and my users are adamant
that this behaviour mustn't change.

Specifically, I want to be able to set

myControl.Enabled = False

and, instead of the controls /actually/ being disabled, I want them to
/recolour/ themselves so that they /look/ disabled, but still respond to
Mouse events, can be copied from, and such like. (I realise the
ReadOnly property is going to be involved, here, but I don't think it
will do the whole job).

Adding to the complication; I thought I'd derive all of these controls
from a single ancestor UserControl and have that ancestor implement
an Interface containing the Enabled property (among other things), as in

Public Interface ITypeable
. . .
Property Enabled() as Boolean
. . .

Public Class Wrapper
Inherits UserControl
Implements ITypeable
. . .
Public Property Enabled() as Boolean _
Implements ITypeable.Enabled

And herein lies my problem.

The Enabled property already exists in UserControl, so when I try to
implement the Interface property, VB (2003) gets quite upset that the
specifiers or signatures on the Interface and Property don't match.
I've tried overloading, overriding, shadowing, and just about every
other modifier I can find on the Property and even overriding the
OnEnabledChanged routine, but I seem to be on a losing streak here.

Any Suggestions?

TIA,
Phill W.

I have a control that I don't want disabled when I set .Enabled = False,
when my code says
..Enabled = False
I have an application that uses UserConrols to
Nov 20 '05 #1
4 5925
Public Interface ITypeable
Property Enabled() As Boolean
End Interface

Public Class Wrapper
Inherits Windows.Forms.UserControl
Implements ITypeable

Public Shadows Property Enabled() As Boolean Implements
ITypeable.Enabled
Get

End Get
Set(ByVal Value As Boolean)

End Set
End Property

End Class


"Phill. W" <P.A.Ward@o-p-e-n-.-a-c-.-u-k> wrote in message
news:c9**********@yarrow.open.ac.uk...
Here's a knotty little problem.

I have some nasty little controls that needs to behave in a non-
windows-Standard way - don't ask why; it's a large application being
converted from some [much] older code and my users are adamant
that this behaviour mustn't change.

Specifically, I want to be able to set

myControl.Enabled = False

and, instead of the controls /actually/ being disabled, I want them to
/recolour/ themselves so that they /look/ disabled, but still respond to
Mouse events, can be copied from, and such like. (I realise the
ReadOnly property is going to be involved, here, but I don't think it
will do the whole job).

Adding to the complication; I thought I'd derive all of these controls
from a single ancestor UserControl and have that ancestor implement
an Interface containing the Enabled property (among other things), as in

Public Interface ITypeable
. . .
Property Enabled() as Boolean
. . .

Public Class Wrapper
Inherits UserControl
Implements ITypeable
. . .
Public Property Enabled() as Boolean _
Implements ITypeable.Enabled

And herein lies my problem.

The Enabled property already exists in UserControl, so when I try to
implement the Interface property, VB (2003) gets quite upset that the
specifiers or signatures on the Interface and Property don't match.
I've tried overloading, overriding, shadowing, and just about every
other modifier I can find on the Property and even overriding the
OnEnabledChanged routine, but I seem to be on a losing streak here.

Any Suggestions?

TIA,
Phill W.

I have a control that I don't want disabled when I set .Enabled = False,
when my code says
.Enabled = False
I have an application that uses UserConrols to

Nov 20 '05 #2
Phill,
Do you need to use Enabled specifically to implement the ITypeable.Enabled
property?

Have you consider naming Enabled, something other then Enabled?

Are you attempting to replace how UserControl.Enabled itself operates? Or
should UserControl.Enabled do what it normally does, while Wrapper.Enabled
does what you want?
The easiest route may be to use a different name for your Enabled property,
and ensure that UserControl.Enabled is "not touched", except possible in the
Specifically, I want to be able to set
myControl.MyEnabled = False

Otherwise I suspect you will need some clever (fragile?) overloading,
shadowing, overriding, of the property & OnEnabledChanged method (you
probably need to use a combination of things that it sounds like you tried
individually).

Hope this helps
Jay

"Phill. W" <P.A.Ward@o-p-e-n-.-a-c-.-u-k> wrote in message
news:c9**********@yarrow.open.ac.uk... Here's a knotty little problem.

I have some nasty little controls that needs to behave in a non-
windows-Standard way - don't ask why; it's a large application being
converted from some [much] older code and my users are adamant
that this behaviour mustn't change.

Specifically, I want to be able to set

myControl.Enabled = False

and, instead of the controls /actually/ being disabled, I want them to
/recolour/ themselves so that they /look/ disabled, but still respond to
Mouse events, can be copied from, and such like. (I realise the
ReadOnly property is going to be involved, here, but I don't think it
will do the whole job).

Adding to the complication; I thought I'd derive all of these controls
from a single ancestor UserControl and have that ancestor implement
an Interface containing the Enabled property (among other things), as in

Public Interface ITypeable
. . .
Property Enabled() as Boolean
. . .

Public Class Wrapper
Inherits UserControl
Implements ITypeable
. . .
Public Property Enabled() as Boolean _
Implements ITypeable.Enabled

And herein lies my problem.

The Enabled property already exists in UserControl, so when I try to
implement the Interface property, VB (2003) gets quite upset that the
specifiers or signatures on the Interface and Property don't match.
I've tried overloading, overriding, shadowing, and just about every
other modifier I can find on the Property and even overriding the
OnEnabledChanged routine, but I seem to be on a losing streak here.

Any Suggestions?

TIA,
Phill W.

I have a control that I don't want disabled when I set .Enabled = False,
when my code says
.Enabled = False
I have an application that uses UserConrols to

Nov 20 '05 #3
"Jay B. Harlow [MVP - Outlook]" <Ja************@msn.com> wrote in message
news:%2***************@TK2MSFTNGP12.phx.gbl...
Do you need to use Enabled specifically to implement the
ITypeable.Enabled property?
Ideally, yes.
Have you consider naming Enabled, something other then Enabled?
Yes - regretably this control will be used by other Developers who
may not appreciate the difference and will cause the eventual Users
considerable confusion :-(
Are you attempting to replace how UserControl.Enabled itself
operates? Or should UserControl.Enabled do what it normally
does, while Wrapper.Enabled does what you want?


Using Wrapper.Enabled is ideally what I'm after, but I need to have
similar behaviours in a number of controls - some are UserControls,
some direct derivatives of, for example, Button. The only way I
know of doing that is with an Interface, but you have to define the
property in order to Implement it, and that's where Studio gets upset.

I think the confusion is that my Wrapper class has both an Enabled
property of its own and my Shadow Enabled property, taken from
my Interface so, if I say

Me.Enabled = whatever

will VB assume I want the inherent property rather than my Shadow?

Regards,
Phill W.

Nov 20 '05 #4
Phill,
I think the confusion is that my Wrapper class has both an Enabled
property of its own and my Shadow Enabled property, taken from
my Interface so, if I say
There's the rub, and the reason (the two distinct Enabled properties) I am
suggesting you avoid this. ;-)
Me.Enabled = whatever
Read very carefully what Shadows does for you. As Shadows is partially how
you will need to get this to work!

http://msdn.microsoft.com/library/de...keyShadows.asp

http://msdn.microsoft.com/library/de...et12252001.asp

http://msdn.microsoft.com/library/de...bspec4_2_3.asp

http://msdn.microsoft.com/library/de...nshadowing.asp

Shadows BREAKS polymorphism, most of the time you want polymorphism, I
normally only use Shadows to "protected the definition of my class members"
as the first link states. It is unlikely that I would start a new design,
such as this one, that relied on Shadowing! In other words Enabled means
Enabled, in both the derived classes & base class. It does not/should not
mean Enabled in the Control and readonly/something else hybrid in the
derived classes. It can however mean Enabled in the Control, while meaning
Enabled+ in the derived class. Normally the designers of the base class mark
the member (property) as Overridable in the base class to allow you to
define Enabled+ in the derived classes...
When you Shadow the Enabled property, if you refer to Enabled via a base
class you will get the base class's Enabled, if you refer to Enabled via the
derived class you will get the derived class's Enabled.

Public Class Wrapper
Inherits Control ' any control: Button, UserControl, etc...
Public Shadows Property Enabled As Boolean
...

Public
End Class

Dim wrapper As New Wrapper

wrapper.Enabled = True ' will change Wrapper.Enabled

Dim base As Control = wrapper
base.Enabled = True ' will change Control.Enabled, not Wrapper.Enabled
which is probably desired.

' within Wrapper
Me.Enabled = True ' will change Wrapper.Enabled

MyBase.Enabled = True ' will change Control.Enabled
Are you attempting to replace how UserControl.Enabled itself
operates? Or should UserControl.Enabled do what it normally
does, while Wrapper.Enabled does what you want?


Using Wrapper.Enabled is ideally what I'm after, but I need to have
similar behaviours in a number of controls - some are UserControls,

You did not really answer this question. Should Control.Enabled only do what
Control.Enabled currently does, or should it behave as your new
Wrapper.Enabled property?

Are you using the Interface polymorphically? (do you use the interface as a
parameter to other methods?) If you aren't using the interface
polymorphically I don't know if I would keep it, of course if you want to
have the set of methods in all your classes its handy to keep, I would need
to have a better idea of what is really in the interface to decide. Part of
the point here is that Control already has Enabled, do you really need
Enabled in the Interface...

Anyway I would approach the solution something like:

Public Interface ITypeable

Property Enabled() As Boolean

End Interface

Public Class Wrapper
Inherits UserControl
Implements ITypeable

Private Property ITypeable_Enabled() As Boolean Implements
ITypeable.Enabled
Get
Return Enabled
End Get
Set(ByVal value As Boolean)
Enabled = value
End Set
End Property

Protected Overrides Sub OnEnabledChanged(ByVal e As
System.EventArgs)
MyBase.OnEnabledChanged(e)
' do the logic for Enabled changing
End Sub

End Class

This gives you Enabled in the Interface, it gives Wrapper Enabled+, it
allows Enabled to continue to be Enabled.

If you don't want Enabled+ (IMHO bad idea) you can try something like:

Public Class Wrapper
Inherits UserControl
Implements ITypeable

Public Shadows Property Enabled() As Boolean Implements
ITypeable.Enabled
Get

End Get
Set(ByVal value As Boolean)

End Set
End Property
Protected Overrides Sub OnEnabledChanged(ByVal e As
System.EventArgs)
MyBase.OnEnabledChanged(e)
If MyBase.Enabled Then
' do something based on Control.Enabled
ElseIf Me.Enabled Then
' do something based on Wrapper.Enabled
End If
End Sub

End Class

Hope this helps
Jay

"Phill. W" <P.A.Ward@o-p-e-n-.-a-c-.-u-k> wrote in message
news:c9**********@yarrow.open.ac.uk... "Jay B. Harlow [MVP - Outlook]" <Ja************@msn.com> wrote in message
news:%2***************@TK2MSFTNGP12.phx.gbl...
Do you need to use Enabled specifically to implement the
ITypeable.Enabled property?


Ideally, yes.
Have you consider naming Enabled, something other then Enabled?


Yes - regretably this control will be used by other Developers who
may not appreciate the difference and will cause the eventual Users
considerable confusion :-(
Are you attempting to replace how UserControl.Enabled itself
operates? Or should UserControl.Enabled do what it normally
does, while Wrapper.Enabled does what you want?


Using Wrapper.Enabled is ideally what I'm after, but I need to have
similar behaviours in a number of controls - some are UserControls,
some direct derivatives of, for example, Button. The only way I
know of doing that is with an Interface, but you have to define the
property in order to Implement it, and that's where Studio gets upset.

I think the confusion is that my Wrapper class has both an Enabled
property of its own and my Shadow Enabled property, taken from
my Interface so, if I say

Me.Enabled = whatever

will VB assume I want the inherent property rather than my Shadow?

Regards,
Phill W.

Nov 20 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Andrew Durdin | last post by:
In Python, you can override the behaviour of most operators for a class, by defining __add__, __gt__, and the other special object methods. I noticed that, although there are special methods for...
3
by: Ali Eghtebas | last post by:
Hi, I have 3 questions regarding the code below: 1) Why can't I trap the KEYDOWN while I can trap KEYUP? 2) Is it correct that I use Return True within the IF-Statement? (I've already read...
4
by: Nilesh | last post by:
I am confused about the purpose of 'new' in overriding. Consider following example. <code_snippet> using console = System.Console; public class TestClass { public static void Main() {
1
by: Morten Plathe | last post by:
Hi, Is there a way to override the shadowed (grey) backcolor of a textbox when the textbox is disabled for input (textbox.enabled = false) ? In some cases I want to have a custom backcolor when...
3
by: Amin Sobati | last post by:
Hi, I have two classes. Class2 inhertis Class1: ----------------------------- Public Class Class1 Public Overridable Sub MySub() End Sub End Class Public Class Class2
1
by: Soheil | last post by:
Hi, I'm trying to use http compression for my web service. I've enabled it on the server and I've overridden SoapHttpClientProtocol.GetWebResponse to add the proper http header to the outgoing...
4
by: RSH | last post by:
How do I go about overriding a Control's OnPaint Method? I would like to prevent a control's color from changing when it is disabled. I have overridden the Form's OnPaint Method but I need to...
4
by: RSH | last post by:
I tried an implementation of overriding a ComboBox control. I am simply trying to avoid it repainting, but I can't seem to get it to work. What am I doing wrong? Please help. Thanks, Ron
10
by: r035198x | last post by:
The Object class has five non final methods namely equals, hashCode, toString, clone, and finalize. These were designed to be overridden according to specific general contracts. Other classes that...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
Oralloy
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,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.