Например, в Form1.cs:
Код: Выделить всё
using System.Windows.Forms;
...
public int[] someCoords = { 20, 10 };
public string someImportantString = "Hello";
public void SayHello() {
MessageBox.Show("Hello world.");
}
private void runCodeInForm() {
// theCode will be read from a text file
string theCode = @"
// Has System.Windows.Forms already added in form
Button newButton = new Button();
newButton.Text = someImportantString; // Hello
newButton.Location = new Point(someCoords[0], someCoords[1]); // 20, 10
// Add this button to the current form
this.Controls.Add(newButton);
this.SayHello(); // Says hello. Just an example function.
";
// Execute theCode in the current form
CodeRunner.Execute(theCode, this);
}
Мне бы этого хотелось, потому что я хочу, чтобы пользователь мог изменить этот код (текстовый файл) на то, что ему хочется. Это не просто создание элементов управления, но эта функциональность будет необходима.
Меня не беспокоит безопасность программы.
Подробнее здесь: https://stackoverflow.com/questions/509 ... rrent-form
Мобильная версия