Call of Duty for a beginner

Hello,
I have a problem here, i don't know how to write a code to launch programs from a tool strip item that was gotten when the form was loaded by a mouse click, the code is:

Private Sub form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

For Each filesfound As String In My.Computer.FileSystem.GetFiles("C:\", FileIO.SearchOption.SearchTopLevelOnly, "*.*")
Dim fileico As Drawing.Icon = System.Drawing.Icon.ExtractAssociatedIcon(filesfound)
Dim fileimage As Bitmap = fileico.ToBitmap()
Dim filename As String = IO.Path.GetFileNameWithoutExtension(filesfound)
Dim item As ToolStripItem = filestsmi.DropDownItems.Add(filename, fileimage)
Next
end sub

Can you help?
For the ones who could, please i need full code.

[840 byte] By [Zooz] at [2007-12-28]
# 1
Your Form needs to have a ToolStrip and a ToolStripDropDownButton (in your code, the toolstripdropdownbutton seems to be named 'filestsmi' but I'll use the default name) and then the code will work:

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

For Each filesfound As String In My.Computer.FileSystem.GetFiles("C:\", FileIO.SearchOption.SearchTopLevelOnly, "*.*")

Dim fileico As Drawing.Icon = System.Drawing.Icon.ExtractAssociatedIcon(filesfound)
Dim fileimage As Bitmap = fileico.ToBitmap()
Dim filename As String = IO.Path.GetFileNameWithoutExtension(filesfound)
Dim item As ToolStripItem = ToolStripDropDownButton1.DropDownItems.Add(filename, fileimage)
Next

End Sub

nogChoco at 2007-9-4 > top of Msdn Tech,Visual Basic,Visual Basic Language...
# 2

It is not my problem, the toolstrip things, all of them, i have them in the design mode.

My problem is:

I want when i click on these tool strip items, i want them to launch

I think using the process.start

Zooz at 2007-9-4 > top of Msdn Tech,Visual Basic,Visual Basic Language...
# 3
hi,

try using the shell function

dave.
DavePatricio at 2007-9-4 > top of Msdn Tech,Visual Basic,Visual Basic Language...
# 4

Well, i know that i may use shell or process.start but what i need is:

When i click on the toolstrip item that was gotten from the code, i want to launch.

Zooz at 2007-9-4 > top of Msdn Tech,Visual Basic,Visual Basic Language...
# 5
More info on starting a program: http://www.devx.com/dotnet/Article/7914

Try this (it'll also start the associated program if you click on a file that isn't an .exe). I'm simply storing the program's full path in the toolstripitem's tag but if you want to have additional commandline arguments passed along, the code will need some adjustment.


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

For Each filesfound As String In My.Computer.FileSystem.GetFiles("C:\", FileIO.SearchOption.SearchTopLevelOnly, "*.*")

Dim fileico As Drawing.Icon = System.Drawing.Icon.ExtractAssociatedIcon(filesfound)
Dim fileimage As Bitmap = fileico.ToBitmap()
Dim filename As String = IO.Path.GetFileNameWithoutExtension(filesfound)
Dim item As ToolStripItem = ToolStripDropDownButton1.DropDownItems.Add(filename, fileimage)
item.Tag = IO.Path.GetFullPath(filesfound)
AddHandler item.Click, AddressOf LaunchProgram
Next

End Sub

Public Sub LaunchProgram(ByVal zClickedToolStripItem As Object, ByVal e As System.EventArgs)
Try
Dim zFullPath As String = zClickedToolStripItem.tag
System.Diagnostics.Process.Start(zFullPath)
Catch ex As Exception
MsgBox("Well that one didn't work :(")
End Try
End Sub

nogChoco at 2007-9-4 > top of Msdn Tech,Visual Basic,Visual Basic Language...