在表单之间传递数据/信息 [英] Passing data/information between forms

查看:60
本文介绍了在表单之间传递数据/信息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

伙计们!希望您对此有所帮助.
我有两种形式,都只有按钮.我想在两者之间做出选择.

1)单击Form1中的某些按钮可以打开Form2(工作正常).

2)单击Form2中的某些按钮必须打开其他表单,具体取决于我在两个表单中单击的按钮.

我的代码:

这是在Form1中:

Hi, guys! I hope you help me with this.
I have two forms, both with only buttons. I want to make a combined choice between the two.

1) Clicking on certain buttons in Form1 opens Form2 (that''s working fine).

2) Clicking on certain buttons in Form2 must open other forms, depending on which buttons I clicked on both forms.

My code:

This is in Form1:

#pragma endregion
private: System::Void button1_Click(System::Object^  sender, System::EventArgs^  e)
		 {
		 	 String ^ m_option1 = "1";//Project
			 Form2 ^form2 = gcnew Form2;
	                 form2->Show();
		 }
This is in Form2:
#pragma endregion
private: System::Void button1_Click(System::Object^  sender, System::EventArgs^  e)
		{
			String ^ m_option2 = "1";//Add
			String ^ m_choice  = m_option1 + m_option2;
			Form8_add_tutor ^form8_add_tutor = gcnew Form8_add_tutor;
	                form8_add_tutor->Show();
		}

这是错误:m_option1未声明的标识符.
注意:到目前为止,这给了我最少的错误.我尝试将m_option1公开,但这只会使情况变得更糟.
致谢

This is the error: m_option1 undeclared identifier.
NOTE: So far, this has given me the least errors. I tried making m_option1 public and it only made it worse.
THANKS IN ADVANCE

推荐答案

如果要在表单之间共享数据,最好的选择是将数据放入两个表单都可以访问的静态类中. (您将不得不将下面的代码转换为C ++.)

If you want to share data between forms, your best bet is to make put data into static class that both forms can access. (You''re going to have to convert the code below to C++.)

public static class Globals
{
    public static string MyString { get; set; }
}


请参阅我对问题的评论.我认为您目前不准备进行任何开发-不仅仅是现在.您声明一个变量m_option1,它是一个堆栈变量.如果在函数退出时甚至不存在,则不仅无法访问堆栈框架的范围之外的内容.同一类的不同实例,同一类的不同实例,访问修饰符—完全不相关.

您甚至尝试向其添加访问修饰符.当有人踢电视机直到开始显示图片时,这就是这种工程".你没有机会您应该了解所写的每一行.在这种情况下,问题不在于语法的任何细节.它表明您不知道什么是变量和什么是函数.不多不少.我不能一言以蔽之.您需要掌握一本手册,并从一开始就开始学习编程,这是您已全面了解.解决简单的问题,以掌握代码.
Please see my comment to the question. I don''t think you are ready to do any development at this moment — not just yet. You declare a a variable m_option1, which is a stack variable. Not only it is no accessible out of the scope of the stack frame, if does not even exist on exit of the function. Same of different instance of the same of different class, access modifiers — all that is totally irrelevant.

You even tried to add an access modifiers to it. This is that kind of "engineering" when someone kicks a TV set until it starts showing picture. You have no chance. You should understand every single line you write. In this case, the problem is not any detail of syntax or something. It shows that you have no idea what is a variable and what is a function. No more no less. And I cannot explain it in a short answer. You need to grab a manual and start learning programming from the very beginning, this time with full understanding. Solve simple problems, to get a grip on the code.
Yoda 所写:

取消了解您所学.

—SA


这篇关于在表单之间传递数据/信息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆