如何将变量传递给另一种形式 [英] How to pass variable to another form

查看:98
本文介绍了如何将变量传递给另一种形式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

尊敬的先生/女士,

我现在是
在csharp winform应用程序中,成功登录后如何将登录ID传递给另一种形式?
我的登录按钮代码是这样的

Hi Sir/Madam,

I am uday
In csharp winform application,how i to pass login id to another form,after successfull login?.

My code for login button is like this

if (rowsCount > 0)          // IF USER IS VALID
                      {
                          string userName = txtUserNm.Text;
                          int loggeduserId=Convert.ToInt32(ds.Tables["UserLogin"].Rows[0][0]);

    

                          
                          this.Hide();
                          MDIParent menu = new MDIParent();

                          this.DialogResult = DialogResult.OK;


                      }
                      else
                      {
                          MessageBox.Show("You are not valid user", "alert", MessageBoxButtons.OK, MessageBoxIcon.Error);

                      }




在上面的代码 loggeduserId 中,我必须传递其他所有形式.

如何实现?他们的会议像c尖锐的winform中的概念吗?

在此先感谢.............




in above code loggeduserId i have to pass other all forms.

how it can achieved? Is their session like concept in c sharp winform?

Thanks in advance.............

推荐答案

没有像Session这样的概念.
您可以使用公共访问修饰符来创建一个类,并且在该类中使用属​​性以其他形式进行访问...
No there is no concept like Session.
You can make a class with public access modifier and in this class use properties to access in other forms...


在C#中没有可用的会话,但是您可以使用属性将信息从一种形式传递到另一种形式.
另外,不整洁的方法是使用静态变量.
No there is no session avaiable in C# but you can use properties to pass information from one form to another.
Also, untidy method is to use static variable.


简单的步骤为您提供::

1.在您要访问登录名的位置创建一个属性
2.为您在其中创建属性的表单创建对象
3.成功登录后将值分配给您的财产
4.在该页面中访问属性

简单
simple steps for you::

1.create a property where you want to access the login name
2.create object for the form where you create the property
3.assign value to your property after successfull login
4.there in that page access the property

its simple


这篇关于如何将变量传递给另一种形式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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