2011-03-10 49 views
3

我設計了一個windows窗體,其中我放置了3個按鈕和一個richtextBox。
現在我想獲取程序代碼在richtextbox上點擊不同的按鈕,即我在每個按鈕的click()事件中寫入的。獲取C#中按鈕單擊的程序代碼

private void button1_Click(object sender, ButtonEventArgs e) 
{ 
     some code lines goes here // 
     ....      // All these lines to be displayed in richtextBox 
     ....      // 
} 
+0

你想讓你的程序打印出源代碼,對嗎?當你點擊一個按鈕? – 2011-03-10 01:27:40

+0

@ 0A0D:是的,你是對的。 – 2011-03-10 01:29:05

+0

這被稱爲奎因。看到這裏:http://stackoverflow.com/questions/753467/the-shortest-program-that-prints-its-own-source-code-in-c – 2011-03-10 01:30:31

回答

2

我認爲你必須真正鏈接和閱讀的源文件做到這一點。一旦您的應用程序編譯完成,您的C#代碼將變成IL代碼,並且看起來完全不一樣。

0

當你執行它時,由於它被編譯成IL,所以如果你想在單擊按鈕時顯示一個字符串,那麼它就沒有源了,那麼就這樣做。

richTextBox.Text = @"some code lines goes here... 
... 
..."; 
相關問題