نمایش نتایج 1 تا 40 از 534

نام تاپیک: 1001 نکته در سی شارپ

Threaded View

پست قبلی پست قبلی   پست بعدی پست بعدی
  1. #8

    Cool بافر .: نشان دادن مقدار کپی شدن یه فایل :.

    با استفاده از بافر می توان روی مقدار کپی شدن یه فایل مدیریت کرد و مانور داد

    موارد مورد نیاز برای این مثال:

    1. یک Progress Bar
    2. یک Button

    این کد متد اصلی ما می باشد


    public void CopyFile(string FileSource, string FileDestination)
    {
    int NumRead;
    long FileLength;
    System.IO.FileStream From = new System.IO.FileStream(FileSource, System.IO.FileMode.Open);
    System.IO.FileStream To = new System.IO.FileStream(FileDestination, System.IO.FileMode.CreateNew);
    byte[] buffer = new byte[1024];
    FileLength = From.Length;
    progressBar1.Minimum = 0;
    progressBar1.Maximum = (int)FileLength;
    while (FileLength>0)
    {
    System.IO.BinaryReader Reader = new System.IO.BinaryReader(From);
    NumRead = Reader.Read(buffer, 0, 1024);
    FileLength = FileLength - NumRead;
    System.IO.BinaryWriter Writer = new System.IO.BinaryWriter(To);
    Writer.Write(buffer, 0, NumRead);
    progressBar1.Value = progressBar1.Value + NumRead;
    Writer.Flush();
    }
    From.Close();
    To.Close();
    if (progressBar1.Value>99)
    {
    progressBar1.Value = 0;
    MessageBox.Show("Copy Finished successfuly");
    }
    }


    از این کد برای فراخوانی متد اصلی در رویداد Button استفاده می شود


    private void button1_Click(object sender, EventArgs e)
    {
    openFileDialog1.ShowDialog();
    folderBrowserDialog1.ShowDialog();
    System.IO.FileInfo d=new System.IO.FileInfo(openFileDialog1.FileName.ToStri ng());
    CopyFile(openFileDialog1.FileName.ToString(), folderBrowserDialog1.SelectedPath.ToString()+"\\"+ d.Name.ToString());
    }
    آخرین ویرایش به وسیله Mahmoud.Afrad : چهارشنبه 17 تیر 1394 در 13:54 عصر

برچسب های این تاپیک

قوانین ایجاد تاپیک در تالار

  • شما نمی توانید تاپیک جدید ایجاد کنید
  • شما نمی توانید به تاپیک ها پاسخ دهید
  • شما نمی توانید ضمیمه ارسال کنید
  • شما نمی توانید پاسخ هایتان را ویرایش کنید
  •