Content: Slate Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate Marble
Background: Slate Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate Marble
Pattern: Blank Waves Notes Sharp Wood Rockface Leather Honey Vertical Triangles
Welcome to Xbox Chaos: Modding Evolved

Register now to gain access to all of our features. Once registered and logged in, you will be able to contribute to this site by submitting your own content or replying to existing content. You'll be able to customize your profile, receive reputation points as a reward for submitting content, while also communicating with other members via your own private inbox, plus much more! This message will be removed once you have signed in.

Sign in to follow this  
Followers 0
bfixer117

C#
Need Some Help Making A Select Task Dialog

4 posts in this topic

So i need some help making a select task dialog one where you select a task from a list of all the current tasks running on your computer

 

 // this is to get the current process.

Process currentProcess = Process.GetCurrentProcess();

and

// this is to get all processes running on the local computer.
Process [] localAll = Process.GetProcesses();

 

but need some help of making it into a list any ideas.

Share this post


Link to post
Share on other sites

By list, do you mean the collection type (like an array), or something in the UI, such as a ComboBox, where all the processes are displayed? And if you do want to display it in the UI, are you using WinForms or WPF?

 

If you need the collection type, you can use

List<Process> localList = new List<Process>(localAll);
And if this is WPF, and you have a ComboBox in the UI, such as

<ComboBox x:Name="ProcessComboBox" DisplayMemberPath="ProcessName"/> <!-- DisplayMemberPath tells the ComboBox what property of the object used in the item's source to display as the item's text -->
the following code will add the processes to the ComboBox and select the current process

ProcessComboBox.ItemsSource = localList;Process currentProcessInList = localList.FirstOrDefault(process => process.Id == currentProcess.Id); // LINQ expression, make sure to reference the "System.Linq" namespaceif (currentProcessInList != null)  ProcessComboBox.SelectedIndex = localList.IndexOf(currentProcessInList);
If you wish to access the selected process when the ComboBox selection is changed, add the attribute 'SelectionChanged="ProcessComboBox_OnSelectionChanged"' to the ComboBox in WPF, and add this to your code

private void ProcessComboBox_OnSelectionChanged(object sender, SelectionChangedEventArgs e){  Process selectedProcess = ProcessComboBox.SelectedItem as Process;  if (selectedProcess == null)    return;  // Do what you want with the process here...}

Share this post


Link to post
Share on other sites

I actually made a simple dialog for this in WinForms once. It's attached to my post.

 

To use it, import the files into your project and change the namespace to match. Then:

var browser = new ProcessBrowser();if (browser.ShowDialog() == DialogResult.OK){    // User clicked OK    var process = browser.SelectedProcess;    if (process != null)    {        // Do something with the process here    }}

ProcessBrowser.zip

Share this post


Link to post
Share on other sites
Sign in to follow this  
Followers 0