表格之间的沟通 [英] Communication between forms

查看:78
本文介绍了表格之间的沟通的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

请帮助我,我有一个项目并有3个表格,表格1表示姓名和名字,表格2表示学校和大学,表格3表示所有数据。如何显示来自textbox1的数据形式1和形式2形成3 ??







看看伙计..

为了解决我的问题

我有两种表格..



表格1:1个文本框和1个按钮(按钮不要不显示用户在txtbox中输入的名称,但打开表单2)



表单2:1 txtbox和按钮,(在txtbox表单1用户输入名称)in这个txtbox表单2用户输入他的姓氏...按钮将显示一个msgbox,显示名称和姓氏..





我该怎么办?





我试过这个:但是它没有用完:/



Please help me, I have a project and have 3 form, form 1 is for name and lastname, form 2 is for school and university, form 3 is to display all the data ..How can i display data from textbox1 in form 1 and form 2 to form 3??



Look Guys ..
To make my problem clear
I have two forms..

Form 1: 1 textbox and 1 button ( button don''t show the name that user enter in txtbox but open form 2)

Form 2: 1 txtbox and button, (in txtbox form 1 user enter name) in this txtbox form 2 the user enter his lastname...The button will show a msgbox wich show up the name and lastname..


how can i do it?


I tried like thi: but it doesn''t work out :/

Private Sub Command1_Click()
Static name As Integer
Static lastname As Integer
firstname = txtFirstName.Text
LastName = txtLastName.Text
txtFirstName.Text = Form1.txtFirstName.Text
txtLastName.Text = Form2.txtLastName.Text

both = (Form1.txtFirstName.Text " & & " Form2.txtLastName.Text)
MsgBox (both)

End Sub

推荐答案

Yo可能会创建一些容器,您可以在其中存储各种表单中的所有数据。 />
但是有一件事你应该考虑,这个持有人/容器的行为必须像单身人士一样!使用单身模式吧!



一个重要的时刻,在将来,请原则上尝试自己编写一些代码,并且只有在出现一些混淆或错误的情况下,请求社区帮助!
Yo might to create some container , where you can store all data from various forms.
But one thing that you should consider, this holder/container must behaves like singleton! Use singleton pattern for it!

And one important moment, in future , please , primiraly try to write some code by yourself , and only in case of some confusion or error , ask comunnity for help!


这是关于表单协作的流行问题。最强大的解决方案是在表单类中实现适当的接口,并传递接口引用而不是引用Form的整个实例。请参阅我过去的解决方案以获取更多详细信息:如何以两种形式复制列表框之间的所有项目 [ ^ ]。



请参阅本讨论中的其他解决方案。如果应用程序足够简单,解决方案就像在一个表单中声明一些 internal 属性并将对一个表单的实例的引用传递给另一个表单的实例一样简单形成。对于更复杂的项目,这种违反严格封装的样式和松散耦合可能会增加代码的意外复杂性并引发错误,因此封装良好的解决方案将是优惠。



另请参阅:

http://en.wikipedia.org/wiki/Accidental_complexity [ ^ ],

http://en.wikipedia.org/wiki/Loose_coupling [ ^ ]。



我还要补充说你的设计看起来不太好。我强烈建议对其进行审核,但我不能建议任何特定的设计,因为我现在还不知道你的目标。首先,我会避免多形式设计。在大多数情况下,一个但更复杂的形式是足够的,但它对用户来说也更方便。你现在作为一个单独的表格可以成为一些容器控制。例如 Panel TabPage 。您可以隐藏一个面板并显示另一个面板,您可以一次激活一个 TabControl 的不同页面,甚至可以开发更复杂的可停靠设计(类似于Visual Studio的设计) )。请考虑一下。



新年快乐!



-SA
This is the popular question about form collaboration. The most robust solution is implementation of an appropriate interface in form class and passing the interface reference instead of reference to a "whole instance" of a Form. Please see my past solution for more detail: How to copy all the items between listboxes in two forms[^].

Please also see other solutions in this discussion. If the application is simple enough, the solution could be as simple as declaring of some internal property in one form and passing a reference to the instance of one form to the instance of another form. For more complex projects, such violation of strictly encapsulated style and loose coupling could add up the the accidental complexity of the code and invite mistakes, so the well-encapsulated solution would be preferable.

Please see also:
http://en.wikipedia.org/wiki/Accidental_complexity[^],
http://en.wikipedia.org/wiki/Loose_coupling[^].

I would also add that your design does not seem good. I would strongly advise to review it, but I cannot suggest any particular design as right now I don''t know your goals. First of all, I would avoid multi-form design at all. In most cases, one but more complex form is quite enough, but it also more convenient for the users. What you have now as a separate form can become some container control. Such as Panel or TabPage. You can hide one panel and show another one, you can activate different pages of TabControl, one at a time, or even develop more complex dockable design (similar to that of Visual Studio). Please think about it.

Happy New Year!

—SA


将TextBox或LabelBox或DataGridView放在第3个表单中

这里我编写代码来显示从Form1和From2到TextBox的详细信息Form3 ...



Place TextBox or LabelBox, or DataGridView in Your 3rd Form
Here i''ve Write Code to Display Details from Form1 and From2 to TextBox(s) in Form3...

txtFristName.Text = Form1.txtFirstName.Text







为所有字段写相似的代码,



如果这个答案不是你在找?只是改善你的问题并针对你的问题......




Write Similar Code for all Fields,

If this answer not you Looking for? Just Improve your Question and Be Specific with your Problem...


这篇关于表格之间的沟通的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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