其他形式的访问控制 [英] Access controls on other form

查看:46
本文介绍了其他形式的访问控制的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我应如何访问其他表单上的控件?


示例:我在Form2中有一个datagridview,我将从form1向它发送值.
我试图通过创建该形式的对象来访问它,但没有结果.
请帮忙我该怎么做

How should i access controls on other forms


Example: i have a datagridview in Form2, I will send values to it from form1.
I tried to access it by creating object of that form but no results.
please help how can i do it

推荐答案

看看这篇文章.您可能会有所了解.

在表单之间传递数据 [
Have a look at this article.You may get some idea.

Passing Data Between Forms[^]


希望http://msdn.microsoft.com/en-us/library/ms171925(v=vs.80).aspx [ ^ ]


在Form2中创建公共方法...

Create a public method in Form2...

public void AddToDataGrid()
{
   // pass whatever it is you wish to add, and add it to the gridview here.
}



然后,您可以使用对Form2的引用从Form1调用此方法...



Then, you can call this method from Form1 using the reference you have to Form2...

Form2 otherForm = new Form2();
otherForm.Show();

otherForm.AddToDataGrid();


这篇关于其他形式的访问控制的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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