C#如何访问彼此的表单对象 [英] C# how to access each other form objects

查看:69
本文介绍了C#如何访问彼此的表单对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述





Below this code I'm trying to figure out how these forms can freely accessed their both objects. In these code, 

 - ITEMCount can access the objects of SIMSProduct
 - On the other side although SIMSProduct can see the objects of ITEMCount
(There is no argument given that corresponds to the required formal parameter 'view' of 'SIMSProduct.SIMSProduct(ITEMCount)')





我尝试过:





What I have tried:

//Form that use SIMSPRODUCT controls
        public partial class ITEMCount : Form
        {
        SIMSProduct  _view;
        public  ITEMCount(SIMSProduct view)
        {
            InitializeComponent();
            _view = view;
            DisplayQuantity();
        }
        }
        // Form controls that been accessed by ITEMCOUNT
        public partial class SIMSProduct : UserControl
        {
        ITEMCount _view;
        public SIMSProduct(ITEMCount view)
        {
            InitializeComponent();
            _view = view;
        }
   
        }

        //Code for calling the ITEMCount form
            new ITEMCount(this).ShowDialog(); // Belongs to SIMSProduct form

        //Code for calling the SIMSProduct form
            var obj = new SIMSProduct(); // this where error point out
            obj.Dock = DockStyle.Fill;
            panel3.Controls.Clear();
            panel3.Controls.Add(obj); 

推荐答案

您忘记了构造函数所需的参数。您声明构造函数:

You forgot the required parameter to the constructor. You declare the constructor:
public SIMSProduct(ITEMCount view)



但是你在调用中未能传递一个view参数,即:


But then you fail to pass a view parameter in your call, which is:

var obj = new SIMSProduct();


这篇关于C#如何访问彼此的表单对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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