在两种形式上使用类的实例 [英] Using and instance of a class on two forms

查看:71
本文介绍了在两种形式上使用类的实例的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在努力使自己的想法趋于正确. 我目前有三种形式,我的主班和一个主班.

I am struggling to get my head around the following. I current have three forms, my main and one main class.

public partial class frmMain : Form
{
    public frmMain()
    {
        InitializeComponent();
    }
}

public partial class frmSuppliers : Form
{
    public frmSuppliers()
    {
        InitializeComponent();
    }
}

public partial class frmCustomers : Form
{
    public frmCustomers()
    {
        InitializeComponent();
    }
}

在我的主程序中,我有:

In my main program I have:

 public class Program
 {
        public StockControl StockSystem = new StockControl("The Book Shop", 20);
 }

我希望能够从frmSuppliers和frmMain中的StockControl中访问这些方法.

I want to be able to access the methods from StockControl in frmSuppliers and frmMain.

我知道这可能是一个N00b问题-但这整天困扰着我!

I know this may be a N00b question - but its been bugging me all day!

推荐答案

您需要将其作为构造函数参数传递给其他表单,然后将其存储在私有字段中.

You need to pass it to the other forms as a constructor parameter, then store it in a private field.

这篇关于在两种形式上使用类的实例的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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