pathname parameter which is created by button1_Click must be passed to button2_Click. How can I pass? (I know this is basic problem but I don't know.
===================================
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;
using System.Drawing.Imaging;
namespace WindowsFormsApplication3
{
public partial class Form1 : Form
{
string pathname;
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
DialogResult result = folderBrowserDialog1.ShowDialog();
string pathname = @folderBrowserDialog1.SelectedPath;
int foldercount = Directory.GetDirectories(@pathname).Length;
int filecount = Directory.GetFiles(@pathname, "*.*", SearchOption.AllDirectories).Length;
int JPGcount = Directory.GetFiles(@pathname, "*.JPG", SearchOption.AllDirectories).Length;
label2.Text = pathname;
label4.Text = foldercount.ToString();
label6.Text = JPGcount.ToString();
label8.Text = (filecount - JPGcount).ToString();
}
private void button2_Click(object sender, EventArgs e)
{
FileInfo[] files = new DirectoryInfo(pathname).GetFiles("*.JPG");
==========================================
Loading
Ali GPosted Sep 30, 2013, 3:44 PM
VulpesPosted Sep 30, 2013, 3:16 PM
If you take this line:
string pathname = @folderBrowserDialog1.SelectedPath;
and remove 'string':
pathname = @folderBrowserDialog1.SelectedPath;
then that will set the value of the field, rather than a local variable, and it can now be accessed from button2_Click.
If you want to programatically click button2 rather than waiting for the user to do it, then you can do so by adding this line at the end of button1_Click:
button2.PerformClick();