|
-
Nov 10th, 2018, 12:15 PM
#1
Addicted Member
Re: Use Run Task in Background
It's almost the same, just put the code I gave you in the SelectedIndexChanged of the ListBox and you're fine. Something like this: (change the listbox items names to your actual names)
Code:
Private Sub ListBox1_SelectedIndexChanged(sender As System.Object, e As System.EventArgs) Handles ListBox1.SelectedIndexChanged
Dim UserCmd As String = ListBox1.Text
Select Case UserCmd
Case "Command Prompt"
Process.Start(Environment.GetFolderPath(Environment.SpecialFolder.System) & "\cmd.exe")
Case "System Configuration"
Process.Start(Environment.GetFolderPath(Environment.SpecialFolder.System) & "\msconfig.exe")
Case "System Information"
Process.Start(Environment.GetFolderPath(Environment.SpecialFolder.System) & "\msinfo32.exe")
Case "Documents"
Process.Start(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments))
Case "Drive C:\"
Process.Start("C:\")
Case "Management Console"
Process.Start(Environment.GetFolderPath(Environment.SpecialFolder.System) & "\wmimgmt.msc")
End Select
End Sub
Now your user just need to click "System Configuration" item and msconfig will run.
Hope that helps
-
Nov 10th, 2018, 09:02 PM
#2
Re: Use Run Task in Background
 Originally Posted by cPubis
It's almost the same, just put the code I gave you in the SelectedIndexChanged of the ListBox and you're fine.
That's really not a good idea. I know that it addresses the OP's request but the request is bad. What if the user has already selected the first item in the list and they want to selected the last item using the keyboard? A developer should never assume that the mouse will always be used for something that the keyboard can be used for too. In that case, your code would execute every single command when the user only wants the last one.
-
Nov 10th, 2018, 10:02 PM
#3
Addicted Member
Re: Use Run Task in Background
 Originally Posted by jmcilhinney
A developer should never assume that the mouse will always be used for something that the keyboard can be used for too.
I agree, but as you said it was the OP's request.
Now kshadow22, in case you didn't figure out how to avoid this, here you go:
Code:
Public Class Form1
Private Sub ListBox1_DoubleClick(sender As Object, e As System.EventArgs) Handles ListBox1.DoubleClick
RunTool()
End Sub
Private Sub ListBox1_KeyDown(sender As Object, e As System.Windows.Forms.KeyEventArgs) Handles ListBox1.KeyDown
If e.KeyCode = Keys.Enter Then
RunTool()
End If
End Sub
Private Sub RunTool()
Dim UserCmd As String = ListBox1.Text
Select Case UserCmd
Case "Command Prompt"
Process.Start(Environment.GetFolderPath(Environment.SpecialFolder.System) & "\cmd.exe")
Case "System Configration"
Process.Start(Environment.GetFolderPath(Environment.SpecialFolder.System) & "\msconfig.exe")
Case "System Information"
Process.Start(Environment.GetFolderPath(Environment.SpecialFolder.System) & "\msinfo32.exe")
Case "Documents"
Process.Start(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments))
Case "Drive C:\"
Process.Start("C:\")
Case "Managment Console"
Process.Start(Environment.GetFolderPath(Environment.SpecialFolder.System) & "\wmimgmt.msc")
End Select
End Sub
End Class
Now you can select the item and press Enter or just double click the item.
Hope that helps.
-
Nov 10th, 2018, 10:40 PM
#4
Re: Use Run Task in Background
 Originally Posted by cPubis
I agree, but as you said it was the OP's request.
I would suggest we should point out to the OP the shortcomings of their request even if we provide a solution. It would be far from ideal if they just accepted that solution, implemented it, deployed it and then had users complaining that it didn't work.
-
Nov 10th, 2018, 10:45 PM
#5
Addicted Member
Re: Use Run Task in Background
 Originally Posted by jmcilhinney
I would suggest we should point out to the OP the shortcomings of their request even if we provide a solution. It would be far from ideal if they just accepted that solution, implemented it, deployed it and then had users complaining that it didn't work.
I unreservedly agree with that.
-
Nov 11th, 2018, 03:41 PM
#6
Re: Use Run Task in Background
 Originally Posted by cPubis
I unreservedly agree with that.
That said, you should be teaching the OP how to correctly build paths.
-
Nov 11th, 2018, 09:24 PM
#7
Addicted Member
Re: Use Run Task in Background
 Originally Posted by ident
That said, you should be teaching the OP how to correctly build paths.
In this very thread, jmc preceded me to that, and he did it professionally as usual. Repeating what he said was unnecessary. If you looked at my first reply to the OP you will see that it's just a practical example of what jmc said in his first reply to the OP.
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|