UserControl.TextChanged

  • Thread starter Thread starter Francesco
  • Start date Start date
F

Francesco

Hi all,
I am trying to make a UserControl with a TextBox in it.
I have to publish the TextChanged event of the inner TextBox, but I have
some trouble.
If I declare :
public event EventHandler TextChanged;

I get a compiler error saying that TextChanged is already declared and I
have to use :
public new event EventHandler TextChanged;

With the "new" keyword added the project compiles but when I drop the
component the TextChanged event doesn't appear in the properties of the
control.

I tried to look at the source code of UserControl with the Reflector
decompiler, and in its declaration there is the TextChanged event, but you
can't access it.

The same thing appears with the Text property.

What should I do to publish both the Text and TextChanged properties?

TIA
Ciao
Formentz
 
Hi,
It won't appear in the properties. This will happen if you only use
design-time code. But in your case, with the "new" then it's run-time code;
thus won't appear in the properties
 
The TextChanged event indeed exists in the Control class and is related to
its Text property. I would therefore suggest you expose an event like
"TextBoxTextChanged" not to alter the standard event's semantics.
Alternatively you could use the protected OnTextChanged method to raise the
TextChanged event.
 
First of all thanks for the answer,

I don't understand, if you try to do this :
UserControl uc;
and then, in the code you write "uc." the code completion shows all the
methods and properties of the UserControl class, and let you select the
property or method you want to use.
But if you do so, the uc.TextChanged property doesn't appear and the same
thing occurs with uc.Text property.

So the question is : how can I show the TextChanged event in the events of
the properties window?
And to show the Text property?

Thanks

Ciao
Formentz
 
Hi Dmitry,
I would therefore suggest you expose an event like
"TextBoxTextChanged" not to alter the standard event's semantics.

it is for this reason that I want to keep the name of the event to
"TextChanged", so the control will appear as a real TextBox.
The problem is that both TextChanged and Text properties seems to be hidden
both in the designer and in code.
Please try to do :
UserControl uc;
then type "uc." to show all methods and properties of UserControl and you
will see that the two properties aren't shown in the list.

Thanks

Ciao
Formentz
 
Back
Top