简体   繁体   中英

Converting a program from console to windows form C#

I am trying to convert a program from console to windows form but the problem is that the output is not showing on my textbox. My program is that user inputs how many number of rows.

图片中的示例输出

    int n = int.Parse(textbox1.Text);
    int counter1 = 1,counter2 = 1,size = n + n -1;
       for(int i = 0;i<size;i++){
       for(int j = 0;j<size;j++){
    
    if(i<n-1){
    if(j<n-1){
    if(i == j){
        textBox2.Text =  "{0} " + counter1;
        counter1++;}
        else{
        textBox2.Text = " ";
    } }
    else{
            if(i + j == size-1){
            textBox2.Text =  "{0} " + counter2;
        counter2++;}                    
            else{
            textBox2.Text = " ";
        }
    } }
        else if(i == n- 1 && j == n-1){
        textBox2.Text =  "{0} " + counter1;
        counter1--;
        counter2--;   }
            else if(i == n-1 && j != n-1){
            textBox2.Text = " ";
            }
            else if(i > n-1){
            if(j>n-1){
                if(i == j){
                textBox2.Text = "{0} " + counter1;
                counter1--;
            }           
                else{
            textBox2.Text = " ";
        } }
        else
        {
            if(i + j == size-1){
            textBox2.Text = "{0} " + counter2;
            counter2--;
        }
            else{
            textBox2.Text = " ";
            }
        } } }
            textBox2.Text = " ";
            }

The program is to display the input x number pattern. Thanks in advance.

You are resetting the text of textBox2 every time. You should use the += operator instead of =. Side note: You should also use the special '\\n' character when you need a new line.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM