技术开发 频道

短信选名字操作(listbox读文本文档)


【IT168技术文档】
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms; using System.IO; using System.Web; namespace WindowsApplication19 { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void Form1_Load(object sender, EventArgs e) { StreamReader sr; string s; int len; int num; try { sr = File.OpenText("c:\\num.txt"); s = sr.ReadToEnd (); len = s.Length; num = len / 11 ; label1.Text = len.ToString(); //for (int i = 0; i < num; i++) //{ // comboBox1.Items.Add(s.Substring (i*12,11)); //} for (int i = 0; i < num; i++) { listBox1.Items.Add(s.Substring(i * 11, 11)); } sr.Close(); } catch(Exception ex) { MessageBox.Show(ex.ToString ()); } } private void button1_Click(object sender, EventArgs e) { int j = 0; for (int i = listBox1.Items.Count - 1; i >= 0; i--) { if (listBox1.GetSelected(i)) { listBox2.Items.Add(listBox1.Items[i]); listBox1.Items.RemoveAt(i); j = i; } } for (; j >= 0; j--) { if (listBox1.Items.Count > j) { listBox1.SetSelected(j, true); break; } } } private void button3_Click(object sender, EventArgs e) { int j = 0; for (int i = listBox2.Items.Count - 1; i >= 0; i--) { if (listBox2.GetSelected(i)) { listBox1.Items.Add(listBox2.Items[i]); listBox2.Items.RemoveAt(i); j = i; } } for (; j >= 0; j--) { if (listBox2.Items.Count > j) { listBox2.SetSelected(j, true); break; } } } private void button2_Click(object sender, EventArgs e) { listBox2.Items.AddRange(listBox1.Items ); listBox1.Items.Clear(); //int count; //count = listBox1.Items.Count; //for (int i = 0; i < count; i++) //{ // listBox2.Items.Add(listBox1.Items [i]); //} //listBox1.Items.Clear(); } private void listBox1_SelectedIndexChanged(object sender, EventArgs e) { //listBox2.Items.Add(listBox1.SelectedItem); } private void listBox1_MouseDoubleClick(object sender, MouseEventArgs e) { int j = 0; for (int i = listBox1.Items.Count - 1; i >= 0; i--) { if (listBox1.GetSelected(i)) { listBox2.Items.Add(listBox1.Items[i]); listBox1.Items.RemoveAt(i); j = i; } } for (; j >= 0; j--) { if (listBox1.Items.Count > j) { listBox1.SetSelected(j, true); break; } } } private void listBox2_MouseDoubleClick(object sender, MouseEventArgs e) { int j = 0; for (int i = listBox2.Items.Count - 1; i >= 0; i--) { if (listBox2.GetSelected(i)) { listBox1.Items.Add(listBox2.Items[i]); listBox2.Items.RemoveAt(i); j = i; } } for (; j >= 0; j--) { if (listBox2.Items.Count > j) { listBox2.SetSelected(j, true); break; } } } private void button4_Click(object sender, EventArgs e) { listBox1.Items.AddRange(listBox2.Items); listBox2.Items.Clear(); } private void richTextBox1_TextChanged(object sender, EventArgs e) { StringBuilder sb = new StringBuilder(); sb = new StringBuilder(richTextBox1.Text.ToString(), 100); int len; len = richTextBox1.Text.Length; int tiaoShu; tiaoShu = len / 60 + 1; for (int i = 0; i < tiaoShu; i++) { sb.Insert(i * 66, ' '+ "" + (i + 1) + "条:" + '\n'); } richTextBox2.Text = sb.ToString(); label1.Text = len.ToString(); } private void button5_Click(object sender, EventArgs e) { StreamWriter sw; string time; time = DateTime .Now .ToString (); sw = File.AppendText("c:\\content.txt"); sw.WriteLine(richTextBox2.Text+" "+time); sw.Close(); richTextBox2.Clear(); } private void button6_Click(object sender, EventArgs e) { StreamReader sr; string s; try { sr = File.OpenText("c:\\content.txt"); s = sr.ReadToEnd(); richTextBox3.Text = s.ToString (); sr.Close(); } catch (Exception ex) { MessageBox.Show("文件不存在"); } } private void button7_Click(object sender, EventArgs e) { StreamWriter sw; sw = File.AppendText("c:\\num.txt"); sw.Write(textBox1 .Text .Trim ()); sw.Close(); //Form1. textBox1.Clear(); listBox1.Items.Clear(); StreamReader sr; string s; int len; int num; try { sr = File.OpenText("c:\\num.txt"); s = sr.ReadToEnd(); len = s.Length; num = len / 11; label1.Text = len.ToString(); //for (int i = 0; i < num; i++) //{ // comboBox1.Items.Add(s.Substring (i*12,11)); //} for (int i = 0; i < num; i++) { listBox1.Items.Add(s.Substring(i * 11, 11)); } sr.Close(); } catch (Exception ex) { MessageBox.Show(ex.ToString()); } } private void button8_Click(object sender, EventArgs e) { listBox1.Items.AddRange(listBox2.Items); listBox2.Items.Clear(); } } }
0
相关文章