2011-03-10 50 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... 
... 
..."; 
相关问题