Answer the question
In order to leave comments, you need to log in
How to create an infinite background loop in Win Form?
Here is the built Win Form program (C#)
namespace sharp_test
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
SoundPlayer simpleSound = new SoundPlayer(@"kurlik.wav");
simpleSound.PlayLooping();
}
}
}
{
Random rnd = new Random();
int xi = 1;
int yi = 1;
while (true)
{
int vx = rnd.Next(0, 1);
int vy = rnd.Next(0, 1);
if (vx == 1) xi *= 1; else xi *= -1;
if (vy == 1) yi *= 1; else yi *= -1;
while (pictureBox1.Location.X > 12 & pictureBox1.Location.X < 272 & pictureBox1.Location.Y > 12 & pictureBox1.Location.Y < 249)
{
pictureBox1.Location = new Point(pictureBox1.Location.X + xi, pictureBox1.Location.Y + yi);
textBox1.Text = Convert.ToString(pictureBox1.Location.X + xi);
}
}
}
Answer the question
In order to leave comments, you need to log in
Are you sure you have WPF?
And that something is more similar to WinForms.
For working with controls from separate threads:
- for WinForms read here
- for WPF read about the thread model
UPD: the approach to solving the problem of norms (create a thread and spin your loop in it)
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question