Hi, I am developping an image viewer and everithing is working fine.
Now, i associated this application with all jpg files. It's fine too. But when the application is launched, the image is not being opened.
I supose that i have to do something like this:

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs)
dim filepath as string= (That is what i need. How to get the file from where the application has been launched)
End Sub

Anyone can help me?

try using this

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
dim filepath as string= Application.StartupPath & "filename"
    End Sub

That's geting the application exe file path and not the image file i opened the aplication from.
Thanks however.
Any new suggestions?


When you have created a new image folder in the Bin folder of your application, then you need to use this part of code. foldername is your image folder and imagename is the image you want to load at first.

PictureBox1.Image = System.Drawing.Image.FromFile(Application.StartupPath & "\foldername\imagename.jpg")

However, when you added directly your image in the bin folder then you need to use the code like this:

PictureBox1.Image = System.Drawing.Image.FromFile(Application.StartupPath & "\imagename.jpg")

You can pass commandline arguments to WinForms apps:

Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
    Dim Args() As String

    Args = Environment.CommandLine.Split(CChar(" ")) ' Split arguments (space separated)

    ' Args(0) is application's name
    If Args.Length > 1 Then
      ' Pass the image file's name as an argument
      PictureBox1.Image = Image.FromFile(Args(1))
    End If

  End Sub

The whole commandline is in the Environment.CommandLine string, which you'll have to split in order to get each separate argument. The first "argument" is always the executable's name.


Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.