Add Text In textbox in certain position C #

1

Hello, I'm developing a dental software which one of the functions is to select a tooth on a button and add the name of this tooth in a textbox. So far, no problem, but the point is that this textbox is about observations, and I would like the name of each selected tooth to be added in the textbox on different lines and not side by side. Then as each button referring to each tooth is selected it goes adding the name of the teeth one in each row. For example, when I click on button1 the text "Bot1" is added in the textbox and so on, the problem is that if I click on more than one button the text should go to different lines and not the same. This is what I would like but I can not develop a logic to do this does anyone have any ideas?

It follows the click event I'm using on the buttons:

private void button1_Click(object sender, EventArgs e)
    {
        string Texto = txtObservacao.Text;
        txtObservacao.Text += "Terceiro Molar Inf.Direito (48):";
        if (btnMolar48.BackColor == Color.FromArgb(150, Color.LightSeaGreen))
        {
            btnMolar48.BackColor = Color.Transparent;
            txtObservacao.Text = Texto.Replace("Terceiro Molar Inf.Direito (48):", "");
        }
        else
        {
            btnMolar48.BackColor = Color.FromArgb(150, Color.LightSeaGreen);
        }
    }

    private void btnMolar47_Click(object sender, EventArgs e)
    {
        string Texto = txtObservacao.Text;
        txtObservacao.Text += "\n" + "Segundo Molar Inf.Direito(47):";
        if (btnMolar47.BackColor == Color.FromArgb(150, Color.LightSeaGreen))
        {
            btnMolar47.BackColor = Color.Transparent;
            txtObservacao.Text = Texto.Replace("Segundo Molar Inf.Direito(47):", "");
        }
        else
        {
            btnMolar47.BackColor = Color.FromArgb(150, Color.LightSeaGreen);
        }
    }'

Thank you.

    
asked by anonymous 02.11.2016 / 19:43

3 answers

3

There are basically two types of line breaks CR (carriage return - \n ) and LF (line feed - \r ).

You can read a bit about it here at What's the difference between carriage return and line feed?

Possibly you are using the wrong type, to avoid this kind of stress and even to be completely sure that your code will work even on other machines, you can use Environment.NewLine .

Example:

textBox.Text = "Linha 1" + Environment.NewLine + "Linha 2";
    
02.11.2016 / 22:21
0
 private void button1_Click(object sender, EventArgs e)
 {
 int h =3;

Button newButton = new Button ();
    Button [] buttonArray = new Button [8];

for (int i = 0; i <= h-1; i++)
{
  buttonArray[i] = new Button();
 buttonArray[i].Size = new Size(20, 43);
  buttonArray[i].Name= ""+i+"";
  buttonArray[i].Click += button_Click;//function
  buttonArray[i].Location = new Point(40, 20 + (i * 20));
  panel1.Controls.Add(buttonArray[i]);

}  }
    
02.11.2016 / 21:13
0

I was able to solve my problem using System.Environment.NewLine.

string Texto = txtObservacao.Text; txtObservacao.Text += System.Environment.NewLine; txtObservacao.Text += "Segundo Molar Inf.Direito(47):"; if (btnMolar47.BackColor == Color.FromArgb(150, Color.LightSeaGreen)) { btnMolar47.BackColor = Color.Transparent; txtObservacao.Text = Texto.Replace("Segundo Molar Inf.Direito(47):", ""); } else { btnMolar47.BackColor = Color.FromArgb(150, Color.LightSeaGreen); }

I apologize if I was not clear on my question up, but who answered, my sincere thank you!

    
02.11.2016 / 22:11