以另一种形式存储数据的保护问题 [英] storing data in another form protection issues

查看:83
本文介绍了以另一种形式存储数据的保护问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将一种形式的字符串存储到另一种形式的标签中。但是,这样做时,由于其保护级别,因此无法完成。有想法该怎么解决这个吗?

I'm trying to store a string from one form to a label on another from. However, when doing so it says it cannot be done because of its protection level. Any ideas on how to fix this?

 maskedTxtLogin.Text = FormInvisible.lblInitials.Text();


推荐答案

控件是作为 private 表单设计器中的字段:

The controls are generated as a private field in your form designer:

private System.Windows.Forms.Label lblInitials;

如果要在表格之外访问它们,则需要创建属性。要查看上面的声明并为其编写属性,只需右键单击代码中的 lblInitials 并单击转到声明(或定义),在您要浏览的类中编写以下代码:

If you want to access them outside of the form you need to create a property for them. To see the above declaration and write a property for that, just right click on your lblInitials in your code and click Go to Declaration (or Definition), in the class that you are navigated to write the following code:

public Label LblInitials
{
    get { return lblInitials; }
    set { lblInitials= value; }
}

此外,您还需要创建表单的新实例来访问此属性:

Also you need to create a new instance of your form to access this property:

FormInvisible fr = new FormInvisible();
maskedTxtLogin.Text = fr.LblInitials.Text;

这篇关于以另一种形式存储数据的保护问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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