Новое в переполнении стека, поэтому надеемся, что кто-то знает, что здесь происходит не так.
По какой-то причине всякий раз, когда я нахожу курсор мыши на кнопке в моем приложении c # form, это вызывает сброс в моем коде.Это кажется мне странным, учитывая, что у меня на самом деле нет никаких событий при наведении курсора на кнопку.Я даже пытался добавить еще одну кнопку, и даже когда я ничего не делал с ней, зависание по-прежнему вызывает сброс.
Предполагается, что программа заполняет резервуар цветами, и цвет можно менять во время наполнения.Как только он заполнен, он сбрасывается до пустого.Заполнение должно начаться в следующий раз, когда ползунок, управляющий скоростью заполнения, будет взаимодействовать.
Он делает это правильно, но он также начинает заполняться снова, когда я наводю курсор на кнопку.
namespace Assignment5A
{
public partial class MainForm : Form
{
public float streamHeight = 370;
public float lastWaterHeight = 0;
public float waterHeight = 0;
public float waterBottom = 500;
public float fillSpeed = 300;
public Color brushColor = Color.LightBlue;
public Graphics g;
public Pen pen;
public Brush brush = new SolidBrush(Color.LightBlue);
public MainForm()
{
InitializeComponent();
this.Width = 500;
this.Height =600;
this.BackColor = Color.Black;
SpeedTimer.Interval = (int)fillSpeed;
}
private void MainForm_Paint(object sender, PaintEventArgs e)
{
g = e.Graphics;
pen = new Pen(Color.White);
g.DrawLine(pen, 50, 200, 50, 500);
g.DrawLine(pen, 350, 200, 350, 500);
g.DrawLine(pen, 50, 500, 350, 500);
SpeedTimer.Start();
}
private void SpeedTimer_Tick(object sender, EventArgs e)
{
if (waterHeight < 270)
{
brush = new SolidBrush(brushColor);
g = this.CreateGraphics();
g.FillRectangle(brush, 108, 136, 20, waterBottom - 136 - waterHeight);
waterHeight += 1f;
g.FillRectangle(brush, 51, waterBottom - waterHeight, 299, waterHeight - lastWaterHeight);
lastWaterHeight = waterHeight;
}
else
{
SpeedTimer.Stop();
waterHeight = 0;
lastWaterHeight = 0;
brush = new SolidBrush(Color.Black);
g.FillRectangle(brush, 51, 136, 299, 364);
}
}
private void Speed_Scroll(object sender, EventArgs e)
{
if (waterHeight < 270)
{
float scrollValue = Speed.Value;
fillSpeed = 300 / scrollValue;
SpeedTimer.Interval = (int)fillSpeed;
}
else
{
brush = new SolidBrush(Color.Black);
g.FillRectangle(brush, 51, 230, 299, 270);
SpeedTimer.Start();
}
}
private void ColorButton_Click(object sender, EventArgs e)
{
SetColor.ShowDialog();
brushColor = SetColor.Color;
}
}
}
![enter image description here](https://i.stack.imgur.com/kuDQP.png)