C# 打开子窗体时出现错误
我要用telerik桌面控件制作一个桌面应用程序。 我的主要表格代码是:C# 打开子窗体时出现错误,c#,.net,winforms,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 = "
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、字符串isadmin来自登录页面
登录页面代码:
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));
}
其中三个代码是:
公共部分类表单三:Telerik.WinControls.UI.RadForm
{
公共表格三()
{
初始化组件();
splitPanel1.AllowDrop=true;
splitPanel1.DragEnter+=SplitPanel1U DragEnter;
splitPanel1.DragDrop+=SplitPanel1u DragDrop;
}
私有void splitPanel1_DragDrop(对象发送方,DragEventArgs e)
{
if(例如Data.GetDataPresent(DataFormats.FileDrop))
{
string[]filepath=(string[])(e.Data.GetData(DataFormats.FileDrop));
foreach(文件路径中的字符串fileLoc)
{
//用于读取文本文件内容的代码
if(File.Exists(fileLoc))
{
使用(TextReader tr=新的StreamReader(fileLoc))
{
字符串名称=Path.GetFileName(fileLoc);
字符串扩展名=Path.GetExtension(fileLoc);
MessageBox.Show(“名称:“+Name+”扩展:“+Extention”);
//Show(tr.ReadToEnd());
}
}
}
}
}
私有void splitpanel 1dragenter(对象发送方,DragEventArgs e)
{
if(例如Data.GetDataPresent(DataFormats.FileDrop))
{
e、 效果=DragDropEffects.Copy;
}
其他的
{
e、 效果=DragDropEffects。无;
}
}
private void FormThree_Load(对象发送方、事件参数e)
{
}
}
现在的问题是
当我点击“radMenuItem1”下载我的表单时,它会说
“DragDrop注册未成功。”为什么以及如何解决此问题……在每个应用程序启动时启动应用程序。
在您的主要方法中,请执行以下操作:
Application.Run(new MainForm3());
构造函数中没有参数,然后在MainForm3构造函数中(在InitializeComponent之前)打开专用的模式表单进行登录,以获取继续所需的登录凭据
如果登录失败,您可以通知用户并使用application.Exit()关闭应用程序。
如果登录成功,请读取MainForm3所需的值。没有必要开始另一种生活
线程我可以问一下为什么要在不同的线程上启动MainForm3吗?这在您的应用程序中可能很难处理。那么什么是好的解决方案??我是初学者。只是不要用线,没有意义。只需调用Show()方法即可显示MainForm3实例。顺便说一句,引发此异常是因为您忘记调用线程的SetApartmentState()使其成为STA线程。需要支持D+D。
Application.Run(new MainForm3());