Windows state control in WindowsApplication

Hamilton1

Member
Joined
Jul 27, 2010
Messages
5
Programming Experience
Beginner
Hi,

i am VERY NEW to VB, so please be patient with me :)

i have created a windows application, which contains buttons that open up a new browser and points it at various different links, here's a sample of it, from the top :



Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Shell("C:\Program Files\Internet Explorer\iexplore.exe http://www.hamilton.co.uk/overview.cfm")
End Sub

when the button is clicked the browser opens in minimized mode ??

my question is : how do i get the browser to open in a "normal" manner, you know middle of the screen and the right size to fit the webpage ???

hope you can help

thanks
Hamilton
 
System.Diagnostics.Process is the way to go in VB.NET.

VB.NET:
    Dim psi As System.Diagnostics.ProcessStartInfo
        Dim p As System.Diagnostics.Process

        psi.FileName = "http://www.somewhere.com"
        psi.WindowStyle = ProcessWindowStyle.Normal

        p = System.Diagnostics.Process.Start(psi)
 
Hi

thanks for the reply, i hope i have done this correctly ?? ooer ! this is now how my code looks :

Public Class Form1

Dim psi As System.Diagnostics.ProcessStartInfo
Dim p As System.Diagnostics.Process
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
psi.FileName = "http://www.hamilton.co.uk/overview.cfm"
psi.WindowStyle = ProcessWindowStyle.Normal
p = System.Diagnostics.Process.Start(psi)
End Sub

thinking this to be correct, i ran a debug?? and i got the following Error message :

An unhandled exception of type 'System.NullReferenceException' occurred in Hamilton Pop-up.exe

Additional information: Object reference not set to an instance of an object.

it also highlights the line : psi.FileName = "http://www.hamilton.co.uk/overview.cfm"

please could you help me again and explain how/where i have gone wrong ??

thanks
Hamilton
 
i also have warnings showing : Warning Variable 'psi' is used before it has been assigned a value. A null reference exception could result at runtime.
 
Do you want "http://www.hamilton.co.uk/overview.cfm" to open in the user's default browser? Or do you want it to be opened in a specific browser (like IE, FF, Chrome)?

The reason I ask is because your first post shows you trying to open it specifically in IE then in your latest code post you're only passing the url (which will be opened in the user's default browser)

If you dont care what browser it's opened in:
VB.NET:
    Private Prc As Diagnostics.Process

    Private Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
        Prc = Diagnostics.Process.Start(New Diagnostics.ProcessStartInfo("http://www.hamilton.co.uk/overview.cfm") With {.WindowStyle = ProcessWindowStyle.Normal})
    End Sub
If you do want a specific browser:
VB.NET:
    Private Prc As Diagnostics.Process

    Private Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
        'Replace "iexplore.exe" with the path of the other browser if you dont want IE to be opened
        Prc = Diagnostics.Process.Start(New Diagnostics.ProcessStartInfo("iexplore.exe", "http://www.hamilton.co.uk/overview.cfm") With {.WindowStyle = ProcessWindowStyle.Normal})
    End Sub
Also, does the window style really matter?

Edit: Forgot to include the specific browser arg code example.
 
No.

VB.NET:
 'This will open a new IE application window whether there is already an IE application running or not, and go to the relevant address passed as the argument
        'Dim psi As New System.Diagnostics.ProcessStartInfo("iexplore.exe", "http://www.hamilton.co.uk/overview.cfm")

        'If the current default webbrowser has an active application running it willl use that process to open the page.
        ' If there isn't a current process then it start a new one to open the page.
        Dim psi As New System.Diagnostics.ProcessStartInfo("http://www.hamilton.co.uk/overview.cfm")
        Dim p As System.Diagnostics.Process

        psi.WindowStyle = ProcessWindowStyle.Normal

        p = System.Diagnostics.Process.Start(psi)

If you want to always open a new browser application and go the address then for the StartInfo you need to pass the browser exe as the filename (IE = iexplore.exe, FireFox=firefox.exe) and the url as the arguments.
 
thanks all, awesome response's ! truly grateful !

Ok so now i have a fully working App, thansk again for your help, i am sure i will be back :eek::eek:

Hamilton
 
Back
Top