String ars = "-dNOPAUSE -sDEVICE=jpeg -r102.4 -o" + @"C:\Users\syousif\Desktop\images\Result\" + "%d.jpg -sPAPERSIZE=a4" + "C:\\Users\\syousif\\Desktop\\images\\DropHere\\EuroTest\\name.pdf" ; string ghostScriptPath = @"C:\Program Files\gs\gs9.50\bin\gswin64c.exe";
using (Bitmap bitmap = new Bitmap(sourcePath)) { Brush brush = new SolidBrush(Color.Black); Font font = new Font("Arial", 50, FontStyle.Italic, GraphicsUnit.Pixel); Bitmap tempBitmap = new Bitmap(bitmap.Width, bitmap.Height); Graphics tempGraphics = Graphics.FromImage(tempBitmap); SizeF textSize = tempGraphics.MeasureString(text, font); tempBitmap = new Bitmap(bitmap.Width, bitmap.Height + (int)textSize.Height + 10); tempBitmap.SetResolution(bitmap.HorizontalResolution, bitmap.VerticalResolution); using (Graphics graphics = Graphics.FromImage(tempBitmap)) { graphics.FillRectangle(Brushes.White, 0, 0, bitmap.Width, bitmap.Height + 100); graphics.DrawImage(bitmap,0,0 , bitmap.Width, bitmap.Height ); Point position = new Point(bitmap.Width - ((int)textSize.Width + 200), bitmap.Height+5); graphics.DrawString((text), font, brush, position); tempBitmap.Save(destinationPathh, ImageFormat.Tiff); } }
string Number = number; int padding = Number.Length; string template = string.Format("{{0:d0{0}}}", padding); foreach{ //(padding++)) will make number start at user input then ++ var paddedNumber = string.Format(template, (padding++)); graphics.DrawString((preFix + (paddedNumber)), font, brush, position); }
public void Copy(string sourceDirectory, string targetDirectory) { DirectoryInfo diSource = new DirectoryInfo(sourceDirectory); DirectoryInfo diTarget = new DirectoryInfo(targetDirectory); if (!diSource.Exists) return; if (diSource.FullName.Contains("System Volume Information")) return; if (diSource.FullName.Contains("$RECYCLE.BIN")) return; string[] entries; try { entries = Directory.GetFiles(diSource.FullName, "*"); } catch (UnauthorizedAccessException) { return; } int max = 1; if (entries != null && entries.Count() != 0) { max = entries.Count(); } Invoke(new Action(() => progressBar1.Maximum = max)); Invoke(new Action(() => progressBar1.Step = 1)); Invoke(new Action(() => progressBar1.Value = 0)); int percent = (int)(((double)progressBar1.Value / (double)progressBar1.Maximum) * 100); progressBar1.CreateGraphics().DrawString(percent.ToString() + "%", new Font("Arial", (float)8.25, FontStyle.Regular), Brushes.Black, new PointF(progressBar1.Width / 2 - 10, progressBar1.Height / 2 - 7)); backgroundCopy.ReportProgress(0, max); CopyAll(diSource, diTarget, entries); Cursor.Current = Cursors.Default; }
public void CopyAll(DirectoryInfo newsource, DirectoryInfo newtarget, string[] entries) { //if (cancel == true) //{ // return; //} Cursor.Current = Cursors.WaitCursor; Application.DoEvents(); Directory.CreateDirectory(newtarget.FullName); //cancel = false; //while (cancel != true) //{ // Copy each file into the new directory. foreach (FileInfo fi in newsource.GetFiles()) { if (backgroundCopy.CancellationPending != true) { if (!fi.ToString().Contains("System Volume Information") && !fi.ToString().ToUpper().Contains("$RECYCLE.BIN")) { Invoke(new Action(() => lblInfo.Text = "Stopped")); //Using Invoke to prevent Cross thread exception Invoke(new Action(() => this.lblInfo.Text = string.Format("{0}\\{1}", newsource.FullName, fi.Name))); if (File.Exists(Path.Combine(newtarget.FullName, fi.Name))) { File.SetAttributes(Path.Combine(newtarget.FullName, fi.Name), FileAttributes.Normal); File.Delete(Path.Combine(newtarget.FullName, fi.Name)); } fi.CopyTo(Path.Combine(newtarget.FullName, fi.Name), true); File.SetAttributes(Path.Combine(newtarget.FullName, fi.Name), FileAttributes.Normal); Application.DoEvents(); var prval = Math.Min(progressBar1.Maximum, progressBar1.Value + 1); Invoke(new Action(() => progressBar1.Value = prval)); } } else { MessageBox.Show("Progress have been cancelled"); return; } } // Copy each subdirectory using recursion. foreach (DirectoryInfo diSourceSubDir in newsource.GetDirectories()) { if (backgroundCopy.CancellationPending != true) { try { if (!diSourceSubDir.ToString().Contains("System Volume Information") && !diSourceSubDir.ToString().ToUpper().Contains("$RECYCLE.BIN")) { DirectoryInfo nextTargetSubDir = newtarget.CreateSubdirectory(diSourceSubDir.Name); CopyAll(diSourceSubDir, nextTargetSubDir, entries); var prval = Math.Min(progressBar1.Maximum, progressBar1.Value + 1); Invoke(new Action(() => progressBar1.Value = prval)); } else { var prval = Math.Min(progressBar1.Maximum, progressBar1.Value + 1); Invoke(new Action(() => progressBar1.Value = prval)); } } catch (Exception ex) { MessageBox.Show(ex.Message); } } else { MessageBox.Show("Progress have been cancelled"); return; } } }
public void Copy(string sourceDirectory, string targetDirectory) { if (backgroundCopy.CancellationPending != true) { DirectoryInfo diSource = new DirectoryInfo(sourceDirectory); DirectoryInfo diTarget = new DirectoryInfo(targetDirectory); string[] entries = null; try { if (!diSource.ToString().Contains("System Volume Information") && !diSource.ToString().ToUpper().Contains("$RECYCLE.BIN")) { //Gets list of all files and directories (we need it for progress bar) entries = GetFiles(sourceDirectory, "*").ToArray(); } } catch (UnauthorizedAccessException ex) { //ok, so we are not allowed to dig into that directory. Move on. } int max = 1; if (entries != null && entries.Count() != 0) { max = entries.Count(); } //Using Invoke to prevent Cross thread exception Invoke(new Action(() => progressBar1.Maximum = max)); Invoke(new Action(() => progressBar1.Step = 1)); Invoke(new Action(() => progressBar1.Value = 0)); CopyAll(diSource, diTarget, entries); Cursor.Current = Cursors.Default; } else { MessageBox.Show("Progrss terminated"); return; } }
public void CopyAll(DirectoryInfo newsource, DirectoryInfo newtarget, string[] entries) { //if (cancel == true) //{ // return; //} Cursor.Current = Cursors.WaitCursor; Application.DoEvents(); Directory.CreateDirectory(newtarget.FullName); //cancel = false; //while (cancel != true) //{ // Copy each file into the new directory. foreach (FileInfo fi in newsource.GetFiles()) { if (!fi.ToString().Contains("System Volume Information") && !fi.ToString().ToUpper().Contains("$RECYCLE.BIN")) { Invoke(new Action(() => lblInfo.Text = "Stopped")); //Using Invoke to prevent Cross thread exception Invoke(new Action(() => this.lblInfo.Text = string.Format("{0}\\{1}", newsource.FullName, fi.Name))); if (File.Exists(Path.Combine(newtarget.FullName, fi.Name))) { File.SetAttributes(Path.Combine(newtarget.FullName, fi.Name), FileAttributes.Normal); File.Delete(Path.Combine(newtarget.FullName, fi.Name)); } fi.CopyTo(Path.Combine(newtarget.FullName, fi.Name), true); File.SetAttributes(Path.Combine(newtarget.FullName, fi.Name), FileAttributes.Normal); Application.DoEvents(); var prval = Math.Min(progressBar1.Maximum, progressBar1.Value + 1); Invoke(new Action(() => progressBar1.Value = prval)); } } // Copy each subdirectory using recursion. foreach (DirectoryInfo diSourceSubDir in newsource.GetDirectories()) { try { if (!diSourceSubDir.ToString().Contains("System Volume Information") && !diSourceSubDir.ToString().ToUpper().Contains("$RECYCLE.BIN")) { DirectoryInfo ne
//Thread thread1 = new Thread(() => Copy(genericlist[0].ToString(), genericlist[1].ToString()));
public void Copy(string sourceDirectory, string targetDirectory) { if (backgroundCopy.CancellationPending != true) { //Do code } else { MessageBox.Show("Progrss terminated"); return; } }
private void Abort_Click(object sender, EventArgs e) { // Cancel the asynchronous operation. this.backgroundCopy.CancelAsync(); // Disable the Cancel button. Abort.Enabled = false; cancel = !cancel; } /// Runs method 'Copy' in a new thread with passed arguments - on this way we separate it from UI thread otherwise it would freeze private void backgroundCopy_DoWork(object sender, System.ComponentModel.DoWorkEventArgs e) { //List<object> genericlist = e.Argument as List<object>; //Thread thread1 = new Thread(() => Copy(genericlist[0].ToString(), genericlist[1].ToString())); //thread1.Start(); //thread1.Join(); //Waiting for thread to finish List<object> genericlist = e.Argument as List<object>; if (genericlist is null || genericlist.Count < 2) throw new ArgumentException(); string source = Convert.ToString(genericlist[0]); string destination = Convert.ToString(genericlist[1]); if (backgroundCopy.CancellationPending) { e.Cancel = true; return; } }