如何从TXT文本中读取数据到textBox.Text里
1个回答
展开全部
private void textBox1_DragDrop(object sender, DragEventArgs e)
{
var filenames = (string[])e.Data.GetData(DataFormats.FileDrop);
using (StreamReader sr = new StreamReader(filenames[0], Encoding.Default))
{
textBox1.Text = sr.ReadToEnd();
}
}
private void textBox1_DragEnter(object sender, DragEventArgs e)
{
if (e.Data.GetDataPresent(DataFormats.FileDrop, false) == true)
{
var filenames=(string[])e.Data.GetData(DataFormats.FileDrop);
var hz=filenames[0].LastIndexOf('.')+1;
var houzhui = filenames[0].Substring(hz);//文件后缀名
if (houzhui == "txt")
{
e.Effect = DragDropEffects.All;
}
}
}
给textbox控件添加DragDrop和DragEnter 事件
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询