控制从一种形式到另一种形式的访问 [英] Control access from one form to another form

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

问题描述

您好,专家,

我有两种形式-Form1和Form2. Form1具有一些控件,例如dataGridView,Textbox,dateTimePicker,ListBox和命令按钮.

所有人都可以在相同的表单(FORM1)上正常工作. FORM2是具有crystalReportViewer控件的FORM1的参考,该控件也正在工作.但是,当我基于FORM1的输入运行此报告时,控件的值将重置如下:

## dateTimePicker与当前dateTime
##包含空数据的列表框

我也尝试过使用Property seting(get; set)并创建Form1和Form2的实例.但没有成功.

谁能帮我吗?

--- Anil Kumar

Hi Experts,

I have two forms - Form1 & Form2. Form1 has some control like dataGridView, Textbox, dateTimePicker,ListBox and command buttons.

All are working fine on the same form(FORM1). FORM2 is the reference for FORM1 having crystalReportViewer control which is also working. But when i run this report based on input of FORM1 the value of controls get reset as below:

## dateTimePicker with current dateTime
## listBox with empty data

I have also tried it with Property seting(get;set) and create instance of Form1 & Form2. but not succeeded.

Can anyone help me please ???

--- Anil Kumar

推荐答案

这只是一个猜测,因为您没有提供任何代码,但是我很确定您正在Form2中访问Form1作者:
This is just a guess since you didn''t supply any code, but I am pretty sure at some point in Form2 you are accessing Form1 by:
Form1 f1 = new Form1();
PassMyDataToReporting(f1.DateTimePicker1, f1.ListBox1);


重要的词是new,它创建Form1的新实例-不是您填写所有详细信息的实例,而是具有默认值的全新实例.
我认为您需要回到笔记上并继续阅读实例,依此类推...


The important word is new which creates a new instance of Form1 - not the one you filled in all the details on, but a brand new instance with the default values.
I think you need to go back to your notes and read up on instances and so forth...


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

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