I am trying to build a scratch-like application to simulate block-based programming approach. I want the user to add the commands to command pool(queue) and run them in order when the user clicks on the "RUN" button.
I researched on the internet and found queueing is possible by Action lists.
//Global Variables
List<Int32> NumberOfSteps = new List<Int32>();
List<Int32> NumberOfDegrees = new List<Int32>();
List<Int32> GlideXPos = new List<Int32>();
List<Int32> GlideYPos = new List<Int32>();
List<String> SayList = new List<String>();
List<String> SoundList = new List<String>();
List<Action> queue = new List<Action>();
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
}
private void textBox7_TextChanged(object sender, EventArgs e)
{
}
private static Bitmap RotateImageByAngle(Image oldBitmap, float angle)
{
var newBitmap = new Bitmap(oldBitmap.Width, oldBitmap.Height);
var graphics = Graphics.FromImage(newBitmap);
graphics.TranslateTransform((float)oldBitmap.Width / 2, (float)oldBitmap.Height / 2);
graphics.RotateTransform(angle);
graphics.TranslateTransform(-(float)oldBitmap.Width / 2, -(float)oldBitmap.Height / 2);
graphics.DrawImage(oldBitmap, new Point(0, 0));
return newBitmap;
}
private void button3_Click(object sender, EventArgs e)
{
pictureBox1.Image = RotateImageByAngle(pictureBox1.Image, 30);
}
private void button1_Click(object sender, EventArgs e)
{
queue.Add(() => { HAREKETETTIR(Convert.ToInt32(txtNumberOfSteps.Text)); });
}
private void HAREKETETTIR(int miktar)
{
deneme2 += miktar;
Point deneme = new Point(deneme2, 455);
pictureBox1.Location = deneme;
}
private void pictureBox1_Click(object sender, EventArgs e)
{
}
private void btnRotate_Click(object sender, EventArgs e)
{
queue.Add(() => { HAREKETETTIR(Convert.ToInt32(txtNumberOfSteps.Text)); });
}
private void RUN_Click(object sender, EventArgs e)
{
foreach (Action item in queue)
{
item();
}
}
}
When I click Run,The code creates an error as "Input string was not in a correct format."
How can I solve the issue here?
Thanks