I want to make a winform by C#, and add a ironpython console window in it, like a multiline textbox. So I can write python program into it to do some operations in my Winform software.
How can I do that? Thanks.
affixture:
I created a opensource project IpyIF, Ironpython Interacti开发者_如何学运维ve Window.http://ipyiw.codeplex.com/
maybe you could start here.
Quickstart: You need a string with your code from your textbox in "script". Add references from IronPython, IronPython.Modules, Microsoft.Scripting and Microsoft.Scripting.Core to your project.
ScriptRuntime runtime = IronPython.Hosting.Python.CreateRuntime();
ScriptScope scope = runtime.GetEngine("py").CreateScope();
ScriptSource source = engine.CreateScriptSourceFromString(script,
Microsoft.Scripting.SourceCodeKind.Statements);
source.Execute(scope);
a real console is included in the CodePlex-Samples
Thanks a lot. I got it by myself.
I use two TextBox, one is to input code of ironpython, another is to redirect the ironpython output.
If someone want to know how to redirection, look this: How can I redirect the stdout of IronPython in C#?
精彩评论