如何在几种形式之间进行通信? [英] how to communicate between several forms?

查看:65
本文介绍了如何在几种形式之间进行通信?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,


我正在尝试创建一个存在2种形式的应用程序:

a登录表单和面板表单。


现在登录表单自己说话,当我按下登录时我向我的服务器发送请求,服务器返回一些东西..


我制作使用表单中的Form类和进行联网的Client(表单登录)类。


现在当我插入错误的密码时,我想要它设置它登录面板上的文字无效密码。


但是,当我设置文本时,我会遇到有关交叉线程的错误,即使我使用代理来解决这个问题。 />

但问题是我通过表单类的实例访问文本:this.loginForm.text =" invalid pass";


此代码在我的Client类中:

Hello,

i''m trying to create an application which exists of 2 forms:
a login form and a panel form.

Now the login form speaks for itself, when i press login i send a request to my server and the server returns some things..

I make use of a Form class which inits the form and a Client(Form login) class which do the networking.

Now when i insert a wrong pasword for example, i want it that it sets a text on the login panel to invalid password.

But the thing is that i get errors about cross threading when i set my text, EVEN if i use delegates to fix this.

But the problem is that i acces the text via an instance of the form class: this.loginForm.text = "invalid pass";

this code is in my Client class:

展开 | 选择 | Wrap | 行号

推荐答案

好的,你得到的代码有让我大吃一惊...太过混乱!!!


但是有一个简单的解决方案。


我假设你的''panel''表单是主要表单,''login''表单就像一个弹出的对话框?


如果是这样,请按照以下步骤操作。

登录表单名为frmLogin

面板表单名为frmPanel


在登录表单的代码中,声明此变量:
Ok, the code you''ve got has blown my mind... way too confusing!!!

But there is a simple solution.

I''m assuming that your ''panel'' form is the main form and the ''login'' form is just like a dialog that pops up?

If so, follow these steps.
login form is called frmLogin
panel form is called frmPanel

In the login form''s code, declare this variable:
展开 | 选择 | Wrap | 行号


好的感谢快速回复!


我会试一试!
ok thanks for the fast reply!

i''ll try it!


嗯,似乎这不是我想要的想法:


i'有3个课程atm

一个登录表格类

一个面板表格类

一个网络客户端类(这不是表格!)


因此,当应用程序启动时,我希望它只显示我的登录表单,我使用客户端类进行网络连接,当我有错误的用户名/通行证时我想要文本要在客户端类的登录类中设置..所以我需要在我的客户端类中使用登录类的SAFE实例,但是如上所述以上我现在所做的不行。


您是不是在任何步骤中使用客户端类?


感谢您的回复虽然:)
Hmm it seems that this isn''t what i want i think:

i''ve 3 classes atm
one login form class
one panel form class
one client class for networking(this is not a form!)

so when the application starts up, i want it to show only my login form, i use the client class for networking, and when i have a wrong username/pass i want the text to be set at login class from the client class.. so i need an SAFE instance of the login class in my client class, but as stated above what i have now doesn''t work.

you are not using the client class in any step?

thanks for the reply though :)


这篇关于如何在几种形式之间进行通信?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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