vrijdag bierdag 🗣
❔ Form does not show up after using loop
My WindowsForm does not show up when using a
for(;;)
loop and I'm new to csharp. Any explanation??
namespace csNotes
{
public partial class Form1 : Form
{
public Form1()
{
ChangeRGB();
InitializeComponent();
}
void Sleep(double ms)
{
Thread.Sleep((int)(ms * 1000));
}
void ChangeRGB()
{
for(; ;)
{
Sleep(0.1);
// Change RGB
int c1 = new Random()
.Next(0, 255);
int c2 = new Random()
.Next(0, 255);
int c3 = new Random()
.Next(0, 255);
BackColor = Color.FromArgb(c1, c2, c3);
};
}
private void ClearButton_Click(object sender, EventArgs e)
{
// Clear the text box
inputBox.Clear();
}
}
}
namespace csNotes
{
public partial class Form1 : Form
{
public Form1()
{
ChangeRGB();
InitializeComponent();
}
void Sleep(double ms)
{
Thread.Sleep((int)(ms * 1000));
}
void ChangeRGB()
{
for(; ;)
{
Sleep(0.1);
// Change RGB
int c1 = new Random()
.Next(0, 255);
int c2 = new Random()
.Next(0, 255);
int c3 = new Random()
.Next(0, 255);
BackColor = Color.FromArgb(c1, c2, c3);
};
}
private void ClearButton_Click(object sender, EventArgs e)
{
// Clear the text box
inputBox.Clear();
}
}
}
15 replies