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

C#在不同线程中怎么设置一个窗体是另一个窗体的父窗体

2013-10-11 
C#在不同线程中如何设置一个窗体是另一个窗体的父窗体主窗体form1是Run()出来的,另一个窗体form2是在新线

C#在不同线程中如何设置一个窗体是另一个窗体的父窗体
主窗体form1是Run()出来的,另一个窗体form2是在新线程中使用showdialog方法显示出来的,现在需要把form2的父窗体设置为form1,改如何实现?
[解决办法]
你怎么能在非工作线程showdialog呢?
[解决办法]
请回到主线程创建并调用ShowDialog,也就是用Invoke或者BeginInvoke进行所有UI相关操作
[解决办法]
不可以了吧。为什么要这样
[解决办法]


Thread th = new Thread(new ThreadStart(ExportCost));
            th.SetApartmentState(ApartmentState.STA);
            th.Start();


private void ExportCost()
        {
            SetExportBusinessNum();
            if (!string.IsNullOrEmpty(ExportBusinessNum))
            {
                Query_Customs_CustomsDeclaration query_Customs_CustomsDeclaration = GetQuery_Customs_CustomsDeclaration();
                query_Customs_CustomsDeclaration.BusinessNum = ExportBusinessNum;

                DataTable dt = Customs_CustomsDeclarationManager.QDZYExportCostExcel(query_Customs_CustomsDeclaration);
                if (dt != null && dt.Rows.Count > 0)
                {
                    SaveFileDialog sfd = new SaveFileDialog();
                    sfd.Filter = "excel文件(*.xls)
[解决办法]
*.xls";
                    sfd.FileName = "财务数据";
                    DataTable dtCopy = dt.Copy();
                    if (dt.Columns.Contains("是否审核")) dt.Columns.Remove("是否审核");
                    if (dt.Columns.Contains("是否导出")) dt.Columns.Remove("是否导出");
                    if (dt.Columns.Contains("Id")) dt.Columns.Remove("Id");
                    if (sfd.ShowDialog() == DialogResult.OK)
                    {
                        if (CommonMethodHelper.ExportExcel_NoScientificCalc(dt, sfd.FileName))
                        {
                            ShowInformationMsgBox(sfd.FileName + "导出成功!");
                            Customs_CustomsDeclarationManager.UpdateIsExport(query_Customs_CustomsDeclaration);
                            InvokeSearchCostData();
                        }
                    }
                }
                else
                {
                    ShowInformationMsgBox("没有要导出数据!");


                }
            }
            else
            {
                ShowInformationMsgBox("请选择您要导出的数据!");
            }
        }


[解决办法]
不可以的,跨线程不能搞这个

热点排行