473,606 Members | 2,877 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.Enabl ed = 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.Enabl ed

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
OnEnabledChange d 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 5948
Public Interface ITypeable
Property Enabled() As Boolean
End Interface

Public Class Wrapper
Inherits Windows.Forms.U serControl
Implements ITypeable

Public Shadows Property Enabled() As Boolean Implements
ITypeable.Enabl ed
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.Enabl ed = 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.Enabl ed

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
OnEnabledChange d 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.Enabl ed
property?

Have you consider naming Enabled, something other then Enabled?

Are you attempting to replace how UserControl.Ena bled itself operates? Or
should UserControl.Ena bled 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.Ena bled is "not touched", except possible in the
Specifically, I want to be able to set
myControl.MyEna bled = False

Otherwise I suspect you will need some clever (fragile?) overloading,
shadowing, overriding, of the property & OnEnabledChange d 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.Enabl ed = 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.Enabl ed

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
OnEnabledChange d 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******** *******@TK2MSFT NGP12.phx.gbl.. .
Do you need to use Enabled specifically to implement the
ITypeable.Enabl ed 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.Ena bled itself
operates? Or should UserControl.Ena bled 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.Ena bled itself
operates? Or should UserControl.Ena bled 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_Enabl ed() As Boolean Implements
ITypeable.Enabl ed
Get
Return Enabled
End Get
Set(ByVal value As Boolean)
Enabled = value
End Set
End Property

Protected Overrides Sub OnEnabledChange d(ByVal e As
System.EventArg s)
MyBase.OnEnable dChanged(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.Enabl ed
Get

End Get
Set(ByVal value As Boolean)

End Set
End Property
Protected Overrides Sub OnEnabledChange d(ByVal e As
System.EventArg s)
MyBase.OnEnable dChanged(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******** *******@TK2MSFT NGP12.phx.gbl.. .
Do you need to use Enabled specifically to implement the
ITypeable.Enabl ed 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.Ena bled itself
operates? Or should UserControl.Ena bled 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
3784
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 most operators, they are conspicuously absent for the logical "or" and "and". I'm guessing that the reason for this is that these operators short-circuit if their first operand answers the whole question? Would it be possible to allow...
3
4177
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 the documentation but it is rather hard to understand so please don't refer to it :) 3) Many examples in the newsgroups use Return MyBase.ProcessKeyPreview(m) as the last code line while I have used Return MyBase.ProcessKeyEventArgs(m)
4
1703
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
2668
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 the textbox is disabled. The same question applies for a listview. When the listview is disabled, the backcolor of the listview turns grey (shadowed) for the area which is not filled
3
1536
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
6109
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 request. Now I have to override SoapHttpClientProtocol.GetWebResponse so that I can decompress the data on the response stream. Since this method returns a HttpWebResponse, I need to derive
4
4664
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 do it at the control level. Thanks, Ron
4
3717
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
105171
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 make use of these methods assume that the methods obey these contracts so it is necessary to ensure that if your classes override these methods, they do so correctly. In this article I'll take a look at the equals and hashCode methods. ...
0
8031
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8443
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8107
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8315
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
5971
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5467
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
2452
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1565
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
1309
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.