1
void ClearAllRichtextboxes()
{
    richTextBox3.Clear();
    richTextBox5.Clear();
    richTextBox6.Clear();
    richTextBox9.Clear();
    richTextBox10.Clear();
}

ClearAllRichtextboxes();

if (comboBox5.Text == "Primer")
{
    richTextBox5.Text = "This is the number of primer tins" + primer.ToString();
    richTextBox6.Text = "This is the cost of the primer tins" + primercost.ToString();
}

if (comboBox3.Text == "Matt")
{
    richTextBox10.Text = "This is how many 2.5 tins of paint are needed: " + val44.ToString();
    richTextBox9.Text = "This is the matt cost" + valmatt.ToString();
}

if (comboBox3.Text == "Vinyl ")
{
    richTextBox10.Text = "This is how many 2.5 tins of paint are needed" + val44.ToString();
    richTextBox9.Text = "This is the of vinyl cost" + valmatt.ToString();
}

if (comboBox3.Text =="Silk")
{
    richTextBox10.Text = "This is how many 2.5 tins of paint are needed" + silkval.ToString();
    richTextBox9.Text = "This is the cost: " + valcostsilk.ToString();
}

Hi, I need to output the variables of valcostsilk.ToStrin, silkval.ToStrin, valmatt.ToString, val44.ToString, val44.ToString. Pretty much all of them to just ONE rich text box. As I am new to c# so, I have no idea. I asked on a previous thread, but I couldn't seem to get the answer I needed. Someone mentioned Enviorment.Newline, but I can't seem to program it right.

Any help appreciated.

Balagurunathan Marimuthu
  • 2,927
  • 4
  • 31
  • 44
Nel J
  • 13
  • 3
  • There is a RTB mehod `AppendText` and yes add an Environment.NewLine as well. – TaW Jul 30 '17 at 13:14
  • could you give me an example to get me started? I'm trying to do it now, but it doesn't seem to want to do it for me. – Nel J Jul 30 '17 at 13:18
  • `commonRTB.AppendText( "This is the number of primer tins" + primer.ToString() + Environment.NewLine);` – TaW Jul 30 '17 at 13:28
  • `Environment.NewLine` works specific to the environment where your code executes. For example, this gets string containing "\r\n" for non-Unix platforms, or a string containing "\n" for Unix platforms - so it is just a string like any other string with specific content that you desire. – Mark Schultheiss Jul 30 '17 at 13:31
  • You are replacing the text (which is empty from your clear method) based on TWO combo boxes `comboBox3` and `comboBox5` to various text boxes. Doing multiple things like this in one place appears to be confusing you; is that a true statement? It might also help you if you create a `StringBuilder`, for each textbox, set those to what you desire the content of the textbox to be, then set the text once using those for each of your text boxes that you have; helping you understand your code better. – Mark Schultheiss Jul 30 '17 at 14:09
  • Please do not ask the same question multiple times. – Rob Aug 02 '17 at 00:28

1 Answers1

0

You need to put your if statements into the event handler for comboBox3 changing. To do this just double-click the comboBox in the designer view and it will create the event handler in the code-behind for you. Move your if statements all into there (you could also use a switch statement). Also shown is how you create a single complex string into the Text property including a newline. I avoid concatenating with +. $"{}" is cleaner IMHO.

Your code also needs to be cleaned up - you're clearing the same RTB twice in your method for instance, and you reference both comboBox5 and 3 for apparently the same purpose in your series of ifs. You will also need fewer RTBs. Hope it helps.

    private void comboBox3_SelectedIndexChanged(object sender, EventArgs e)
    {
        if (comboBox3.Text == "Matt")
        {
            richTextBox10.Text = $"This is how many 2.5 tins of paint are needed: {val44.ToString()}.{Environment.NewLine}This is the matt cost: {valmatt.ToString()}";
            richTextBox10.Update();
        }
    }

Example of switch statement:

switch (comboBox3.Text)
{
    case ("Matt"):
        {
            richTextBox10.Text = $"This is how many 2.5 tins of paint are needed: {val44.ToString()}.{Environment.NewLine}This is the matt cost: {valmatt.ToString()}";
            richTextBox10.Update();
            break;
        }

    case ("Vinyl"):
        {    (insert code)
             break;
        }
}
gnivler
  • 100
  • 1
  • 13