How to open a program into a XAML c# window -
i using visual studio 2015 rc (wpf application c#) , want program open of apps (with click of button) app window, code below unfinished.
the problem happens when click button, notepad opens randomly in it's own window, , not in app's canvas.
main.window.xaml:
<window x:class="stackoverflowquestion1.mainwindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:local="clr-namespace:stackoverflowquestion1" mc:ignorable="d" title="mainwindow" height="350" width="525"> <grid> <grid.columndefinitions> <columndefinition width="0*"/> <columndefinition/> </grid.columndefinitions> <menu x:name="menu" horizontalalignment="left" height="22" margin="2,10,0,0" verticalalignment="top" width="497" grid.column="1"> <button x:name="button" click="button_click" width="187">click here open notepad below</button> </menu> <canvas grid.columnspan="2" horizontalalignment="left" height="257" margin="10,52,0,0" verticalalignment="top" width="489" background="black"/> </grid></window>
mainwindow.xaml.cs:
using system; using system.collections.generic; using system.diagnostics; using system.linq; using system.text; using system.threading.tasks; using system.windows; using system.windows.controls; using system.windows.data; using system.windows.documents; using system.windows.input; using system.windows.media; using system.windows.media.imaging; using system.windows.navigation; using system.windows.shapes; namespace stackoverflowquestion1 { public partial class mainwindow : window { public mainwindow() { initializecomponent(); } private void button_click(object sender, routedeventargs e) { process.start("notepad.exe"); } } }
found answer, here code:
using system; using system.diagnostics; using system.runtime.interopservices; using system.threading; using system.windows.forms; namespace windowsformsapplication1 { public partial class form1 : form { public form1() { initializecomponent(); } private void button1_click(object sender, eventargs e) { process p = process.start("notepad.exe"); p.waitforinputidle(); // allow process open it's window setparent(p.mainwindowhandle, this.handle); } [dllimport("user32.dll")] static extern intptr setparent(intptr hwndchild, intptr hwndnewparent); } }
final notes, used windows forms application c#, not windows wpf application, phew im glad found answer haha gl everyone
Comments
Post a Comment