How to override Control.Focused?

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hello NG!

Within a custom-control (inherits system.windows.forms.control), that
contains some 'basic'-controls I want to override the Focused-property,
because oztherwise it always returns false. But the property is marked as
NotOverridable within the CF (althought the help says something different).

Is there a workaround for that problem?

Thanks, D.Barisch
 
U can use "shadows" instead of overrides

That also was my first thought, but there's a scenario, that makes it not
work:

This control (and some others), implements a (self-defined) interface.
Within my programm I loop through all controls of a form. I only want to
call functions for the controls, that implement my interface, so I test if
"TypeOf" is my interface and if so, i cast the control to it.
But if i call the Focused-Property of the (casted) control, the
base-class-property (sys.win.forms.control) is called, not the specific one
of my control-class.

Any workaround or do really have to cast to each of my self-defined
control-classes?

Thanks, D.Barisch
 
I am not sure I understand your problem.
Is the base's Focused property doesn't work for you?
 
I am not sure I understand your problem.
Is the base's Focused property doesn't work for you?

No, it does not work. That's the problem. When I cast the MyControl in my
programm to MyInterface and then call MyCastedControl.Focused (where Focused
is Shadowed in MyControl) it always returns False, because
Sys.Win.Forms.Control.Focused is called, not MyControl.Focused (see
"Shadows"-help for details).

The base-property does not work, because MyControl-Class consists of a
TextBox (with specific ContextMenu-functionality, ...) and some other
controls. So in my Focused-property I should ask, if the TextBox is focused,
but I don't know how to "send it upwards".

Thanks, D.Barisch
 
Does the MyInterface has Focused property that's implemented by your
control?
 
Does the MyInterface has Focused property that's implemented by your

No, maybe that's the key...

....with one disadvantage: I have to implement the Focused-Property for each
of my controls (even if it only calls the base-class property)

Thanks, D.Barisch
 
Back
Top