另一个项目的表单的访问字段 [英] Access Field of Another Project's Form

查看:95
本文介绍了另一个项目的表单的访问字段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个项目.项目1和项目2
我已将Project 2添加到Project 1
我还在项目1中添加了对项目2的引用

我用
导入Project2

on Button单击事件
将xform变暗为新的Project2.form1
xform.show()

它显示的是form1....现在

在Project 2.Form1中,有一个textbox1.当我单击项目1的按钮时,我想在textbox1中输入文本.但是该textbox1(Project2.Form1)没有出现在列表中...
例如

将xform视作新的Project2.form1
xform.show()
xform.textboxt1(这不会出现...)
我无法访问Project2.Form1.textbox1
请帮助....

I have Two Projects.. Project 1 and Project 2
I have add Project 2 into Project 1
I have also add reference of Project 2 into Project 1

I use
Import Project2

on Button Click event
dim xform as new Project2.form1
xform.show()

It is showing the form1.... NOW

In Project 2.Form1 there is one textbox1. I want to enter text into that textbox1 when I click on button of Project 1.. but that textbox1 (Project2.Form1) is not appearing in the list...
e.g.

dim xform as new Project2.form1
xform.show()
xform.textboxt1 (this is not coming...)
I am unable to access Project2.Form1.textbox1
please help....

推荐答案

在Project2.Form1设计器视图中,选择您要讨论的TextBox;在属性"面板中,注意AccessModifier属性,并将其设置为Public.

然后重新生成您的解决方案;您现在应该看到此TextBox出现在列表中.

说明:默认情况下,您创建的控件具有Friend(在C#中为internal)访问修饰符.当您尝试从另一个项目访问该对象时,看不到它.
将其访问修饰符更改为公共"应该可以访问它.

希望这会有所帮助.
In the Project2.Form1 designer view, select the TextBox you are talking about ; in the Properties panel, watch out for the AccessModifier property, and set it to Public.

Then regenerate your solution ; you should now see this TextBox appear in the list.

Explanation : by default, the controls you create have Friend (internal in C#) access modifier. As you are trying to access this object from another project, you cannot see it.
Changing its access modifier to Public should give you access to it.

Hope this helps.


这篇关于另一个项目的表单的访问字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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