WPF中桌面屏保的制作(主要代码)
制作要點:
(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();
??????? }
??????? void Window1_KeyDown(object sender, System.Windows.Input.KeyEventArgs e)
??????? {
??????????? // 當按Esc按鈕時關閉窗口,即中止屏保
??????????? if (e.Key == System.Windows.Input.Key.Escape)
??????????????? this.Close();
??????? }
??????? private void OnFrame(object sender, EventArgs e)
??????? {
??????? }?
???????? //繪制屏保內容,可以是動畫,也可以是動態更新的圖片
??????? private void DrawingSomethings()
??????? {
???????????????// 代碼.....
??????? }
總結
以上是生活随笔為你收集整理的WPF中桌面屏保的制作(主要代码)的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: iOS使用 xcconfig配置文件的若
- 下一篇: Algs4-2.2.22三向归并排序