已有56人关注
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()函数呢?
分享到:
精彩评论 1
小科_mrkj
学分:43 LV2
2016-04-13
沙发
读者朋友:
    您好,在其他窗体中创建当前窗体的对象,然后使用该对象调用相应控件的click事件即可,跟调用方法一样。
首页上一页 1 下一页尾页 1 条记录 1/1页
手机同步功能介绍
友情提示:以下图书配套资源能够实现手机同步功能
明日微信公众号
明日之星 明日之星编程特训营
客服热线(每日9:00-17:00)
400 675 1066
mingrisoft@mingrisoft.com
吉林省明日科技有限公司Copyright ©2007-2022,mingrisoft.com, All Rights Reserved长春市北湖科技开发区盛北大街3333号长春北湖科技园项目一期A10号楼四、五层
吉ICP备10002740号-2吉公网安备22010202000132经营性网站备案信息 营业执照