Click here to Skip to main content
15,884,298 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hello everybody ...
i have about 5 textbox in my winform aplication, i hava a button, and a textbox apart just for writtin.. the thing is that i want that went i click the button, text that is in the textbox for write, go to a textbox where is the cursor
Posted
Comments
Chris Maunder 27-May-11 22:05pm    
What, specifically, isn't working? You need to be precise.
[no name] 27-May-11 23:58pm    
post what you have done so far, let us take a look and correct the mistake

1 solution

It's not difficult.
All you have to do is set up a Private class level TextBox variable to hold the last one you were in, and construct an Leave event handler for the 5 textboxes you want to recieve the information - they all go to the same one:
private TextBox lastCursor = null;
private void tbWithCursor_Leave(object sender, EventArgs e)
    {
    lastCursor = sender as TextBox;
    }
The button click event is then simple:
private void butMoveText_Click(object sender, EventArgs e)
    {
    if (lastCursor != null)
        {
        lastCursor.Text = tbForWriting.Text;
        }
    }
What happens is that when the focus leave a TextBox (i.e. it had the cursor in it, but some other control is becoming the active control) the identity of the TextBox is saved.When you click the button, the last saved value is teh TextBox you want to put your text into.

Simples!
 
Share this answer
 
Comments
edygs1010 28-May-11 21:19pm    
Thanks OriginalGriff it was very helpful to me

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900