Reputation: 2832
I'm developing a web site as well as windows application and i'm going to use same web page for windows form application as well as for web site.
so i want to call the windows form control after clicking on the link which is placed on the web page. And i want to show the windows form control as a pop up form.
How to do this? Or provide some document related to this issue.
Upvotes: 1
Views: 7376
Reputation: 6548
You can display Windows Form in Web Browser (Internet Explorer Preferred) by using WPF Browser Application which have a facility to embed Windows Forms (or similar like .NET Components).
This is a valid Question because there are lots of Legacy .NET Applications which company don't have resources to be developed for Web HTML 5 format (using AJAX etc). Such legacy applications can be easily displayed in a web browser with a minor initial setup required.
Let me know if you want me to create a video tutorial to achieve the same.
Upvotes: 0
Reputation: 65712
I think your getting confused - or we are.
"I have web page which i designed for web application and i'm going to open the same web page in the web browser control which will be placed on the one of form of windows form application. And if i open the form which is having my web site page and i clicked on the link from the web page then that time it should open the another form from the windows application"
So you know the link that will be clicked? Then in the WebBrowser Navigating Method check if its the link you were expecting and open the WinForm, eg:
private void webBrowser1_Navigating(object sender, WebBrowserNavigatingEventArgs e)
{
if (e.Url.Tostring() == "http://localhost/LinkThatOpensFormTwo.htm")
{
Form2 f = new Form2();
f.Show();
Upvotes: 0
Reputation: 45789
Assuming you mean that within your WinForms application you're hosting an instance of the WebBrowser
class, you can provide an object to its ObjectForScripting
property. that provides a method to call to trigger your WinForms code. For example:
public partial class MyWindowsFormsForm()
{
public MyWindowsFormsForm()
{
this.WebBrowserControl.ObjectForScripting = this;
}
public void DoSomething()
{
MyOtherForm f = new MyOtherForm();
f.Show();
}
}
Then, in your page:
<script language="javascript" type="text/javascript">
function loadOtherForm()
{
if (RunningInWinFormsApplication())
{
window.external.DoSomething();
}
else
{
// Code to do something when NOT running inside the WinForms app could go here
}
}
function RunningInWinFormsApplication()
{
return (window.external.DoSomething != undefined);
}
</script>
<button onclick="loadOtherForm();">Call into WinForms app</button>
There's the obvious caveat that you'll need to have code in your web page that checks to ensure that window.external.DoSomething
is actually there, so likely your onclick
(in this example) would call a helper method that either calls into WinForms, or does whatever needs doing in the event that the page isn't being hosted inside your application.
Upvotes: 1