在文本框/块中打印多行.net c#

Joh*_*las 1 .net c# visual-studio-2015

所以我要做的是将输出打印到文本框但是发生的事情是它始终使用它找到的最后一个textbox2.text因为我假设每次打印它都会覆盖最后一个输出.我正在寻找某种工作方式

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Web;
using System.Net;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;

namespace ProgrammingProject
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();
        }
        private void btn_getinfo_Click(object sender, RoutedEventArgs e)
        {
            string UserInput = "76561198056932916";
           // string UserInput = textBox.Text;
            ProfileSummary(UserInput);
        }

        public void ProfileSummary(string SteamID)
        {
            string SteamKey = "CensoredAPIKEY";
            WebClient c = new WebClient(); 
            var data = c.DownloadString("http://api.steampowered.com/ISteamUser/GetPlayerSummaries/v0002/" + "?key=" + SteamKey + "&steamids=" + SteamID);
            //Console.WriteLine(data);
            JObject o = JObject.Parse(data);
            JArray players = (JArray)o["response"]["players"];

            if (players.Count > 0)
            {
                int PrivacyLevel = (int)players[0]["communityvisibilitystate"];
                string username = (string)players[0]["personaname"];
                string ProUrl = (string)players[0]["profileurl"];
                double LastLogOff = (double)players[0]["lastlogoff"];
                int CurrentStatus = (int)players[0]["personastate"];
                int GamePlaying = (int)players[0]["gameid"];

                textBox2.Text = "your username is " + username + "\n";
                textBox2.Text = "You last logged off on " + ConvertUnix(LastLogOff) + "\n";

                if (PrivacyLevel == 3)
                {
                    textBox2.Text = "This user's account is public"; 
                }
                else if (PrivacyLevel == 1)
                {
                    textBox2.Text = "This user's account is private";
                }
                switch (CurrentStatus)
                {
                    case 1:
                        textBox2.Text = "This user is offline";
                        break;
                    case 2:
                        textBox2.Text = "This User is online and playing";
                        break;
                }
            }
            else
            {
                textBox2.Text = "You have entered the SteamID incorrectly";
            }

        Console.ReadLine();  // Don't remove you idiot

    }

    public static DateTime ConvertUnix(double unixTimeStamp)
    {
        // Unix timestamp is seconds past epoch
        System.DateTime dtDateTime = new DateTime(1970, 1, 1, 0, 0, 0, 0, System.DateTimeKind.Local);
        dtDateTime = dtDateTime.AddSeconds(unixTimeStamp).ToLocalTime();
        return dtDateTime;
    }
}
Run Code Online (Sandbox Code Playgroud)

这段代码的输出将是最后一个textbox2.text,所以在这种情况下它将是switch语句.我知道我没有解释它最好,但我只是不知道为什么会这样,谢谢

use*_*639 5

你应该使用textBox2.Text += "more text to be added to the text box"而不是textBox2.Text = "more text to be added to the text box"