Results 1 to 16 of 16

Thread: [RESOLVED] [2008] Launch browser with button click

Hybrid View

  1. #1

    Thread Starter
    New Member
    Join Date
    Feb 2008
    Posts
    11

    Resolved [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 in advance.

  2. #2
    Raging swede Atheist's Avatar
    Join Date
    Aug 2005
    Location
    Sweden
    Posts
    8,018

    Re: [2008] Launch browser with button click

    If you want to run the HTML file in the default browser, just execute it with Process.Start:
    vb Code:
    1. Process.Start("someFile.html")
    Me.Close would be the correct way of closing a form yes.
    And no, I dont think theres a simple way of enforcing the browser to allow active content.
    Rate posts that helped you. I do not reply to PM's with coding questions.
    How to Get Your Questions Answered
    Current project: tunaOS
    Me on.. BitBucket, Google Code, Github (pretty empty)

  3. #3

    Thread Starter
    New Member
    Join Date
    Feb 2008
    Posts
    11

    Re: [2008] Launch browser with button click

    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

  4. #4
    Raging swede Atheist's Avatar
    Join Date
    Aug 2005
    Location
    Sweden
    Posts
    8,018

    Re: [2008] Launch browser with button click

    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.
    Rate posts that helped you. I do not reply to PM's with coding questions.
    How to Get Your Questions Answered
    Current project: tunaOS
    Me on.. BitBucket, Google Code, Github (pretty empty)

  5. #5

    Thread Starter
    New Member
    Join Date
    Feb 2008
    Posts
    11

    Re: [2008] Launch browser with button click

    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.

    vb Code:
    1. Process.Start("index.htm")

  6. #6
    Raging swede Atheist's Avatar
    Join Date
    Aug 2005
    Location
    Sweden
    Posts
    8,018

    Re: [2008] Launch browser with button click

    Then it cant be in the same folder.
    Put this line in there:
    vb Code:
    1. MessageBox.Show(Application.StartupPath)
    Then verify that the html file exists on that path.
    Rate posts that helped you. I do not reply to PM's with coding questions.
    How to Get Your Questions Answered
    Current project: tunaOS
    Me on.. BitBucket, Google Code, Github (pretty empty)

  7. #7

    Thread Starter
    New Member
    Join Date
    Feb 2008
    Posts
    11

    Re: [2008] Launch browser with button click

    All works well now, thank you very much!

  8. #8

    Thread Starter
    New Member
    Join Date
    Feb 2008
    Posts
    11

    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.
    --------------------------------------------------------------------
    Attached Images Attached Images  

  9. #9
    Raging swede Atheist's Avatar
    Join Date
    Aug 2005
    Location
    Sweden
    Posts
    8,018

    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:
    1. Dim psi As New ProcessStartInfo("\site\index.htm")
    2.         psi.WindowStyle = ProcessWindowStyle.Maximized
    3.         Process.Start(psi)
    And to your final question, could you elaborate a bit? Im not sure I understand.
    Rate posts that helped you. I do not reply to PM's with coding questions.
    How to Get Your Questions Answered
    Current project: tunaOS
    Me on.. BitBucket, Google Code, Github (pretty empty)

  10. #10

    Thread Starter
    New Member
    Join Date
    Feb 2008
    Posts
    11

    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:
    1. Public Class CD
    2.     Dim psi As New ProcessStartInfo("\site\index.htm")
    3.     Private Sub MenuButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MenuButton.Click
    4.         'MessageBox.Show(Application.StartupPath)
    5.         psi.WindowStyle = ProcessWindowStyle.Maximized
    6.         Process.Start(psi)
    7.         'Process.Start("\site\index.html")
    8.         Me.Close()
    9.     End Sub
    10. 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.

  11. #11
    Raging swede Atheist's Avatar
    Join Date
    Aug 2005
    Location
    Sweden
    Posts
    8,018

    Re: [RESOLVED] [2008] Launch browser with button click

    So it throws an exception? What is the error message?
    Rate posts that helped you. I do not reply to PM's with coding questions.
    How to Get Your Questions Answered
    Current project: tunaOS
    Me on.. BitBucket, Google Code, Github (pretty empty)

  12. #12

    Thread Starter
    New Member
    Join Date
    Feb 2008
    Posts
    11

    Re: [RESOLVED] [2008] Launch browser with button click

    The error is attached - does this give enough information?
    Attached Images Attached Images  

  13. #13
    Raging swede Atheist's Avatar
    Join Date
    Aug 2005
    Location
    Sweden
    Posts
    8,018

    Re: [RESOLVED] [2008] Launch browser with button click

    Well that error pretty much says it all . The path/file you provided doesnt exist. Remember what I posted in post #4 and #6.
    Rate posts that helped you. I do not reply to PM's with coding questions.
    How to Get Your Questions Answered
    Current project: tunaOS
    Me on.. BitBucket, Google Code, Github (pretty empty)

  14. #14

    Thread Starter
    New Member
    Join Date
    Feb 2008
    Posts
    11

    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!?

  15. #15
    Raging swede Atheist's Avatar
    Join Date
    Aug 2005
    Location
    Sweden
    Posts
    8,018

    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
    Rate posts that helped you. I do not reply to PM's with coding questions.
    How to Get Your Questions Answered
    Current project: tunaOS
    Me on.. BitBucket, Google Code, Github (pretty empty)

  16. #16

    Thread Starter
    New Member
    Join Date
    Feb 2008
    Posts
    11

    Re: [RESOLVED] [2008] Launch browser with button click

    Ok thanks. Any idea on why the launched browser is not maximising? Do I have your code correct?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width