Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Data;
- using System.Drawing;
- using System.Linq;
- using System.Text;
- using System.Threading;
- using System.Threading.Tasks;
- using System.Windows.Forms;
- using System.IO;
- using System.Runtime.InteropServices;
- namespace MyComponent
- {
- //public static class ModifyProgressBarColor
- //{
- // [DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = false)]
- // static extern IntPtr SendMessage(IntPtr hWnd, uint Msg, IntPtr w, IntPtr l);
- // public static void SetState(this ProgressBar pBar, int state)
- // {
- // SendMessage(pBar.Handle, 1040, (IntPtr)state, IntPtr.Zero);
- // }
- //}
- public partial class Form1 : Form
- {
- public Form1()
- {
- InitializeComponent();
- numberComponent1.GroupTitle = "Copy file";
- numberComponent1.sendMsg = receiveMsg;
- // progressBar1.SetState(2);
- }
- public void updateProgressBar(int cislo)
- {
- progressBar1.Value = cislo;
- }
- // ModifyProgressBarColor.SetState(progressBar1, 2);
- FileOperation.SendMsgCnt s = null;
- // public delegate void SetValueIntCallBack(int v);
- public void ZapisData(int cislo)
- {
- if (progressBar1.InvokeRequired)
- {
- s = updateProgressBar;
- this.Invoke(s, new object[] { cislo });
- }
- else
- progressBar1.Value = cislo;
- }
- // public FileOperation.SendMsgCnt s = null;
- public SendMsgStop sendMsgStop = null;
- // public delegate void ThreadStart();
- private void receiveMsg()
- {
- try
- {
- // string z = numberComponent1.Zdroj;
- // string c = numberComponent1.Cil;
- }
- catch (Exception)
- {
- MessageBox.Show("01", "Chyba");
- }
- }
- private void button1_Click(object sender, EventArgs e)
- {
- try
- {
- string z = numberComponent1.Zdroj;
- string c = numberComponent1.Cil;
- FileOperation operace = new FileOperation(z, c);
- // s(30);
- // DelegateCopy objektDelegata = new DelegateCopy(operace.Copy);
- System.Threading.Thread t = new System.Threading.Thread(operace.Copy);
- t.Start();
- //progressBar1.Value = FileOperation.updateProgressBar(5);
- }
- catch (NezadanaCestaExpection ex)
- {
- MessageBox.Show(ex.Message, "Chyba");
- }
- catch (NezadanyCilExpection ex)
- {
- MessageBox.Show(ex.Message, "Chyba");
- }
- catch (Exception)
- {
- // MessageBox.Show("{0}\n{1}", "Během zpracování souboru došlo k chybě.", e.Message);
- }
- }
- private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e)
- {
- try
- {
- string z = numberComponent1.Zdroj;
- string c = numberComponent1.Cil;
- FileOperation operace = new FileOperation(z, c);
- //operace.Copy(progressBar1);
- for (int i = 0; i <= 100; i++)
- {
- if (backgroundWorker1.CancellationPending)
- {
- File.Delete(c);
- e.Cancel = true;
- MessageBox.Show("Kopírování bylo přerušeno!");
- break;
- }
- else
- {
- kopirovani();
- // int pocetZkopirovanych = FileOperation.CharCount(operace.FILENAMEIN) / FileOperation.CharCount(operace.FILENAMEIN);
- backgroundWorker1.ReportProgress(i);
- }
- }
- operace.Copy();
- }
- catch (Exception ex) { MessageBox.Show(ex.Message); e.Cancel = true; };
- }
- // FileOperation.Char
- private void backgroundWorker1_ProgressChanged(object sender, ProgressChangedEventArgs e)
- {
- progressBar1.Value = e.ProgressPercentage;
- lbStavProcent.Text = e.ProgressPercentage.ToString() + " %";
- }
- private void backgroundWorker1_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
- {
- if (e.Cancelled)
- {
- progressBar1.Value = 0;
- lbStavProcent.Text = "";
- }
- else
- {
- MessageBox.Show("Kopírování úspěšně dokončeno");
- lbStavProcent.Text = "";
- progressBar1.Value = 0;
- }
- }
- private void kopirovani()
- {
- Thread.Sleep(10);
- }
- private void button1_Click_1(object sender, EventArgs e)
- {
- backgroundWorker1.RunWorkerAsync();
- }
- private void button2_Click(object sender, EventArgs e)
- {
- backgroundWorker1.CancelAsync();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement