opening a web browser on windows form load.

Hello All,

I'm currently using Windows forms and on click of display button of the main frame I need to open a new form. But now we thought of going to web where we have a  requirement to show web browser on click of display button instead of the win form.

for this purpose I used process.start("http://www.google.com") where on each click single instance of the web page is being displayed.

I want to show only one instance.  I'm using 2005 .net.

Can any body help me out in this issue. I don't want winform to be displayed but it needs to supress win form load and needs to load web browser.

Thanks in advance.
MEDIZAsked:
Who is Participating?

Improve company productivity with a Business Account.Sign Up

x
 
rockiroadsConnect With a Mentor Commented:
Have you thought of using a web browser control within your own form? that way you just set the url on that control whenever you want and so you will only ever have that one page showing

0
 
packratt_jkCommented:
Try setting the shell execute flag:

System.Diagnostics.Process proc = new System.Diagnostics.Process();
 proc.StartInfo.FileName = "http://www.google.com";
 proc.StartInfo.UseShellExecute = true;
 proc.Start();
0
Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

 
MEDIZAuthor Commented:
Dear rockiroads,

I thought of using WebBrowser control but my team doesn't like it.

thanks for your post.
 
Dear packratt_jk,

I'm trying to implement your solution.

Thanks for your post.
0
 
rockiroadsCommented:
when u use Process.Start it returns a Process object. Is it possible to use that process object to reload? maybe perform a start on that process object?
0
 
rockiroadsCommented:
what browser are you using?

I tried what I suggested and it used the same window but created a new tab (IE8)

        Dim myProcess As Process = Process.Start("www.google.com")
        MsgBox("Wait")
        myProcess.Start("www.bbc.co.uk")
0
 
MEDIZAuthor Commented:
Dear packratt_jk,

still different browsers are opening on each click.

Thanks for your post.
0
 
rockiroadsCommented:
dont know if this is feasible, probably wont loo too elegant, kill the existing process and create a new one
0
 
MEDIZAuthor Commented:
Dear packratt_jk,

I'm using IE7.  Is there any way to reload same page or just highlight already opened page from the next click of the button.

0
 
MEDIZAuthor Commented:
Dear  rockroads,

If there are two different iexplore processes running how can the system knows which one is the correct one to kill.

thanks,
0
 
rockiroadsCommented:
Process.start returns the process object, from that you should be able to identify

Maybe use WebBrower as a object instead of a form control

        Dim x As New WebBrowser
        x.Navigate("www.google.com")

now if you did x.Navigate("www.bbc.co.uk") later on, does that work? I think so but not 100% sure
0
 
packratt_jkCommented:
My guess is IE is set to open new windows in a new window, where rockiroads has his set to open in a new tab.  If you want the link to open in the existing window, you would need some kind of link back to it, like rockiroads suggests.

WebBrowser will not do it, however.  I think for that you would need an api for IE (I haven't seen such a thing).

One thing you could do (although it's a bit hacky) would be to do this:
Create a file with the url you want to navigate to.
Create a javascript that checks for this file every so often, and when found navigates to that url.

Then later when you want to change the page, just copy in a new file.

You'd probably also want to keep the process reference around too, so if the user closes the browser you can open it again.

Not a great solution, but it should work.
0
 
MEDIZAuthor Commented:
Dear packratt_js,

I didn't understand how to do that file concept.

Usually I will open a new form for all the rest of the screen which we kept in a workflow.

but only for this workflow item I suppressed the form and trying to open a new web browser.

but when I go back and clicked on the workflow item again new browser or a new browser tab is getting opened.

can you please tell me how to do that file stuff.

thanks,
0
 
packratt_jkCommented:
Honestly, you'd probably spend hours getting it to work, and even then I'm not sure it would work very well.

Is there a particular reason management doesn't want to have the website appear in a form?
0
 
packratt_jkCommented:
For your reference, it would look something like this:

<html>
<head>
<script type="text/javascript">
function loadXMLDoc()
{
if (window.XMLHttpRequest)
  {// code for IE7+, Firefox, Chrome, Opera, Safari
  xmlhttp=new XMLHttpRequest();
  }
else
  {// code for IE6, IE5
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
xmlhttp.onreadystatechange=function()
  {
  if (xmlhttp.readyState==4 && xmlhttp.status==200)
    {
      if(document.getElementById("myFrame").src != xmlhttp.responseText)
{
    document.getElementById("myFrame").src = xmlhttp.responseText;
}
loadXmlDoc();
    }
  }
xmlhttp.open("GET","static_page_url.txt",true);
xmlhttp.send();
}
</script>
</head>
<body onLoad="loadXMLDoc()">

<frame id="myFrame" width="100%" height="100%"></frame>
</body>
</html>
0
 
rockiroadsCommented:
okay thought long and hard about this and thought I how used this idea in vb, use references in particular ie (vb.net example given)

if you are happy to use ie then we can use the microsoft internet controls reference (you need to add it)

then define a class level variable eg
    Dim ie As SHDocVw.InternetExplorer

You can instantiate it in the forms new method if you want

then when you want to load a url call a function to do it for you like this

    Private Sub loadIEUrl(ByVal sUrl As String)
        Try
            ie.Navigate2(sUrl)
            ie.Visible = True
        Catch ex As System.Runtime.InteropServices.COMException
            ie = New SHDocVw.InternetExplorer
            ie.Navigate2(sUrl)
            ie.Visible = True
        End Try

    End Sub

Note I check for comexception this is because the user may close the ie browser manually therefore navigating will cause an error

I tested this using ie and multiple tabs and each time the same tab was loaded even if it didnt have focus

0
 
MEDIZAuthor Commented:
hello rockiroads,

sorry for the delay in posting email. let me try this and I will update you on the output.

Thanks
0
 
rockiroadsCommented:
hopefully it works for you as this really got me racking my brains. so much so I had to get a beer to relax :)
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.