Solved

opening a web browser on windows form load.

Posted on 2010-09-10
18
754 Views
Last Modified: 2012-05-10
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.
0
Comment
Question by:MEDIZ
  • 8
  • 6
  • 4
18 Comments
 
LVL 3

Expert Comment

by:packratt_jk
ID: 33649152
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
 
LVL 65

Accepted Solution

by:
rockiroads earned 500 total points
ID: 33649155
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
 
LVL 65

Expert Comment

by:rockiroads
ID: 33649172
0
 

Author Comment

by:MEDIZ
ID: 33649206
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
 
LVL 65

Expert Comment

by:rockiroads
ID: 33649212
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
 
LVL 65

Expert Comment

by:rockiroads
ID: 33649231
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
 

Author Comment

by:MEDIZ
ID: 33649249
Dear packratt_jk,

still different browsers are opening on each click.

Thanks for your post.
0
 
LVL 65

Expert Comment

by:rockiroads
ID: 33649307
dont know if this is feasible, probably wont loo too elegant, kill the existing process and create a new one
0
 

Author Comment

by:MEDIZ
ID: 33649314
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
Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

 

Author Comment

by:MEDIZ
ID: 33649337
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
 
LVL 65

Expert Comment

by:rockiroads
ID: 33649357
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
 
LVL 3

Expert Comment

by:packratt_jk
ID: 33650885
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
 

Author Comment

by:MEDIZ
ID: 33650987
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
 
LVL 3

Expert Comment

by:packratt_jk
ID: 33651166
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
 
LVL 3

Expert Comment

by:packratt_jk
ID: 33651181
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
 
LVL 65

Expert Comment

by:rockiroads
ID: 33651819
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
 

Author Comment

by:MEDIZ
ID: 33688141
hello rockiroads,

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

Thanks
0
 
LVL 65

Expert Comment

by:rockiroads
ID: 33688173
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

Featured Post

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

Introduction Hi all and welcome to my first article on Experts Exchange. A while ago, someone asked me if i could do some tutorials on object oriented programming. I decided to do them on C#. Now you may ask me, why's that? Well, one of the re…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…

708 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now