Categories > Coding > C# >

(REL) Auto Refreshing ListBox C#

Huddy

Domain Expansion

vip

Posts: 318

Threads: 18

Joined: Apr, 2022

Reputation: 22

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}");
        }
  • 0

Discord Contact : showerhuddy

SeizureSalad

i love femboys

Posts: 1159

Threads: 79

Joined: Mar, 2021

Reputation: 40

Replied

why use filesystemwatcher when you can just use a while(true) loop?!?!?!???/??

 

https://cdn.discordapp.com/emojis/905478989232103435.png

  • 0

"Questionable intellegence, but I like the mystery" - CubeFaces

https://cdn.discordapp.com/attachments/1136067487847415848/1138948596679589898/sig.png

Huddy

Domain Expansion

vip

Posts: 318

Threads: 18

Joined: Apr, 2022

Reputation: 22

Replied

@SeizureSalad filesystemwatcher good thats why

  • 0

Discord Contact : showerhuddy

Posts: 197

Threads: 10

Joined: Feb, 2021

Reputation: 9

Replied

@SeizureSalad joke??? try it before saying that.

  • 0

Im netral, not evil, not too kind either.

Posts: 1430

Threads: 71

Joined: May, 2022

Reputation: 20

Replied

@SeizureSalad

Ikr clearly a bad decision to use FileSystemWatcher 😂😂😂😂😂😂😂😂😂😂😂😂

  • 0

i use arch btw

Huddy

Domain Expansion

vip

Posts: 318

Threads: 18

Joined: Apr, 2022

Reputation: 22

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

  • 0

Discord Contact : showerhuddy

Posts: 1008

Threads: 66

Joined: Sep, 2021

Reputation: 20

Replied

@Whoman you clearly dont know what you are talking about. filesystemwatcher is actually useful

  • 0

"Building blocks of imagination, united in the virtual realm, where creativity thrives and friendships ignite. Welcome to the Roblox revolution!" - chatgpt

 

Posts: 1430

Threads: 71

Joined: May, 2022

Reputation: 20

Replied

@crazy_cat

nahh 😂😂😂😂😂😂

  • 0

i use arch btw

Posts: 1008

Threads: 66

Joined: Sep, 2021

Reputation: 20

Replied

@Whoman ... please learn c# before talking about it

  • 0

"Building blocks of imagination, united in the virtual realm, where creativity thrives and friendships ignite. Welcome to the Roblox revolution!" - chatgpt

 

Posts: 1430

Threads: 71

Joined: May, 2022

Reputation: 20

Replied

@crazy_cat

please learn about comedy 😐

  • 0

i use arch btw

Posts: 2014

Threads: 198

Joined: Apr, 2021

Reputation: 16

Replied

Great release!

  • 0

Random quote here...

Posts: 511

Threads: 32

Joined: Aug, 2021

Reputation: 58

Replied

vouch nice release :)

  • 1

Posts: 1008

Threads: 66

Joined: Sep, 2021

Reputation: 20

Replied

@Whoman plz learn how to not turn your unknowledge to comedy

  • 0

"Building blocks of imagination, united in the virtual realm, where creativity thrives and friendships ignite. Welcome to the Roblox revolution!" - chatgpt

 

Posts: 197

Threads: 10

Joined: Feb, 2021

Reputation: 9

Replied

@Whoman Not funny bro, atleast you look dumb

  • 0

Im netral, not evil, not too kind either.

Posts: 1430

Threads: 71

Joined: May, 2022

Reputation: 20

Replied

@OrbitRBX

thanks

  • 0

i use arch btw

Users viewing this thread:

( Members: 0, Guests: 1, Total: 1 )