کلاس فرم زیر کلاس کامل فرمی که من میخوام تو فرم دوم از نمونش استفاده کنم
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
// Showing folderBrowserDialog for getting specific directory
DialogResult result = folderBrowserDialog1.ShowDialog();
if (result == DialogResult.OK)
{
textBox1.Text = folderBrowserDialog1.SelectedPath;
}
}
private void button3_Click(object sender, EventArgs e)
{
Application.Exit();
}
public string[] fileExtensions = null;
private void button2_Click(object sender, EventArgs e)
{
VertifyRequests();
}
public void VertifyRequests()
{
// Error for empty textbox
if (textBox1.Text == "")
{
MessageBox.Show("لطفا مسیر مورد نظر خود را برای جست و جو انتخاب کنید"
, "خطای انتخاب مسیر"
, MessageBoxButtons.OK
, MessageBoxIcon.Error);
}
// Error for invalide value for numericUp and Down
if (numericUpDown1.Value > 3000000 || numericUpDown2.Value < 10)
{
MessageBox.Show("سایز فایل انتخابی باید بین 10 تا3000000 کیلوبایت باشد"
, "ارور سایز فایل"
, MessageBoxButtons.OK
, MessageBoxIcon.Error);
}
if (System.IO.Directory.Exists(textBox1.Text))
{
RecognizeExtensionsArguments();
}
}
private void RecognizeExtensionsArguments()
{
// Getting DirectoryInfo from textbox Which Selected in folderBrowserDialog
System.IO.DirectoryInfo targetDirectory = new System.IO.DirectoryInfo(textBox1.Text);
if (fileExtensions != null)
{
checkBox1.Checked = false;
checkBox2.Checked = false;
checkBox3.Checked = false;
checkBox4.Checked = false;
}
else
{
// if checkBoxes was checked then send that file extensions arguments to GetFileTypeName
// Method
if (checkBox1.Checked)
{
fileExtensions = new string[] { ".mp3" };
targetDirectory.GetFileTypeName(minNumeric: numericUpDown2.Value
, maxNumeric: numericUpDown1.Value, extensions: fileExtensions);
}
if (checkBox2.Checked)
{
fileExtensions = new string[] { ".mkv", ".mp4", ".mov", ".mpeg2" };
targetDirectory.GetFileTypeName(minNumeric: numericUpDown2.Value
, maxNumeric: numericUpDown1.Value, extensions: fileExtensions);
}
if (checkBox3.Checked)
{
fileExtensions = new string[] { ".jpj", ".png" };
targetDirectory.GetFileTypeName(minNumeric: numericUpDown2.Value
, maxNumeric: numericUpDown1.Value, extensions: fileExtensions);
}
if (checkBox4.Checked)
{
fileExtensions = new string[] { ".txt", ".doc", ".pdf" };
targetDirectory.GetFileTypeName(minNumeric: numericUpDown2.Value
, maxNumeric: numericUpDown1.Value, extensions: fileExtensions);
}
}
}
// Open OtherOption form if button4 was Clicked
private void button4_Click(object sender, EventArgs e)
{
OtherOption OtherOptionForm = new OtherOption();
OtherOptionForm.Show();
}
}
و کلاس زیر کلاسی که میخوام تو اون از پروپرتی fileExtensions کلاس فرم اول استفاده کنم
public partial class OtherOption : Form {
public OtherOption()
{
InitializeComponent();
label1.Enabled = false;
label2.Enabled = false;
textBox1.Enabled = false;
comboBox1.Enabled = false;
}
private void button2_Click(object sender, EventArgs e)
{
this.Close();
}
private void button1_Click(object sender, EventArgs e)
{
if (checkBox1.Checked == true)
{
}
if (checkBox2.Checked == true)
{
Form1 formOne = new Form1();
formOne.fileExtensions[0] = comboBox1.SelectedValue.ToString();
formOne.VertifyRequests();
}
this.Close();
}
private void checkBox1_CheckedChanged(object sender, EventArgs e)
{
if (!checkBox1.Checked)
{
label1.Enabled = false;
textBox1.Enabled = false;
}
if (checkBox1.Checked)
{
label1.Enabled = true;
textBox1.Enabled = true;
}
}
private void checkBox2_CheckedChanged(object sender, EventArgs e)
{
if (!checkBox2.Checked)
{
label2.Enabled = false;
comboBox1.Enabled = false;
}
if (checkBox2.Checked)
{
label2.Enabled = true;
comboBox1.Enabled = true;
}
}
}
که چه مقدار اولیشو null کنم چه مثلا new string[10]
بازم ارور NullReferenceException رو در قسمت کد زیر میده
formOne.fileExtensions[0] = comboBox1.SelectedValue.ToString();