将一个网页文件设置为电脑的屏幕保护程序
如何实现
1.自己写的网页文件或者是某个浏览器的URL,将其网页形式变成屏幕保护程序
2.用C#写一个WindowsForm程序,用WebBrowser控件实现
3.将产生的.exe文件复制到System32文件下,并将其后缀名更改为.scr(屏幕保护程序的后缀名)
4.最后,按照正常设置Windows的屏幕保护程序进行设置即可
下面是代码:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace WindowsFormsApp1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
this.FormBorderStyle = FormBorderStyle.None;
this.ShowInTaskbar = false;
this.KeyPreview = true;
this.Location = new Point(0, 0);
this.Size = new Size(Screen.PrimaryScreen.Bounds.Width, Screen.PrimaryScreen.Bounds.Height);
Thread.CurrentThread.Priority = ThreadPriority.Highest;
webBrowser1.Location = this.Location;
webBrowser1.Size = this.Size;
webBrowser1.Url = new Uri("C:\\Test\\Index.html");
}
private void WebBrowser1_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
{
}
private void WebBrowser1_PreviewKeyDown(object sensder, PreviewKeyDownEventArgs e)
{
if (e.KeyCode == Keys.Escape)
{
this.Close();
}
}
}
}
注意:
1.C#项目中的.NetFramework的版本,必须要和电脑中的.NetFramework的版本要一致,或者小于电脑的版本,否则会出现错误
2.WebBrowser控件的一个属性ScriptErrorSuppressed要修改为true,否则程序运行的时候,会提示脚本无法运行。
3.根据实际情况改变转义序列"C:\Test\Index.html"
4.至于现在有一个问题就是WebBrowser控件加载网页的时候速度会很慢,暂时不知道如何解决,欢迎大家交流讨论
另外,附上GitHub地址欢迎大家随时交流意见。