2013-02-10 63 views
1

我使用MCS版本2.10.8.1,我有以下代碼:的InitializeComponent不會在目前情況下在Ubuntu 12.04中存在,使用單聲道C#編譯器

using System; 
using System.Drawing; 
using System.Windows.Forms; 

namespace WindowsFormsApplication1 
{ 
    public partial class Form1 : Form 
    { 
     public Form1() 
     { 
      InitializeComponent(); 
     } 

     private void button1_Click(object sender, EventArgs e) 
     { 
      OpenFileDialog dlg = new OpenFileDialog(); 
      dlg.ShowDialog(); 

      if (dlg.ShowDialog() == DialogResult.OK) 
      { 
       string fileName; 
       fileName = dlg.FileName; 
       MessageBox.Show(fileName); 
      } 
     } 
    } 
} 

我編譯使用命令

$ mcs source_code.cs -r:System.Windows.Forms.dll -r:System.Drawing.dll 

我收到錯誤

source_code.cs(11,13): error CS0103: The name `InitializeComponent' does not exist in the current context 
Compilation failed: 1 error(s), 0 warnings 

我使用Visual巴斯看到許多這個問題的答案的情況下C;我想知道我應該如何解決這個問題。謝謝。

回答

2

您的C#代碼最初是在Visual Studio中創建的嗎?如果是這樣,那麼您可能會有一個Form1.Designer.cs文件以及包含您手動編寫的代碼的文件。您需要將該文件包含在命令行中。

如果本來不是在Visual Studo創建 C#代碼,你甚至可能不會有一個InitializeComponent方法...但在這種情況下,你需要更多的代碼做任何有用的形式(如創建該按鈕並連接其事件Click)。

+0

我認爲它一定是從MSVS導入的,由「partial」關鍵字來判斷。 – antonijn 2013-02-10 09:59:24

+0

@Antonijn:看起來它*可能*是 - 但你可以很容易地手寫部分類... – 2013-02-10 09:59:56

相關問題