试图在C#中使用WinForm进行简单的杀菌游戏,但细菌(我Panel暂时使用)似乎并没有随意移动.
具体来说,我遇到的问题是,细菌试图向左上角移动并仅在那里移动.理想情况下,细菌需要均匀地在矩形范围内移动,但我不确定如何实现.看看下面的gif文件.

如您所见,红色Panel仅在左上角移动.我怎样才能让它随意均匀地随处移动?
这是我的代码:
private Panel _pnlBacteria; //Panel representing a piece of bacteria
private Random r = new Random(); //For randomly-generated values
private int _prevX; //Stores the previous X location
private int _prevY; //Stores the previous Y location
public Form1()
{
InitializeComponent();
_pnlBacteria = new Panel();
/* Get more property assignments to this._pnlBacteria (omitted) */
//Bacteria's start position is also randomly selected
_prevX = r.Next(50, 300);
_prevY = r.Next(50, 500);
}
//Timer runs every …Run Code Online (Sandbox Code Playgroud)