如何在函数中调用Form

How to call Form in a function

当 cariGuide.cs 表格单元格双击功能执行时,我有两种表格 我想去 Form1.cs 或 Form2.cs 如果以前的表格 form1 或 form2?

这是我的代码块:

public void GoBackMain(Form frm) //
        {
            if (dgvCariRehber.CurrentRow.Index != -1)
            {
                cariModel.Id = Convert.ToInt32(dgvCariRehber.CurrentRow.Cells["Id"].Value);
                using (Entities db = new Entities())
                {
                    cariModel = db.xcaSabits.Where(x => x.Id == cariModel.Id).FirstOrDefault();
                    frm.lblCariID.Text = cariModel.Id.ToString(); // cariSabitte güncelleme için id yi gönder.
                    frm.txtCariKodu.Text = cariModel.cariKodu;

                    frm.Show();
                    this.Hide();
                }
            }
        }

我的问题是如何捕捉和理解以前表格的数据并发送函数(Form frm)

我终于找到了!!

首先你必须声明你的主窗体;

        frmMain originalForm;
        public frmCariRehber(frmMain incomingForm)
        {
            originalForm = incomingForm;
            InitializeComponent();
        }

此表单是您的主表单,它不会关闭,您 return 即将到来的表单并以此管理表单。

在那之后;

public void GoBackMain()
        {
            if (dgvCariRehber.CurrentRow.Index != -1)
            {
                cariModel.Id = Convert.ToInt32(dgvCariRehber.CurrentRow.Cells["Id"].Value);
                using (fastCellDb db = new fastCellDb())
                {
                    cariModel = db.xcaSabits.Where(x => x.Id == cariModel.Id).FirstOrDefault();
                    originalForm.CariID = cariModel.Id;
                    originalForm.CariKodu = cariModel.cariKodu;
                    originalForm.CariAdi = cariModel.cariIsim;
                    originalForm.CariPopulate();
                    this.Close();
                }
            }
        }

这是我的 Datagridview 单元格点击函数 GoBackMain()。

谈论MainForm.cs

public string StokKodu,CariKodu,CariAdi;
public decimal StokFiyati;
public int StokID,CariID;

您必须在 return 打开表格时声明变量。

最后得到值MainForm.cs!!

     internal void StokPopulate()
        {
            txtStokKodu.Text = StokKodu;
            lblStokID.Text = StokID.ToString();
        }
     internal void CariPopulate()
        {
            txtCariKodu.Text = CariKodu;
            lblCariID.Text = CariID.ToString();
            lblCariGetir.Text = CariAdi;
        }