equivalent to "Load" event for a textbox.

Z

ZBINContact

I am creating a self-checking set of usercontrols. They tend to call
their self-checking functionally in the "Load" event. I have run into
a problem with my TextBox usercontrol, however, as the base component
does NOT have a Load event as far as i can ascertain.

What I need is to have a self-check function called when the component
loads. I am currently using the "Layout" event but that can fire
multiple times, and I can't just call the method from the constructor
for multiple reasons.

So in summary:

1. Is there an event that I just haven't noticed that can be used in
place of "Load" for a TextBox
OR, lacking that
2. Is there a way to add an event or mimic this Load event behavior?
OR
3. Is there a way to fully disable the Layout event handler inside
its own code so that is guaranteed only to fire once at the beginning
of runtime and not twice nor ever again?

Whoever answers this, thank you so much for your time. This has
driven me crazy.
 
N

Nicholas Paldino [.NET/C# MVP]

Well, you might want to detail why calling the method from the
constructor isn't feasible, because this is really the way I would do it.

However, if you absolutely positively MUST not place the code in the
constructor, then you might want to place the code in the HandleCreated
event. It will be called after the handle for the window is created.

Mind you, that event can be called multiple times, so you might want to
put a flag in the event handler indicating to only run that code once, but
generally, it will be called when you show the control for the first time,
as well as when the control handle is recreated (which probably is not
often, but the point here is that it definitely is called after the
constructor, and when the first time the control is shown).
 
B

Ben Voigt [C++ MVP]

Nicholas Paldino said:
Well, you might want to detail why calling the method from the
constructor isn't feasible, because this is really the way I would do it.

However, if you absolutely positively MUST not place the code in the
constructor, then you might want to place the code in the HandleCreated
event. It will be called after the handle for the window is created.

Mind you, that event can be called multiple times, so you might want to
put a flag in the event handler indicating to only run that code once, but
generally, it will be called when you show the control for the first time,
as well as when the control handle is recreated (which probably is not
often, but the point here is that it definitely is called after the
constructor, and when the first time the control is shown).

A teeny bit more efficient: unsubscribe from the event instead of using a
flag.
--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

I am creating a self-checking set of usercontrols. They tend to call
their self-checking functionally in the "Load" event. I have run into
a problem with my TextBox usercontrol, however, as the base component
does NOT have a Load event as far as i can ascertain.

What I need is to have a self-check function called when the component
loads. I am currently using the "Layout" event but that can fire
multiple times, and I can't just call the method from the constructor
for multiple reasons.

So in summary:

1. Is there an event that I just haven't noticed that can be used in
place of "Load" for a TextBox
OR, lacking that
2. Is there a way to add an event or mimic this Load event behavior?
OR
3. Is there a way to fully disable the Layout event handler inside
its own code so that is guaranteed only to fire once at the beginning
of runtime and not twice nor ever again?

Whoever answers this, thank you so much for your time. This has
driven me crazy.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top