如何使用此文本文件中的进度条来位转换代码? [英] how can i use progress bar in this text file to bits conertaing code?

查看:76
本文介绍了如何使用此文本文件中的进度条来位转换代码?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何使用此文本文件中的进度条来显示包含代码的位?

how can i use progress bar in this text file to bits containing code?

string totalbits = "";

private void button1_Click(object sender, EventArgs e)
{
    OpenFileDialog ofd = new OpenFileDialog();
    ofd.Filter = "Text Files(.txt)|*.txt";
    ofd.ShowDialog();
    string s1 = ofd.FileName;
    string s2 = System.IO.File.ReadAllText(s1);          
    ASCIIEncoding asc = new ASCIIEncoding();
    //byte array which hold int values of alphabet
    byte[] b = asc.GetBytes(s2);
    foreach (int item in b)
    {         
        int item1 = item;
        string binarystring = "";
        while (item1 > 0)
        {
            //binary conersion of text byte
            int binary = item1 % 2;
            binarystring = binarystring + binary.ToString();
            item1 = item1 / 2;
        }
        char[] binarynumber = binarystring.ToCharArray();
        Array.Reverse(binarynumber);
        binarystring = new string(binarynumber);
        totalbits = totalbits + binarystring;              
        }
    }
}

推荐答案

将以foreach开头的代码放入BackgroundWorker线程中,并将线程报告进度放在适当的位置.
Put the code starting with foreach into a BackgroundWorker thread, and have the thread report progress in the appropriate place.


这篇关于如何使用此文本文件中的进度条来位转换代码?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆