【发布时间】:2020-10-15 05:27:55
【问题描述】:
我无法获得从第一个 main form 到第二个 form 的值。我希望能够以richtextbox 的第二种形式显示计算出的文件夹和文件的数量。我求你帮助我。感谢大家的建议。
表格1:
using System;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Windows.Forms;
namespace pocetadresaru
{
public partial class Form1 : Form
{
private Form2 form2;
public Form1()
{
InitializeComponent();
}
private void Form1_Shown(object sender, EventArgs e)
{
form2 = new Form2();
form2.FormClosed += new FormClosedEventHandler(form2_FormClosed);
form2.Location = new Point(Location.X, Location.Y + Height + 80);
form2.Show();
textBox1.Focus();
}
private void form2_FormClosed(object sender, FormClosedEventArgs e)
{
Close();
}
private void button1_Click_1(object sender, EventArgs e)
{
string folderPath= String.Empty;
var folder = new FolderBrowserDialog();
if (folder.ShowDialog() == DialogResult.OK)
{
folderPath = Path.GetFullPath(folder.SelectedPath);
textBox1.Text = folderPath;
}
}
public static int GetDirectoryCount(string folderPath)
{
return Directory.EnumerateDirectories(folderPath).Count();
}
public static int GetFileCount(string folderPath)
{
return Directory.EnumerateFiles(folderPath).Count();
}
}
}
表格2:
using System;
using System.Windows.Forms;
namespace pocetadresaru
{
public partial class Form2 : Form
{
public string Data
{
get { return richTextBox1.Text; }
set { richTextBox1.Text = "Adresář:" +
**the number of directories listed here** `+ Environment.NewLine + "Soubor:" +` **the number of files listed here**`; }
}
public Form2()
{
InitializeComponent();
}
}
}
【问题讨论】:
-
form2.Data = "what ever you want"; form2.Show(); -
@TheGeneral 当我想查看
GetDirectoryCount()它不起作用
标签: c# forms return-value