| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1922 人关注过本帖
标题:求助(C#控件使用)
只看楼主 加入收藏
细雨斜飞
Rank: 1
等 级:新手上路
帖 子:42
专家分:0
注 册:2008-5-4
收藏
得分:0 
using System;
using System.Collections.Generic;
using
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using
using System.Globalization;
using System.Threading;

namespace Sort
{
    public partial class Form1 : Form
    {
        public static void Sort(char[] arr, int n)
        {
            string strlin;
            
            strlin=Convert.ToString(arr);

            for (int i = 0; i < strlin.Length; i++)
            {
                for (int j = i + 1; j < strlin.Length; j++)
                {
                    if ((Convert.ToString(arr[i]), Convert.ToString(arr[i + 1])) > 0)
                    {
                        char temp = arr[i];
                        arr[i] = arr[i + 1];
                        arr[i + 1] = temp;
                    }
                }
            }


        }
   


        public Form1()
        {
            //int k;
            InitializeComponent();
            //static int k;
        }
        private void button1_Click(object sender, EventArgs e)
        {

            OpenFileDialog file = new OpenFileDialog();
            file.InitialDirectory = "d:\text";
            file.Filter = "txt files (*.txt)|*.txt|All files (*.*)|*.*";
            foreach (string Name in file.FileNames)
            {
                file.FileName = Name;
            }


            if (file.ShowDialog() == DialogResult.OK)
            {
                sr = new (file.FileName);
                string str = sr.ReadToEnd();
                int m = str.Length;
                // k = m;
                char[] array = new char[m];
                for (int j = 0; j < m; j++)
                {
                    array[j] = str[j];
                }

                for (int i = 1; i < str.Length; i++)
                {
                    listBox1.Items.Add(array[i]);
                }


                Sort(array, m);
                //--------------------------------------------------------------------------------------------------------------------------------------------
                using (StreamWriter sw = new StreamWriter("MyTest.txt"))
                {
                    for (int p = 0; p < m; p++)
                        sw.WriteLine(array[p]);
                    sw.Close();
                }
            }

        }
        //---------------------------------------------------------------------------------------------------------------------------------------------
        private void button2_Click(object sender, EventArgs e)
        {
            string FILE_NAME = "MyTest.txt";
            OpenFileDialog file = new OpenFileDialog();
            using (StreamReader sr = File.OpenText(FILE_NAME))
            {

                st = new (FILE_NAME);
                string str = st.ReadToEnd();
                int m = str.Length;
                // k = m;
                char[] array = new char[m];
                for (int j = 0; j < m; j++)
                {
                    array[j] = str[j];
                }

                for (int i = 1; i < str.Length; i++)
                {
                    listBox2.Items.Add(array[i]);
                }
            }
        }
    }
}
问题已经决绝  谢谢大家支持 谢谢
2008-08-02 16:52
快速回复:求助(C#控件使用)
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.015383 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved