| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1922 人关注过本帖
标题:求助(C#控件使用)
取消只看楼主 加入收藏
细雨斜飞
Rank: 1
等 级:新手上路
帖 子:42
专家分:0
注 册:2008-5-4
收藏
 问题点数:0 回复次数:6 
求助(C#控件使用)
老师布置一任务    要求是用listbox  button 空间做一个sort排序   
                  具体内容 "
                  1.添加两个button 两个listbox  
                  重新命名button为 Read 和Sort,并且Read添加一个openfiledialog 控件 ,使其可以调用本地磁盘下的text文件,
                  2.将text文件显示在listBox1里,通过普通的排序(比如选择,冒泡,插入等等),将listBox1的内容重新排序,
                  点击Sort,排序好的内容在Listbox2里显示.

小弟是菜鸟,希望大虾能过帮个小忙 ,在线等 谢谢了啊!!!

[[it] 本帖最后由 细雨斜飞 于 2008-7-30 17:46 编辑 [/it]]

错误提示.jpeg (235.49 KB)
图片附件: 游客没有浏览图片的权限,请 登录注册
搜索更多相关主题的帖子: 控件 
2008-07-30 17:25
细雨斜飞
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

namespace Sort
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
        private void button1_Click(object sender, System.EventArgs e)
        {
            OpenFileDialog dlg = new OpenFileDialog();
            dlg.Multiselect = true;

            if (dlg.ShowDialog() == DialogResult.OK)
            {
                foreach (string s in dlg.FileNames)
                {
                    this.listBox1.Items.Add(s);
                }
            }
        }
        public void Sort(char[] Read)
        {
            int k = Read.Length;
            for (int i = 1; i < k; i++)
            {
                for (int j = 0; j < k - i; j++)
                {
                    if (Read[j] > Read[j + 1])
                    {
                        char temp;
                        temp = Read[j];
                        Read[j] = Read[j + 1];
                        Read[j + 1] = temp;
                    }
                }
            }
            foreach (int j in Read)
            {
                Console.Write(j + " ");
            }
            Console.WriteLine("\n");
        }

        private void listBox2_SelectedIndexChanged(object sender, EventArgs e)
        {

        }

        private void button2_Click(object sender, EventArgs e)
        {
            object str = listBox1.Items;
            string str2 = (string)str;
            int m = str2.Length;
            char[] c1 = new char[m];
            char c;
            c = Convert.ToChar(str2);
            for (int i = 0; i < m; i++)
            {
                c1[i] = str2[i];
            }
            Sort(c1);
        }





    }

}
这是  “ 源 ”  不知道怎么回事 运行 出错
2008-07-30 17:32
细雨斜飞
Rank: 1
等 级:新手上路
帖 子:42
专家分:0
注 册:2008-5-4
收藏
得分:0 
好了 船上去了 是那个错误提示 程序可以编译运行
2008-07-30 17:47
细雨斜飞
Rank: 1
等 级:新手上路
帖 子:42
专家分:0
注 册:2008-5-4
收藏
得分:0 
谢谢啊~~~~
2008-07-30 20:20
细雨斜飞
Rank: 1
等 级:新手上路
帖 子:42
专家分:0
注 册:2008-5-4
收藏
得分:0 
问题还是没有解决啊!!! 问个菜鸟问题啊 用Button的事件  openfiledialog ,打开了一个窗口,并且可以选中一个文本文件,可是却怎么也不能把这个文本文件的内容添加到listBox里去,那么 listBox 到底能不能接受并显示文本的内容?不能的话 我应该选用那种控件呢?
2008-08-01 10:07
细雨斜飞
Rank: 1
等 级:新手上路
帖 子:42
专家分:0
注 册:2008-5-4
收藏
得分:0 
读取text文本文档,想把文档里面的内容都读进去,
                foreach (string s in dlg.FileNames)
                {
                    this.listBox1.Items.Add(s);
                }
这个只是把Items度进去了 ,不是我想要的啊~~~
2008-08-01 16:39
细雨斜飞
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.054081 second(s), 9 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved