Categories > Coding > C# >
(REL) Auto Refreshing ListBox C#
Posted
So I know most people know how to do this but this is for all the people that still use refresh buttons
using System.Threading; //For Auto Refresh
using System.Threading.Tasks; //I forget if you need this just adding it because I can
using System.IO; //For File.ReadAllText
//Code for the auto fresh to work
public executor()
{
InitializeComponent();
new DirectoryInfo("./Scripts").GetFileSystemInfos().ToList().ForEach(
info => listBox1.Items.Add(info.Name));
var fileSystemWatcher = new FileSystemWatcher("./Scripts")
{ EnableRaisingEvents = true };
var context = SynchronizationContext.Current;
fileSystemWatcher.Created += (s, e) => {
context.Post(val => listBox1.Items.Add(e.Name), s);
};
}
//Allow the listbox put code into the TextBox
private void listBox1_SelectedIndexChanged(object sender, EventArgs e)
{
TextBox.Text = File.ReadAllText($"./Scripts/{listBox1.SelectedItem}");
}
Discord Contact : fatty__joe
Replied
why use filesystemwatcher when you can just use a while(true) loop?!?!?!???/??
Cancel
Post
"Questionable intellegence, but I like the mystery" - CubeFaces
https://cdn.discordapp.com/attachments/1136067487847415848/1138948596679589898/sig.png
Discord Contact : fatty__joe
Im netral, not evil, not too kind either.
Replied
Ikr clearly a bad decision to use FileSystemWatcher 😂😂😂😂😂😂😂😂😂😂😂😂
Cancel
Post
Did I mention I use arch btw?
Replied
@CertifiedBanan Why would you use a timer if you use a timer it just keeps resetting the listbox making it impossible to load a script into the TextBox
Cancel
Post
Discord Contact : fatty__joe
Replied
@Whoman you clearly dont know what you are talking about. filesystemwatcher is actually useful
Cancel
Post
"Building blocks of imagination, united in the virtual realm, where creativity thrives and friendships ignite. Welcome to the Roblox revolution!" - chatgpt
Did I mention I use arch btw?
"Building blocks of imagination, united in the virtual realm, where creativity thrives and friendships ignite. Welcome to the Roblox revolution!" - chatgpt
Did I mention I use arch btw?
Replied
Great release!
Cancel
Post
Random quote here...
"Building blocks of imagination, united in the virtual realm, where creativity thrives and friendships ignite. Welcome to the Roblox revolution!" - chatgpt
Im netral, not evil, not too kind either.
Did I mention I use arch btw?
Users viewing this thread:
( Members: 0, Guests: 1, Total: 1 )
Cancel
Post