首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > C# >

winform窗体切换,该如何处理

2013-07-08 
winform窗体切换父窗体点击btnAdd打开窗体A,在窗体A中完成操作后(点击确定按钮),返回数据,并打开B窗体我的

winform窗体切换
父窗体点击btnAdd打开窗体A,在窗体A中完成操作后(点击确定按钮),返回数据,并打开B窗体

我的实现代码:
A窗体:

private void btnOK_Click(object sender, EventArgs e)
        {
            if (!DoValid()) return;
            string str = "";
            foreach (string strSpNo in strSpPlanArr)
            {
                str = str + strSpNo + ",";
            }

            str = str.TrimEnd(',');
            PlanSelectedEvent(this, new PlanSelectedEventArgs { spPlanNoList = str });
        }

父窗体:

 private void btnAdd_Click(object sender, EventArgs e)
        {
            frmPlanSelect.Width = 175;
            frmPlanSelect.ReferForm = this;
            frmPlanSelect.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle;
            frmPlanSelect.MaximizeBox = false;
            frmPlanSelect.ShowDialog();
        }

        private void onPlanSelected(object sender, PlanSelectedEventArgs e)
        {
            strSpNoList = e.spPlanNoList;
            frmPlanSelect.Close();
            ShowEditForm();
        }


        /// <summary>
        /// 显示编辑页
        /// </summary>
        /// <param name="iSpID"></param>


        void ShowEditForm()
        {
            frmCharegeAgainsetEdit frm = new frmCharegeAgainsetEdit();
            int iwidth = (int)((float)Screen.PrimaryScreen.WorkingArea.Width * 0.9F);
            if (iwidth > 1200) iwidth = 1200;
            frm.Width = iwidth;
            frm.strSpNoList = strSpNoList;
            frm.ReferForm = this;
            frm.ShowDialog();
        }
    }




if(A.ShowDialog()==DialogResult.OK)
{
   A.返回的数据
   B.ShowDialog()
}
[解决办法]

首先你这么传递数据就有问题,太麻烦了

你为何不做一个全局的类呢,然后把需要传递的数据赋给全局值

点击ok返回dialogue.result  ok  来判断是否点击了确定按钮

比你这样简单都了
那如何才能达到这种效果呢?
+1



if(A.ShowDialog()==DialogResult.OK)
{
   A.返回的数据


   B.ShowDialog()
}

热点排行