本文介绍了使用C#.net将函数从Form调用到另一个表单的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 项目有3个Forms.that是Form1,Form2,Form3.One按钮位于每个form.One函数位于Form中,名为Message()。我只是从Form3调用该函数。 但它没有用。 Form1 private void button1_Click( object sender,EventArgs e) { Form2 frm = new Form2(); frm.Show(); } 功能 public void message() { pictureBox1.ImageLocation = @ C:\Documents and Settings \User\My Documents\My Pictures\ index.JPEG; } Form2 private void button1_Click( object sender,EventArgs e) { this .Close(); Form3 frm = new Form3(); frm.Show(); } Form3 声明 Form1 frm = new Form1; private void button1_Click( object sender, EventArgs e) { frm.message(); this .Close(); } 但它没有用。请帮助我。为什么?我在图片框中上传了一张图片。如何解决这个问题?请做好... 解决方案 这取决于你打电话给消息时你期望发生的事情方法。 如果你期望它在Form1的新实例(你看不到)上设置pictureBox1的ImageLocation属性,那么它正在做你正在期待的。 如果您希望它影响创建For2和Form3的现有Form1上的pictureBox1,或者影响For2或Form3的PictureBox,那么它就赢了t,你需要仔细考虑你在做什么,并访问你希望影响的表格的实际实例。 你想做什么? ?你期望它做什么? 使形成对象并调用该功能。 。 。 喜欢: FORM1 FRM =新FORM1(); FRM.MESSAGE(); Hi,Project has a 3 Forms.that is Form1,Form2,Form3.One button is in the Each form.One Function is in the Form that is called Message(). I just call that function from Form3.But It is not worked.Form1private void button1_Click(object sender, EventArgs e){Form2 frm = new Form2();frm.Show();}Functionpublic void message(){pictureBox1.ImageLocation = @"C:\Documents and Settings\User\My Documents\My Pictures\index.JPEG";}Form2private void button1_Click(object sender, EventArgs e){this.Close();Form3 frm = new Form3();frm.Show();}Form3DeclarationForm1 frm = new Form1;private void button1_Click(object sender, EventArgs e){frm.message();this.Close();}But it is not worked.Please help me.why?I upload a picture in the Picture Box. how to solve this issue?Please do needful... 解决方案 It depends what you are expecting to happen when you call the message method.If you are expecting it to set the ImageLocation property of pictureBox1 on the new instance of Form1 (which you can't see) then it is doing exactly what you are expecting.If you are expecting it to affect the pictureBox1 on the existing Form1 that created For2 and Form3, or to affect a PictureBox of For2 or Form3, then it won't, and you need to think carefully about what you are doing, and access the actual instance of the form that you expect to affect.What are you trying to do? What do you expect it to do?MAKE TO FORM3 OBJECT AND CALL THAT FUNCTION . . .LIKE:FORM1 FRM = NEW FORM1();FRM.MESSAGE(); 这篇关于使用C#.net将函数从Form调用到另一个表单的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 10-24 07:12