我只需要在屏幕上画一些东西1 帧。
诸如一行文本之类的东西。
我试图通过移动窗口来实现这一点,但我失败了。通过显示/隐藏或移入移出位置,我无法让它们仅显示 1 帧(8-16 毫秒)。
有没有办法做到这一点?
(呃,出于好奇,我是为别人做这件事,所以对需要这样做的原因进行合理化是没有用的。)
编辑:我尝试的最后一件事:
public partial class Form2 : Form
{
static Random rand = new Random();
public void ShowString(string s)
{
this.label1.Text = s; // Has .AutoSize = true
this.Size = this.label1.Size;
var bnds = Screen.PrimaryScreen.WorkingArea;
bnds.Size -= this.Size;
this.Location = new Point(rand.Next(bnds.X, bnds.Right), rand.Next(bnds.Y, bnds.Bottom));
}
public Form2()
{
InitializeComponent();
}
private void Form2_Load(object sender, EventArgs e)
{
timer1.Enabled = true;
}
private void timer1_Tick(object sender, EventArgs e)
{
if (Location.X != -10000 && Location.Y != -10000)
{
Location = new Point(-10000, -10000);
timer1.Interval = Program.interval; // How long to wait before showing two things.
}
else
{
timer1.Interval = Program.delay; // For how long to show.
ShowString("just something to test");
}
}
}
在此之前:
public partial class Form2 : Form
{
static Random rand = new Random();
public void ShowString(string s)
{
this.label1.Text = s; // Has .AutoSize = true
this.Size = this.label1.Size;
var bnds = Screen.PrimaryScreen.WorkingArea;
bnds.Size -= this.Size;
this.Location = new Point(rand.Next(bnds.X, bnds.Right), rand.Next(bnds.Y, bnds.Bottom));
}
public Form2()
{
InitializeComponent();
timer1.Interval = Program.interval;
}
private void Form2_Load(object sender, EventArgs e)
{
timer1.Enabled = true;
}
private void Form2_Move(object sender, EventArgs e)
{
if (Location.X != -10000 && Location.Y != -10000)
{
Thread.Sleep(Program.delay); // Dirty cheat, but I was just trying.
this.Location = new Point(-10000, -10000);
}
}
private void timer1_Tick(object sender, EventArgs e)
{
ShowString("just something to test");
}
}