Transferrring focus between forms.

Z

Zach

I have a question for which I will use an analogy to describe the situation.

I have form A on the display. I overlay form A with form B. (So form B is
on top of form A.)
B contains checkboxes. Each checkbox correlates with a different VALUE.
Upon ticking a checkbox on form B, VALUE is stored in a static variable and
form B is closed.
Subsequently clicking a textbox on form A causes VALUE to be displayed in
that textbox on form A.

My question is: how can I achieve the result
(VALUE being displayed in textbox on form A)
without first having to click the textbox on form A (to transfer the focus
to form A).

Hopefully his description makes sense.

Zach.
 
Z

Zach

Peter Duniho said:
I didn't see an analogy anywhere in there. And without a working code
example showing exactly what you mean, it's hard to know for certain that
I understand the problem. But I think I do.

First issue I have with your nominal implementation is the use of a static
variable to communicate the result of form B. Form B should have an
instance property that is the value pertaining to the result of the user's
input on form B.

Now, whether form A gets the value from an instance property in the form B
class or elsewhere (such as the static variable you mention), the real
question is how to have form A react not to a change in focus, but rather
to the completion of input via form B.

There are lots of ways to do this, but they all will involve an event of
some sort. My preferred solution would be to simply subscribe to the
FormClosed event of form B, and then when that event is raised, retrieve
the value from the instance property of form B, and updating the
appropriate TextBox on form A.

Implementing that should be relatively simple, taking advantage of
functionality already present in the Forms API (the FormClosed event) and
C# (properties).

Pete

Given Form A and form B

If I have in form B

this.FormClosing += B_FormClosing;

void B_FormClosing(object o, EventArgs e)
{
// some Bcode
}

and in A

B.FormClosing += B_FormClosing

void B_FormClosing(object o, EventArgs e)
{
// some Acode
}

Acode isn’t executed.
I guess I misunderstood what you meant.
Zach
 
J

Jeff Johnson

and in A

B.FormClosing += B_FormClosing

void B_FormClosing(object o, EventArgs e)
{
// some Acode
}

Acode isn't executed.
I guess I misunderstood what you meant.

Please show how you are creating and opening form B from form A.
 
Z

Zach

Jeff Johnson said:
Please show how you are creating and opening form B from form A.
Pete and Jeff,
I dropped a clanger. The code is working ok now.
Many thanks for your willingness to help. What
Pete suggested was the solution alright.
Zach.
 

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