我需要这方面的帮助,
有 3 个图片框,红色应该向左增加它的宽度,绿色应该把它的高度增加到顶部蓝色的宽度向右
同样,如果到达顶部边框/任何文本框,它应该给出错误/停止执行
我将来需要添加更多图片框,如果其中两个发生碰撞,它应该会出错/停止执行。我设法将它们编码为上升,但无法使其他功能正常工作。请有人帮我解决这个问题。
或者
https://www.box.com/s/d0d302c6c266f52e0abf
谢谢你。RR
我的代码如下,
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Threading;
namespace ThreadwithmovingPicbxmoving
{
public partial class Form1 : Form
{
Thread t1;
Thread t2;
Thread t3;
delegate void CTMethod(int val);
delegate void CTFinish(string t);
Queue<string> order = new Queue<string>();
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
int r = int.Parse(textBox1.Text);
int y = int.Parse(textBox2.Text);
int g = int.Parse(textBox3.Text);
t1 = new Thread(new ParameterizedThreadStart(loopred));
t2 = new Thread(new ParameterizedThreadStart(loopyel));
t3 = new Thread(new ParameterizedThreadStart(loopGree));
t1.Start(r);
t2.Start(y);
t3.Start(g);
}
private void updateRed(int val)
{
pictureBox1.Height = val;
pictureBox1.Refresh();
}
private void updateyell(int val)
{
pictureBox2.Height = val;
pictureBox2.Refresh();
}
private void updategree(int val)
{
pictureBox3.Height = val;
pictureBox3.Refresh();
}
private void loopred(object o)
{
int c = (int)o;
CTMethod ctred = new CTMethod(updateRed);
if (c < 500)
{
for (int i = 0; i < c; i++)
{
this.Invoke(ctred, i);
Thread.Sleep(20);
}
}
else
{
MessageBox.Show("Enter a value less than 500 for Red Box!!!");
}
CTFinish CTFin = new CTFinish(Threadfinish);
this.Invoke(CTFin, "Red");
}
private void loopyel(object o)
{
int c = (int)o;
CTMethod ctyell = new CTMethod(updateyell);
if (c < 500)
{
for (int i = 0; i < c; i++)
{
this.Invoke(ctyell, i);
Thread.Sleep(20);
}
}
else
{
MessageBox.Show("Enter a valure less than 500 for Yellow Box!!!");
}
CTFinish CTFin = new CTFinish(Threadfinish);
this.Invoke(CTFin, "Yell");
}
private void loopGree(object o)
{
int c = (int)o;
CTMethod ctgree = new CTMethod(updategree);
if (c < 500)
{
for (int i = 0; i < c; i++)
{
this.Invoke(ctgree, i);
Thread.Sleep(20);
}
}
else
{
MessageBox.Show("Enter a valure less than 500 for Green Box!!!");
}
CTFinish CTfin = new CTFinish(Threadfinish);
this.Invoke(CTfin, "Green");
}
private void Threadfinish(string t)
{
order.Enqueue(t);
if (order.Count == 3)
{
MessageBox.Show("Threads finished in this order: \n" + "1." + order.Dequeue() + "\n" + "2." + order.Dequeue()
+ "\n" + "3." + order.Dequeue() + "\n", "finished");
}
}
}
}