[RESOLVED] [2008] Launch browser with button click
I am very new at VB, using VB 2008 Express. I have created a very simple splash window (form) which will reside on a CD and autorun. It contains one button which should launch the index.htm file from a folder on the same CD. I have searched through help in VB which I find poor, and on the net where most examples are very complicated. I understand that the ShellExecute API must be used so the default browser software is started.
The form should close once the browser is activated. Is using the following correct: Me.Close()
Is it also possible to force the browser to allow active content instead of it stopping the load of flash movies and Spry widgets until the user enables active content?
Thanks. I still have two problems with the code below;
- it cannot find the index.htm file, I have it in a sub folder of the folder containing the VB project files, do I need to reference it differently?
- it says I have a syntax error with the Me.close line, does it have to be declared somehow?
- also, will the user need .Net 3.5 installed on their PC or will this very simple app work with ealier versions (2.0)?
Code:
Public Class CD
Private Sub MenuButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MenuButton.Click
Process.Start("\site\index.htm")
End Sub
Me.close
End Class
1. You need to know the location of the html file relatively to the location of your EXE file. You're most likely running Debug mode now, so the executable of your project will run from the bin/debug path of your project folder.
2. Me.Close (nor any other method call) line can not be placed outside any method body. Place it underneath the Process.Start() line instead.
3. You will have to go into the project properties and target a lower framework. The framework youre targetting will be the one the user needs to have installed, no matter how simple the application is.
Thanks, the close now works fine .
I still am unable to launch the .htm file - says it cannot be found. I removed the path (as below), built the exe and put the index.htm file in the same folder.
Re: [RESOLVED] [2008] Launch browser with button click
Re changing the target framework to a lower version; I did this but get a list of errors when I open the project as detailed below and in the screen dump attached. I don't have any idea what these errors mean, and when I published the exe it seemed to work but I have not tested on a machine which only has the .NET 2.0 framework installed (and not v3.5).
Also, is there a way to:
- force the browser (index.html file) I am opening with this form code to be full screen? I read the "Force a full screen window" post but it did not seem resolved and I assume referred to forcing the form itself to full screen rather than another application.
- force a blank or single colour screen background while my form is displayed (and have the screen revert to normal when the browser opens full screen)?
Thanks,
Derick
--------------------------------------------------------------------
Warning 1 Namespace or type specified in the project-level Imports 'System.Xml.Linq' doesn't contain any public member or cannot be found. Make sure the namespace or the type is defined and contains at least one public member. Make sure the imported element name doesn't use any aliases. CD menu
Warning 2 Could not resolve assembly System.Xml.Linq. The target framework required by this assembly (3.5) is higher than the project target framework. If this reference is required by your code, you may get compilation errors. CD menu
Warning 3 Could not resolve assembly System.Data.DataSetExtensions. The target framework required by this assembly (3.5) is higher than the project target framework. If this reference is required by your code, you may get compilation errors. CD menu
Warning 4 The referenced component 'System.Data.DataSetExtensions' could not be found.
Warning 5 The referenced component 'System.Xml.Linq' could not be found.
--------------------------------------------------------------------
Re: [RESOLVED] [2008] Launch browser with button click
Try removing the references to System.Xml.Linq and System.Data.DataSetExtensions.
You'd have to use the ProcessStartInfo class if you want more control over how your process is started:
vb Code:
Dim psi As New ProcessStartInfo("\site\index.htm")
psi.WindowStyle = ProcessWindowStyle.Maximized
Process.Start(psi)
And to your final question, could you elaborate a bit? Im not sure I understand.
Re: [RESOLVED] [2008] Launch browser with button click
Thanks. I removed the references and error warnings have gone.
I am not sure where to put your code, as I have it below it gives me this error in debug mode: A first chance exception of type 'System.ComponentModel.Win32Exception' occurred in System.dll
Am I correct to now disable the process I already had?
vb Code:
Public Class CD
Dim psi As New ProcessStartInfo("\site\index.htm")
Private Sub MenuButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MenuButton.Click
'MessageBox.Show(Application.StartupPath)
psi.WindowStyle = ProcessWindowStyle.Maximized
Process.Start(psi)
'Process.Start("\site\index.html")
Me.Close()
End Sub
End Class
Re my last Q, this form autoruns on insertion of a CD, so depending on the apps open and number of icons on the user's desktop it may not stand out very well. Forcing a blank or coloured screen with nothing else but my form would make it stand out and present it better.
Re: [RESOLVED] [2008] Launch browser with button click
Indeed, thnaks, my mistake - I simply copied your code with .htm not realising I changed to using .html However although I have no errors now the launched browser window does not maximise to full screen.
On the last Q, what do you think about forcing a blank background, if it is not simple I best not worry!?
Re: [RESOLVED] [2008] Launch browser with button click
Ah, if I understand you correctly, there'd be no other easy way to do that than to create a borderless form and maximize it. That way it'd be your entire form that occupied the entire screen, but to be honest, I personally would find that annoying