Click here to Skip to main content
15,906,455 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
Good After Noon,
My form having Button "Name", 3 text boxes, At the time of click event, i have to place a label in text box which is having cursor at the position of cursor.
Posted
Updated 6-Jun-11 21:11pm
v2
Comments
Sergey Alexandrovich Kryukov 7-Jun-11 3:19am    
Where is your question? Well, place it...
--SA

You have to "remember" where you were when you clicked the button, so at class level, create a varaiable:
private TextBox lastUsed = null;

Handle the Leave event for all of the three textboxes with the same handler, and do this:
private void allMyTextBoxes_Leave(object sender, EventArgs e)
    {
    lastUsed = sender as TextBox;
    }

Then, in your button click event, you can do this:
private void butPutTextInLastTextBox_Click(object sender, EventArgs e)
    {
    if (lastUsed != null)
        {
        lastUsed.Text = "Hello";
        }
    }
 
Share this answer
 
Comments
ajitha.pusapati 7-Jun-11 5:19am    
Thank u so much...
it will work.. but lastUsed.Text +="Hello" this is exactly i want.
i have to put a label instead of "Hello". is it possible
OriginalGriff 7-Jun-11 5:29am    
Yes - a string, is a string, is a string:
lastUsed.Text += myLabel.Text;
ajitha.pusapati 7-Jun-11 5:32am    
it should different form remaining text of text box. is it possible.
OriginalGriff 7-Jun-11 5:37am    
Sorry? I don't understand your question: please give an example!
ajitha.pusapati 7-Jun-11 5:41am    
if i enter "Reservation conformed to $Name$ on $Date$"
$Name$ and $Date$ enter through button clicking. reaming i entered normally.
name and date are variables. name and date color is blue and remaining black.
C#
buttonName.Click += (sender, eventArgs) => {
    myTextBox.Text =
        myTextBox.Text.Insert(
            myTextBox.Text.SelectionStart,
            myLabel.Text);
};


—SA
 
Share this answer
 

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