Need help with windows form

N

newbie

Hi,

I have a windows form written in C#. The form has multiple textboxes
and multiple buttons.

I want to create a form where when the users clicks on a particulat
textbox and then clicks on a button, a text is added to that textbox.

How do i go about doing this when a user selects on any textbox and
clicks on a buttont to insert text, it insert the text in the correct
textbox (the textbox that the user selected before clicking on the
button)?

Any help is really appreciated.

Thanks,

Sean
 
S

Sonya

newbie said:
I want to create a form where when the users clicks on a particulat
textbox and then clicks on a button, a text is added to that textbox.

How do i go about doing this when a user selects on any textbox and
clicks on a buttont to insert text, it insert the text in the correct
textbox (the textbox that the user selected before clicking on the
button)?

Do you mean somethin like ?

private void button1_Click(object sender, EventArgs e)
{
textBox1.Text = textBox2.SelectedText;
}
 
N

newbie

Not really,

Say they click on button1, it will always add the text "TEST" to the
textbox the cursor was on.

How do I know which textbox to add the word "TEST" too since there are
multiple textboxes on the form and it can be a different textbox
everytime depending on which text box they were working on.
 
F

forest demon

newbie said:
Not really,

Say they click on button1, it will always add the text "TEST" to the
textbox the cursor was on.

How do I know which textbox to add the word "TEST" too since there are
multiple textboxes on the form and it can be a different textbox
everytime depending on which text box they were working on.

i needed to do something similar. i needed to find out what control
had focus "prior" to clicking or giving focus to a different control,
like a button.

so, what i did was use the MouseEnter event for a button and a
"focusFlag". this way i knew what control (a textbox in this case) had
focus, before the mouse click on the button occurred.

it's a hokey kind of way to do it, but it worked for me.


private void btnClear_MouseEnter(object sender, EventArgs e)
{
////get the focus before the mouse click occurs
if (tbProduct.Focused)
focusFlag = "tbProduct";
else if (tbProductCode.Focused)
focusFlag = "tbProductCode";
}
 

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