![](https://news.xinpengboligang.com/upload/keji/951cf209fccda367a17412acc907ab25.jpeg)
聲明變量:
private Timer waveTimer;
private int numWaves = 5;
private int[] waveRadius;
private int[] waveOpacity;
public Form1()
{
InitializeComponent();
this.DoubleBuffered = true;
this.BackColor = Color.Pink;
waveTimer = new Timer();
waveTimer.Interval = 50;
waveTimer.Tick = WaveTimer_Tick;
waveTimer.Start();
waveRadius = new int[numWaves];
waveOpacity = new int[numWaves];
for (int i = 0; i < numWaves; i )
{
waveRadius[i] = 10 i * 20;
waveOpacity[i] = 255 - i * 40;
}
}
![](https://news.xinpengboligang.com/upload/keji/9ef614f109449a7b29f8c25f5e74322b.jpeg)
時間控件:
private void WaveTimer_Tick(object sender, EventArgs e)
{
for (int i = 0; i < numWaves; i )
{
waveRadius[i] = 10;
waveOpacity[i] -= 5;
if (waveOpacity[i] <= 0)
{
waveRadius[i] = 10 i * 20;
waveOpacity[i] = 255 - i * 40;
}
}
this.Invalidate();
}
![](https://news.xinpengboligang.com/upload/keji/37793bc388b3a2833fdb0cb7a55609ee.jpeg)
繪制動態電波:
protected override void OnPaint(PaintEventArgs e)
{
base.OnPaint(e);
int centerX = this.ClientSize.Width / 2;
int centerY = this.ClientSize.Height / 2;
for (int i = 0; i < numWaves; i )
{
using (Brush waveBrush = new SolidBrush(Color.FromArgb(waveOpacity[i], Color.Red)))
{
e.Graphics.FillEllipse(waveBrush, centerX - waveRadius[i], centerY - waveRadius[i], waveRadius[i] * 2, waveRadius[i] * 2);
}
}
}