Hallo Community,
mal eine kleine Frage ich hab schon den Code zum asynchronen Kopieren und auch zum darstellen in der ProgressBar aber ich hab gerade eine blockade und kann einfach nicht weiter rechnen, ich will in einer einzelnen ProgressBar den fortschritt anzeigen von allen Dateien:
Mein Code
Spoiler anzeigen
In dem Bereich hängts:
Ich bekomm das einfach nicht in die Anzahl der Dateien und den Fortschritt in der ProgressBar darzustellen. Vor einer halben ewigkeit hab ich das schonmal gemacht, da hab ich aber den MaxValue bei der Progressbar so hoch gesetzt das alle Dateien 100 % zur verfügung haben nun will ich das aber so runterrechnen das alles nur auf die 100 % sind, falls ihr es nicht verstanden habt tuts mir leid ich versteh ni wie ich es ausdrücken soll
Spoiler eingefügt. ~Trade
mal eine kleine Frage ich hab schon den Code zum asynchronen Kopieren und auch zum darstellen in der ProgressBar aber ich hab gerade eine blockade und kann einfach nicht weiter rechnen, ich will in einer einzelnen ProgressBar den fortschritt anzeigen von allen Dateien:
Mein Code
C#-Quellcode
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Data;
- using System.Drawing;
- using System.Linq;
- using System.Runtime.InteropServices;
- using System.Text;
- using System.Threading.Tasks;
- using System.Windows.Forms;
- namespace Camera_Image_Saver
- {
- public partial class frmCopying : Form
- {
- public frmCopying()
- {
- InitializeComponent();
- }
- List<Copyer> copy = new List<Copyer>();
- int now = 0;
- int cs = 0;
- string CopyDir;
- bool hierarchy = false;
- string DestDir;
- public void AnalyzeDir(string dir)
- {
- foreach (var files in System.IO.Directory.GetFiles(dir))
- {
- cs++;
- string Destination;
- if (hierarchy)
- {
- Destination = System.IO.Path.Combine(DestDir, OnlyCDir(dir), System.IO.Path.GetFileName(files));
- }else
- {
- Destination = System.IO.Path.Combine(DestDir, System.IO.Path.GetFileName(files));
- }
- CIN(System.IO.Path.GetDirectoryName(Destination));
- if (System.IO.File.Exists(Destination))
- System.IO.File.Delete(Destination);
- Copyer c = new Copyer(files, Destination);
- copy.Add(c);
- }
- foreach (var dir2 in System.IO.Directory.GetDirectories(dir))
- { try
- {
- AnalyzeDir(dir2);
- }
- catch { }
- }
- }
- public void CIN(string dir)
- {
- if (!System.IO.Directory.Exists(dir))
- System.IO.Directory.CreateDirectory(dir);
- }
- List<Copyer> finishedFiles;
- bool paused = false;
- public bool Pause
- {
- get
- {
- return paused;
- }
- set
- {
- paused = value;
- if(value == false)
- {
- pgProgress.State = AeroSuite.Controls.ProgressBarState.Normal;
- CopyNext();
- }
- }
- }
- public void PrepareSettings()
- {
- finishedFiles = new List<Copyer>();
- copy = new List<Copyer>();
- this.Show();
- DisableCloseButton(this.Handle);
- }
- private void SetProgress(int value)
- {
- if (value == 0)
- return;
- pgProgress.Value = value;
- switch (value.ToString().Length)
- {
- case 1:
- lblPercentage.Text = value + " %";
- break;
- case 2:
- lblPercentage.Text = value + " %";
- break;
- case 3:
- lblPercentage.Text = value + "%";
- break;
- }
- lblPercentage.Refresh();
- Refresh();
- }
- public void PrepareStart()
- {
- SetLabelName(System.IO.Path.GetFileName(copy[0].SourceFilePath));
- pgProgress.State = AeroSuite.Controls.ProgressBarState.Normal;
- SetProgress(0);
- }
- public void SetLabelName(string str)
- {
- lblFile.Text = CopierStart.Replace("%file%", str);
- }
- public string OnlyCDir(string subdir)
- {
- string arx = subdir.Replace(CopyDir, "");
- if (arx.StartsWith("\\"))
- arx = arx.Remove(0, 1
- );
- return arx;
- }
- public void OpenCopy(string Directory, string DestDir, bool UseHierarchy = false)
- {
- CopyDir = Directory;
- this.DestDir = DestDir;
- PrepareSettings();
- //Analyzes Files
- AnalyzeDir(Directory);
- if (copy.Count == 0)
- FinishCopying();
- }
- private void FinishCopying()
- {
- lblPercentage.Text = "Fertig";
- MessageBox.Show("Files successfully copied from " + gsfs + CopyDir + gsfs + " to " + gsfs + DestDir + gsfs, "Camera Image Saver", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
- this.Close();
- }
- string curFile;
- public void CopyNext()
- {
- if(paused)
- {
- pgProgress.State = AeroSuite.Controls.ProgressBarState.Paused;
- lblFile.Text = "paused";
- btnPC.Enabled = true;
- btnPC.Text = "Continue";
- Refresh();
- return;
- }
- now++;
- Copyer c = copy[now];
- SetLabelName(System.IO.Path.GetFileName(c.SourceFilePath));
- curFile = System.IO.Path.GetFileName(c.SourceFilePath);
- c.OnProgressChanged += C_OnProgressChanged;
- c.OnComplete += C_OnComplete;
- Refresh();
- c.Copy();
- }
- private void C_OnComplete()
- {
- if (now == copy.Count - 1)
- {
- FinishCopying();
- return;
- }
- finishedFiles.Add(copy[now]);
- CopyNext();
- }
- private void C_OnProgressChanged(double Persentage, ref bool Cancel)
- {
- //int validate = cs /
- int valueToAdd = (int)Math.Round(Persentage);
- int valval = cs / valueToAdd;
- if (valval + pgProgress.Value >= pgProgress.Maximum)
- {
- pgProgress.Value = pgProgress.Maximum;
- lblPercentage.Text = "100%";
- return;
- }
- AddProgress(valval);
- Refresh();
- }
- public void AddProgress(int val)
- {
- SetProgress(pgProgress.Value + val);
- }
- [DllImport("user32.dll")]
- private static extern IntPtr RemoveMenu(IntPtr hMenu, UInt32 uPosition, UInt32 uFlags);
- [DllImport("user32.dll")]
- private static extern IntPtr GetSystemMenu(IntPtr hWnd, bool bRevert);
- [DllImport("user32.dll")]
- private static extern int GetMenuItemCount(IntPtr hMenu);
- [DllImport("user32.dll")]
- private static extern bool DrawMenuBar(IntPtr hwnd);
- private void DisableCloseButton(IntPtr hwnd)
- {
- IntPtr hMenu = GetSystemMenu(hwnd, false);
- int menuItemCount = GetMenuItemCount(hMenu);
- RemoveMenu(hMenu, (uint)(menuItemCount - 1), 0x2 | 0x400);
- DrawMenuBar(hwnd);
- }
- private void EnableCloseButton(IntPtr hwnd)
- {
- GetSystemMenu(hwnd, true);
- DrawMenuBar(hwnd);
- }
- public const string CopierStart = "Copy File \"%file%\"";
- public const char gsfs = '"';
- private void frmCopying_Load(object sender, EventArgs e)
- {
- }
- private void btnPC_Click(object sender, EventArgs e)
- {
- switch(btnPC.Text.ToLower())
- {
- default:
- case "pause":
- Pause = true;
- btnPC.Enabled = false;
- break;
- case "continue":
- Pause = false;
- btnPC.Enabled = true;
- btnPC.Text = "Pause";
- break;
- case "start":
- captionLabel.Text = "Please wait, Files copying";
- PrepareStart();
- Refresh();
- //Start Copy
- btnPC.Text = "Pause";
- now = -1;
- btnPC.Visible = false;
- CopyNext();
- break;
- }
- }
- }
- }
In dem Bereich hängts:
C#-Quellcode
- private void C_OnProgressChanged(double Persentage, ref bool Cancel)
- {
- int valueToAdd = (int)Math.Round(Persentage);
- int valval = cs / valueToAdd;
- if (valval + pgProgress.Value >= pgProgress.Maximum)
- {
- pgProgress.Value = pgProgress.Maximum;
- lblPercentage.Text = "100%";
- return;
- }
- AddProgress(valval);
- Refresh();
- }
Ich bekomm das einfach nicht in die Anzahl der Dateien und den Fortschritt in der ProgressBar darzustellen. Vor einer halben ewigkeit hab ich das schonmal gemacht, da hab ich aber den MaxValue bei der Progressbar so hoch gesetzt das alle Dateien 100 % zur verfügung haben nun will ich das aber so runterrechnen das alles nur auf die 100 % sind, falls ihr es nicht verstanden habt tuts mir leid ich versteh ni wie ich es ausdrücken soll
Spoiler eingefügt. ~Trade
Dieser Beitrag wurde bereits 1 mal editiert, zuletzt von „Trade“ ()