打开子表单时出错

时间:2012-04-07 12:51:23

标签: c# .net winforms

我将使用telerik桌面控件制作桌面应用程序。 我的主要表单代码是:

 public partial class MainForm3 : Telerik.WinControls.UI.RadForm
       {
        private string ISadmin = string.Empty;
        private string Customer_ID = string.Empty;
        private string sLanguage_Code = "en-US";
        private string Contact_ID = string.Empty;
        public MainForm3(string Contact_IDa, string Customer_IDa, string ISadmina)
        {
            InitializeComponent();

            this.Contact_ID = Contact_IDa;
            this.Customer_ID = Customer_IDa;
            this.ISadmin = ISadmina;  
        }
        private void MainForm3_Load(object sender, EventArgs e)
                {
                    this.IsMdiContainer = true;
                    this.radDock1.AutoDetectMdiChildren = true;
                }
        private void radMenuItem1_Click(object sender, EventArgs e)
        {
            FormThree formthree= new FormThree ();
            formthree.MdiParent = this;
            formthree.Show();
        }

    }

字符串Contact_IDa,字符串Customer_IDa,字符串ISadmina来自登录页面

登录页面代码:

if(login success){

//setup necessary values 



 System.Threading.Thread t = new System.Threading.Thread(new  System.Threading.ThreadStart(ThreadProc));
 t.Start();
 this.Close();

}

public void ThreadProc()
        {
            Application.Run(new MainForm3(Contact_ID, Customer_ID, IsAdmin));
        }
  

和FormThree代码是;

public partial class FormThree : Telerik.WinControls.UI.RadForm
           {
        public FormThree ()
        {
            InitializeComponent(); 
            splitPanel1.AllowDrop = true;
            splitPanel1.DragEnter += splitPanel1_DragEnter;
            splitPanel1.DragDrop += splitPanel1_DragDrop;
        }
        private void splitPanel1_DragDrop(object sender, DragEventArgs e)
        {
            if (e.Data.GetDataPresent(DataFormats.FileDrop))
            {
                string[] filePaths = (string[])(e.Data.GetData(DataFormats.FileDrop));

                foreach (string fileLoc in filePaths)
                {
                    // Code to read the contents of the text file
                    if (File.Exists(fileLoc))
                    {
                        using (TextReader tr = new StreamReader(fileLoc))
                        {
                            string Name = Path.GetFileName(fileLoc);
                            string extention = Path.GetExtension(fileLoc);
                            MessageBox.Show("Name:" + Name + " </br>Extention:" + extention);
                            //MessageBox.Show(tr.ReadToEnd());
                        }
                    }
                }
            }
        }

        private void splitPanel1_DragEnter(object sender, DragEventArgs e)
        {
            if (e.Data.GetDataPresent(DataFormats.FileDrop))
            {
                e.Effect = DragDropEffects.Copy;
            }
            else
            {
                e.Effect = DragDropEffects.None;
            }
        }

        private void FormThree_Load(object sender, EventArgs e)
        {
        }
    }

现在的问题是 当我点击“radMenuItem1”加载我的表格FormThree它说 “DragDrop注册没有成功。”为什么以及如何解决这个问题......

1 个答案:

答案 0 :(得分:0)

在每个应用程序启动时启动您的应用程序 在您的Main方法中执行:

Application.Run(new MainForm3()); 

构造函数中没有参数,然后在MainForm3构造函数中(在InitializeComponent之前)执行登录,打开一个专用模式表单以获取继续所需的登录凭据。

如果登录失败,您可以通知用户并使用Application.Exit()关闭应用程序。 如果登录成功,请阅读MainForm3所需的值。无需开始另类 螺纹