タイマーで一定時間ごと白い線と黒い線を交互に表示しています。
namespace BlinkLine;
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
var sz = new Size(640, 480);
var picbox = new PictureBox
{
Size = sz,
};
bool blinkFlag = false;
var blackPen = new Pen(Brushes.Black, 3);
var whitePen = new Pen(Brushes.White, 3);
var startPos = new Point(80, 100);
var endPos = new Point(260, 100);
var timer = new System.Windows.Forms.Timer(this.components)
{
Interval = 250,
};
timer.Tick += (s, e) =>
{
blinkFlag = !blinkFlag;
picbox.Invalidate();
};
Load +=(s, e) =>
{
timer.Start();
};
picbox.Paint +=(s, e) =>
{
e.Graphics.Clear(Color.LightGray);
var pen = blinkFlag ? blackPen : whitePen;
e.Graphics.DrawLine(pen, startPos, endPos);
};
Closed +=(s, e) =>
{
timer.Stop();
using(timer){}
};
Controls.Add(picbox);
}
}
コメント