c# 怎么获得按钮控件的返回值呢?/怎么在别的类中调用窗体 frm的button1_Click()函数呢?
发表在C#图书答疑
2016-04-10
是否精华
是
否
版块置顶:
是
否
以下是窗体的 button1按钮的单击事件。
public void button1_Click(object sender, EventArgs e)
{
string[] str_name;
string str_path = string.Empty;
string str_show = string.Empty;
int int_count = 100;
int int_path;
int int_full;
str_name = new string[int_count];
openFileDialog1.Filter = "txt文件(*.txt)|*.txt";//筛选文件
openFileDialog1.Multiselect = true;
StringBuilder str_b; // = new StringBuilder();
if (openFileDialog1.ShowDialog() == DialogResult.OK)//弹出打开文件对话框
{
int_count = openFileDialog1.FileNames.Length;
//Mess
//System.IO.StreamReader sr = new//创建文件读取器对象
// System.IO.StreamReader(openFileDialog1.FileName, Encoding.Default);
//textBox1.Text = sr.ReadToEnd();//显示文本文件内容
//sr.Close();//关闭流
str_path = System.IO.Path.GetDirectoryName(openFileDialog1.FileNames[0]);
//MessageBox.Show(str_path);
textBox2.Text = str_path;
int_path = str_path.Length;
for (int j = 0; j < int_count; j++)
{
str_name[j] = openFileDialog1.FileNames[j];
int_full = str_name[j].Length;
//str_path=openFileDialog1.FileName.
str_b = new StringBuilder(str_name[j], 1000);
str_b.Remove(0, int_path + 1);
str_show += str_b;
str_show += "\r\n";
}
textBox1.Text = str_show;//显示文本文件内容
this.turn_on = 1;
//this.rst = DialogResult.OK;
//MessageBox.Show(this.turn_on.ToString());
this.int_num_f = int_count;
this.str_name_f = new string[this.int_num_f];
this.str_name_f = str_name;
}
return ;
}
怎么在别的类中调用窗体 frm的button1_Click()函数呢?
public void button1_Click(object sender, EventArgs e)
{
string[] str_name;
string str_path = string.Empty;
string str_show = string.Empty;
int int_count = 100;
int int_path;
int int_full;
str_name = new string[int_count];
openFileDialog1.Filter = "txt文件(*.txt)|*.txt";//筛选文件
openFileDialog1.Multiselect = true;
StringBuilder str_b; // = new StringBuilder();
if (openFileDialog1.ShowDialog() == DialogResult.OK)//弹出打开文件对话框
{
int_count = openFileDialog1.FileNames.Length;
//Mess
//System.IO.StreamReader sr = new//创建文件读取器对象
// System.IO.StreamReader(openFileDialog1.FileName, Encoding.Default);
//textBox1.Text = sr.ReadToEnd();//显示文本文件内容
//sr.Close();//关闭流
str_path = System.IO.Path.GetDirectoryName(openFileDialog1.FileNames[0]);
//MessageBox.Show(str_path);
textBox2.Text = str_path;
int_path = str_path.Length;
for (int j = 0; j < int_count; j++)
{
str_name[j] = openFileDialog1.FileNames[j];
int_full = str_name[j].Length;
//str_path=openFileDialog1.FileName.
str_b = new StringBuilder(str_name[j], 1000);
str_b.Remove(0, int_path + 1);
str_show += str_b;
str_show += "\r\n";
}
textBox1.Text = str_show;//显示文本文件内容
this.turn_on = 1;
//this.rst = DialogResult.OK;
//MessageBox.Show(this.turn_on.ToString());
this.int_num_f = int_count;
this.str_name_f = new string[this.int_num_f];
this.str_name_f = str_name;
}
return ;
}
怎么在别的类中调用窗体 frm的button1_Click()函数呢?