在我正在工作的项目中,我需要在面板内画一个圆圈并使其闪烁。我已经在PictureBox的Paint事件上绘制了圆形图,但我不能让它闪烁。如果可能,请提供不使用计时器的解决方案。
该绘画由opclblEventoCalidad的TextChanged事件触发,使用this.pboxMaquina.Invalidate()。
private async void opclblEventoCalidad_TextChanged(object sender, EventArgs e)
{
await Task.Run(() =>
{
if (!String.IsNullOrEmpty(this.CodigoMaquina))
{
_continueBlink = true;
Alarmas = _maquinaContract.ObtenerAlarmas();
string text = (sender as OPCControls.OPCControlsLabel).Text;
if (Alarmas != null && Alarmas.Any(m => m.CodigoMaquina == this.CodigoMaquina))
{
ColorInspeccion = Alarmas.First(s => s.CodigoMaquina == CodigoMaquina).CodigoColor;
CantidadInspecciones = Alarmas.First(s => s.CodigoMaquina == CodigoMaquina).CantidadInspecciones;
this.pboxMaquina.Invalidate();
}
}
});
}
private void pboxMaquina_Paint(object sender, PaintEventArgs e)
{
GraficarAlarmasInspeccion(e);
}
private void GraficarAlarmasInspeccion(PaintEventArgs e)
{
Pen blackPen = new Pen(Color.Black, 3);
int rectangleWidth = Math.Min(pnlMaquina.Width, pnlMaquina.Height);
int width = Convert.ToInt32(rectangleWidth / 2.75);
int positionX = (pnlMaquina.Width - width) / 2;
int positionY = (pnlMaquina.Height - width) / 2;
Rectangle rect = new Rectangle(positionX, positionY, width, width);
e.Graphics.DrawEllipse(blackPen, rect);
e.Graphics.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;
e.Graphics.FillEllipse(Brushes.Red, rect);
SizeF textSize = e.Graphics.MeasureString(this.CantidadInspecciones.ToString(), Font);
PointF locationToDraw = new PointF();
locationToDraw.X = (pnlMaquina.Width / 2);
locationToDraw.Y = (pnlMaquina.Height / 2);
StringFormat fmt = new StringFormat() { Alignment = StringAlignment.Center, LineAlignment = StringAlignment.Center };
using (Font myFont = new Font("Arial", (float)(width / 2), FontStyle.Bold))
{
e.Graphics.DrawString(this.CantidadInspecciones.ToString(), myFont, Brushes.Black, locationToDraw, fmt);
}
}
这会产生以下图像。现在我需要让这个圆圈闪烁。提前谢谢。