我真的不确定这是否是我对 C#、VS 2010、调试、.net 或一般事件缺乏经验的问题,所以请多多包涵。我有一个绘制字母水族馆的项目。将不同颜色的字母添加到面板,然后为它们设置动画。这是一个简单的窗体项目,包括两个类,Fishtank 和 Fish。绘制事件用于绘制彩色字母,我们的任务是为它们设置动画。为了了解绘画事件如何使用具有初始加载和控件的类,我设置了一个断点。使用断点,我无法通过或越过绘制事件。没有断点,程序加载??这是我的经验不足,代码,调试还是什么的问题?
private void fishTankPanel_Paint(object sender, PaintEventArgs e)
{
// Loop through each fish in our fish tank, and draw them.
for (int i = 0; i < _fishTank.CountFish(); i++)
{
Fish fish = _fishTank.GetFish(i);
e.Graphics.DrawString(fish.FishLetter, new Font("Arial", 10),
new SolidBrush(fish.FishColor), new Point(fish.XPosition, fish.YPosition));
}
fishCountLabel.Text = _fishTank.CountFish().ToString();
}
class Fish
{
private Color _fishColor;
public Color FishColor
{
get { return _fishColor; }
set { _fishColor = value; }
}
private int _xPosition;
public int XPosition
{
get { return _xPosition; }
set { _xPosition = value; }
}
private int _yPosition;
public int YPosition
{
get { return _yPosition; }
set { _yPosition = value; }
}
private string _fishLetter;
public string FishLetter
{
get { return _fishLetter; }
set { _fishLetter = value; }
}
private string _direction;
public string Direction
{
get { return _direction; }
set { _direction = value; }
}
public Fish(string fishLetter, int xPosition, int yPosition, Color fishColor, string fishDirection)
{
// If no letter specified, use "X."
if (fishLetter.Length == 0)
fishLetter = "X";
_fishLetter = fishLetter;
// Ensure the position is >= 0.
if (xPosition < 0)
xPosition = 0;
_xPosition = xPosition;
if (yPosition < 0)
yPosition = 0;
_yPosition = yPosition;
// Set the fish color.
_fishColor = fishColor;
// Set fish direction
}
}class FishTank
{
// Use a List collection to hold the fish.
private List<Fish> _fishTank = new List<Fish>();
public int CountFish()
{
return _fishTank.Count;
}
public Fish GetFish(int position)
{
return _fishTank[position];
}
public void AddFish(Fish fish)
{
_fishTank.Add(fish);
}
public void ClearFish()
{
_fishTank.Clear();
}
}
反馈将不胜感激,并提前致谢。