0
我打算用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註冊沒有成功。」爲什麼以及如何解決這個問題.....
我可以問你爲什麼你在不同的線程啓動MainForm3?這在您的應用程序中很難處理。 – Steve 2012-04-07 13:01:01
那麼,什麼是好的解決方案?我是初學者。 – 2012-04-07 13:06:04
只要不使用線程,就沒有意義。只需調用Show()方法即可顯示MainForm3實例。順便說一句,這個異常是因爲你忘記調用線程的SetApartmentState()使其成爲STA線程而引發的。需要支持D + D。 – 2012-04-07 13:16:04