• 微软原版系统

  • 一键重装系统

  • 纯净系统

  • 在线技术客服

魔法猪系统重装大师 一键在线制作启动 U 盘 PE 系统 用一键重装的魔法拯救失去灵魂的系统
当前位置:首页 > 教程 > 电脑教程

C#-winform编程问题使用TextBoxbuttonComboBox三个控件

时间:2015年04月02日 15:46:02    来源:魔法猪系统重装大师官网    人气:11753

一共有TextBox button ComboBox三个控件 、在Textbox里输入内容、点添加 、就把内容添加到了ComboBox中 、 内容需要写入到XML或者记事本、下次重启软件的时候添加的内容才会存在 、请问我该如何把我输入的内容添加到XML或者记事本中?

随便写了个代码,通过记录文本实现的。

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;
using System.IO;

namespace WindowsFormsApplication4
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}

private void Form1_Load(object sender, EventArgs e)
{
FileInfo DataFile;
DataFile = new FileInfo(@"c:\2.txt");
if (DataFile.Exists)
{
StreamReader sr = new StreamReader(@"c:\2.txt", Encoding.GetEncoding("GB2312"), true);
string line;
while ((line = sr.ReadLine()) != null)
{
comboBox1.Items.Add(line);

}
sr.Close();
}
else
{
DataFile.Create();

}

}

private void button1_Click(object sender, EventArgs e)
{
if (textBox1.Text != "")
{
GC.Collect();
StreamWriter writeline = new StreamWriter(@"c:\2.txt", true, Encoding.GetEncoding("GB2312"));
writeline.Write(textBox1.Text + "\r\n");
writeline.Flush();
writeline.Close();
comboBox1.Items.Add(textBox1.Text);
textBox1.Text = "";
}
else
{
MessageBox.Show("请输入内容");
}
}

 

}
}

C#-winform,编程,问题,使用,TextBoxbut
栏目:电脑教程 阅读:1000 2023/12/27
Win7教程 更多>>
U盘教程 更多>>
Win10教程 更多>>
魔法猪学院 更多>>

Copyright © 2015-2023 魔法猪 魔法猪系统重装大师

本站发布的系统仅为个人学习测试使用,请在下载后24小时内删除,不得用于任何商业用途,否则后果自负,请支持购买微软正版软件。

在线客服 查看微信 返回顶部