System.NullReferenceException错误c#

时间:2015-03-05 08:11:15

标签: c# winforms null active-form

我有这段代码:

 using System;
 using System.Collections.Generic;
 using System.Linq;
 using System.Text;
 using System.Threading.Tasks;
 using System.Windows.Forms;

 namespace ConsoleApplication2
 {
     class Program
     {
         static void Main(string args)
         {
             string TheFormText;
             string TheFormName;
             string TheFormTag;
             Form activeForm = Form.ActiveForm;
             TheFormText = activeForm.ActiveMdiChild.Text.ToString();          
             TheFormName = activeForm.ActiveMdiChild.Name.ToString();
             try
             {
                 TheFormTag = activeForm.ActiveMdiChild.Tag.ToString();
             }
             catch
             {
                 TheFormTag = "<none>";
             }
         }
     }
 }

我尝试运行但是当我这样做时我得到了这个错误 ConsoleApplication2.exe中发生了未处理的“System.NullReferenceException”类型异常

在TheFormText = activeForm.ActiveMdiChild.Text.ToString();

有人可以帮助我让它发挥作用吗?

0 个答案:

没有答案
相关问题