I will clean up the code after I get some more functionality working. Currently stuck at getting the value of destFile2 over to form2.
Here is my code for form1 and below that for form2.
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;
namespace Project21
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
Form2 frm2 = new Form2(this); //pass reference to this form in constructor
}
public string TextBoxText //read only property to access textbox text
{
get { return textBox1.Text; }
}
FolderBrowserDialog fbd = new FolderBrowserDialog();
string targetPath = @"C:\temp";
string targetPath2 = @"C:\FileIn";
string renamePath = @"C:\FileOut";
public void button1_Click(object sender, EventArgs e)
{
fbd.Description = "Select folder";
fbd.RootFolder = Environment.SpecialFolder.Desktop;
if (fbd.ShowDialog() == System.Windows.Forms.DialogResult.OK)
MessageBox.Show(fbd.SelectedPath);
string[] files = System.IO.Directory.GetFiles(fbd.SelectedPath);
progressBar1.Minimum = 0;
progressBar1.Maximum = files.Length;
progressBar1.Step = 1;
// Copy the files and overwrite destination files if they already exist.
foreach (string file in files)
{
// Use static Path methods to extract only the file name from the path.
string fileName = System.IO.Path.GetFileName(file);
string destFile = System.IO.Path.Combine(targetPath, fileName);
System.IO.File.Copy(file, destFile, true);
progressBar1.PerformStep();
}
}
private void button2_Click(object sender, EventArgs e)
{
if(ofd.ShowDialog() == System.Windows.Forms.DialogResult.OK)
MessageBox.Show(ofd.FileName);
string[] files = System.IO.Directory.GetFiles(targetPath);
//move file to FileIn folder on desktop
progressBar2.Minimum = 0;
progressBar2.Maximum = files.Length;
progressBar2.Step = 1;
string destFile2 = System.IO.Path.GetFileName(ofd.FileName);
File.Copy(ofd.FileName, targetPath2 + "\\" + destFile2);
progressBar2.PerformStep();
InitializeComponent();
this.Hide();
Form2 frm2 = new Form2(this);
frm2.ShowDialog();
frm2.MdiParent = this;}
}
}
form2
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace Project21
{
public partial class Form2 : Form
{
Form1 frm1;
private string p;
public Form2(Form1 callingForm)
{
InitializeComponent();
frm1 = callingForm; //store local reference to Form1
}
public string TextBoxText //read only property to access textbox text
{
get { return textBox1.Text; }//testing to see if the I can pass value from from1 to here - not working
}
private void button1_Click(object sender, EventArgs e)
{
MessageBox.Show("Test;more todo here");//would like to be able to
}
}
}

New Topic/Question
Reply




MultiQuote






|