Click here to Skip to main content
15,885,878 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hey Guys I have a button who is sending the text to the textbox

What I have tried:

private void button10_Click(object sender, EventArgs e)
        {

            string sent = button10.Text;
            textBox1.AppendText(sent);
            textBox1.AppendText(Environment.NewLine);
        }


now how I can if I have to click button 5 times can do it with a button click I was thinking just to click a button who will copy the last line in the textbox and paste it in the same text box *times how much I wright it I can not simulate a button click because i have more that one button
Posted
Updated 30-Mar-21 21:30pm
Comments
Arfat M 31-Mar-21 3:16am    
description of issue isn't so clear can you brief what exactly you are in need
Kleo Rogers 31-Mar-21 3:24am    
I need to copy the last line of the textbox1 and paste it in the same textbox that many times how much i wright it in textbox2

1 solution

Well, you need only one event for all your textboxes:
C#
private void button_Click(object sender, EventArgs e)
{
    //get clicked button
    Button btn = sender as Button;
    //check how many times this button has been clicked
    int cnt = btn.Tag == null ? 0 : (int)btn.Tag;
    //save value+1 for further use
    btn.Tag = cnt +1;
    //get last line from textbox
    string sent = textBox1.Lines[textBox1.Lines.Count-1];
    textBox1.AppendText(string.Format("\n{0} has been clicked {1} times", btn.Name, cnt));
}
 
Share this answer
 
Comments
Kleo Rogers 31-Mar-21 4:01am    
yes but I am righting how many times the button will be clicked in the textbox 2
Maciej Los 31-Mar-21 5:08am    
So, replace it with custom text.

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