How can i show form Dynamically by passing string in roslyn project code
-
Mittwoch, 7. Dezember 2011 11:05
hi,
i want to show form by giving form name as string in roslyn code but i am getting some error on below code.
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; using Roslyn.Compilers; using Roslyn.Compilers.CSharp; using Roslyn.Scripting; using Roslyn.Scripting.CSharp; namespace WindowsFormsApplication7 { public partial class Form1 : Form { public Form1() { InitializeComponent(); ScriptEngine scriptEngine = new ScriptEngine(); Session mySession = Session.Create(); string f =""; f = @" Form2 frm = new Form2(); frm.Show();"; scriptEngine.Execute(f); } } }
Alle Antworten
-
Mittwoch, 7. Dezember 2011 15:26
The ScriptEngine has its own set of assembly references and usings. So, if you want to instantiate the form, you can do something like this:
ScriptEngine scriptEngine =
new ScriptEngine(
new[]
{
Assembly.GetExecutingAssembly(),
typeof(Form).Assembly, // System.Windows.Forms
typeof(Uri).Assembly // System
});
string f = @"
using WindowsFormsApplication7;
Form2 frm = new Form2();
frm.Show();";
scriptEngine.Execute(f);- Bearbeitet svick Mittwoch, 7. Dezember 2011 15:27 fixed namespace
- Als Antwort vorgeschlagen Shyam NamboodiripadMicrosoft Employee, Owner Mittwoch, 7. Dezember 2011 20:16

