制作要點:
(1) 使用System.Windows.Threading.DispatcherTimer;
(2) 將Window屬性設置為:
this.WindowState = Windowstate.Maximized;
this.WindowStyle = Windowstyle.None;
this.ResizeMode = ResizeMode.NoResize;
(3) 按ESC鍵時,關閉窗口。
關鍵代碼:
System.Windows.Threading.DispatcherTimer frameTimer;
int lastTick;
public Window1()
{
InitializeComponent();
this.WindowState = Windowstate.Maximized;
this.WindowStyle = Windowstyle.None;
this.ResizeMode = ResizeMode.NoResize;
frameTimer = new System.Windows.Threading.DispatcherTimer();
frameTimer.Tick += OnFrame;
frameTimer.Interval = TimeSpan.FromSeconds(1.0 / 60.0);
frameTimer.Start();
this.lastTick = Environment.TickCount;
rand = new Random(this.GetHashCode());
this.Show();
this.KeyDown += new System.Windows.Input.KeyEventHandler(Window1_KeyDown);
//繪制屏保內容,可以是動畫,也可以是動態更新的圖片
// DrawingSomethings();
}