static void Main(string[] args)
{
StreamReader objReader = new StreamReader("c:\\test.txt",System.Text.Encoding.GetEncoding("gb2312"));
string sLine="";
ArrayList arrText = new ArrayList();
while (sLine != null)
{
sLine = objReader.ReadLine();
if (sLine != null)
arrText.Add(sLine);
}
objReader.Close();
foreach (string sOutput in arrText)
Console.WriteLine(sOutput);
Console.ReadLine();
}
请教大家,以上这段代码能将文本框中的内容通过控制台输出,我想让他们在文本框中显示,应该怎么做呢?我在窗体上添加了名为source的文本框,并把最后一句改为source.Text = sOutput;可是行,请问我是错在哪了?请大侠执教!
{
StreamReader objReader = new StreamReader("c:\\test.txt",System.Text.Encoding.GetEncoding("gb2312"));
string sLine="";
ArrayList arrText = new ArrayList();
while (sLine != null)
{
sLine = objReader.ReadLine();
if (sLine != null)
arrText.Add(sLine);
}
objReader.Close();
foreach (string sOutput in arrText)
Console.WriteLine(sOutput);
Console.ReadLine();
}
请教大家,以上这段代码能将文本框中的内容通过控制台输出,我想让他们在文本框中显示,应该怎么做呢?我在窗体上添加了名为source的文本框,并把最后一句改为source.Text = sOutput;可是行,请问我是错在哪了?请大侠执教!
然后我试了下,可以从控制台输入,文本框输出,代码如下
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;namespace Console_And_Form
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
} private void Form1_Load(object sender, EventArgs e)
{
} private void button1_Click(object sender, EventArgs e)
{
string d = Console.ReadLine();
textBox1.Text = d;
}
}
}
using System;
using System.IO;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;namespace WindowsApplication4
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
} private void Form1_Load(object sender, EventArgs e)
{
StreamReader objReader = new StreamReader("c:\\test.txt", System.Text.Encoding.GetEncoding("gb2312"));
string sLine = "";
ArrayList arrText = new ArrayList();
while (sLine != null)
{
sLine = objReader.ReadLine();
if (sLine != null)
arrText.Add(sLine);
}
objReader.Close();
foreach (string sOutput in arrText)
textBox1.Text += sOutput;
}
}
}