有一天在微信里看见了微软的Fluent Design系统(腾讯翻译为浸流设计系统)界面设计的一张图片,觉得非常好看,顿时想,这么好看的界面,如果能是一个屏保该有多好。这样的话,用户坐在电脑前也不会忍心动它,从而保证我们坐在电脑前也能好好学习了。

环境介绍:
编译环境: VS2017 C# .NETFramework4.5.2 -> 要改成.NETFramework3.5.0
操作系统: Windows7

技能需求:
软件技能: 最好有过的C#或者Java编写经验,以免遇到问题了都不知道怎么办。

想自己编写一个屏保程序是一晚上的事情,当时觉得自己应该有这个能力去开发一个简单的小程序了,于是第二天就开始动手了,百度上搜了一些网站,都是字多图少类的,看不下去,最终找到了一个看起来结构比较清晰的,而且有代码,便依照着那个代码开始了我的屏保程序。(网址如下)
http://www.cr173.com/html/7989_1.html

Step1: 打开VS,新建一个C#应用程序


 
Step2: 设置窗体属性


文字说明:
窗体:
Name属性       ->    screen、
Text属性        ->    空、
BackColor属性     ->    Black、
Size属性        ->    (800, 600)、
ControlBox、MaximizeBox、MinimizeBox、ShowInTaskbar属性 -> false、
FormBorderStyle属性  ->    None
 
 
Step3: 添加控件(需要使用工具箱,工具箱可以通过“视图”点开)


往窗体上添加Label控件、PictureBox控件、Timer控件各一个。

将Label控件的Name设置为word、Text属性设置为空;
将PictureBox控件的Name设置为picture1、Image设置为一个预知图片;
将Timer控件的Name设置为timerSaver、Enabled 属性设为true、Interval属性设为5。

Step4: 添加程序
在代码片内添加下列代码,我这儿是在Form1.cs内添加代码。

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading;
using System.Windows.Forms;namespace WindowsProtect
{public partial class Screen : Form{private IContainer components;private int iSpeed = 2;private string str = "福建南纺股份公司计算机中心";private Font TextStringFont = new Font("宋体", 10, FontStyle.Bold);private Color TextStringcolor = Color.Yellow;private int iDistance;private int ixStart = 0;private int iyStart = 0;private int speed;private int x1, y1;private PictureBox picture1;    //图形控件 private System.Windows.Forms.Timer timerSaver;       //计时器控件 private Label word;             //文本显示控件 int width1, height1;public Screen(){// Windows 窗体设计器支持所必需的 InitializeComponent();word.Font = TextStringFont;word.ForeColor = TextStringcolor;Cursor.Hide();     //隐藏光标 }/* 清理所有正在使用的资源。*/protected override void Dispose(bool disposing){if (disposing){if (components != null) { components.Dispose(); }}base.Dispose(disposing);}#region Windows Form Designer generated code /* 设计器支持所需的方法 - 不要使用代码编辑器修改 */private void InitializeComponent()          //初始化程序中使用到的组件 {this.components = new Container();ComponentResourceManager resources = new ComponentResourceManager(typeof(Screen));this.word = new Label();this.timerSaver = new System.Windows.Forms.Timer(this.components);this.picture1 = new PictureBox();((ISupportInitialize)(this.picture1)).BeginInit();this.SuspendLayout();// // word// this.word.ForeColor = Color.Yellow;this.word.Location = new Point(832, 10);this.word.Name = "word";this.word.Size = new Size(224, 21);this.word.TabIndex = 0;this.word.Visible = false;// // timerSaver// this.timerSaver.Enabled = true;this.timerSaver.Interval = 5;this.timerSaver.Tick += new EventHandler(this.timerSaver_Tick);// // picture1// this.picture1.Image = ((Image)(resources.GetObject("picture1.Image")));this.picture1.Location = new Point(1067, 771);this.picture1.Name = "picture1";this.picture1.Size = new Size(405, 288);this.picture1.SizeMode = PictureBoxSizeMode.StretchImage;this.picture1.TabIndex = 1;this.picture1.TabStop = false;// // Screen// this.AutoScaleBaseSize = new Size(8, 18);this.BackColor = Color.Black;this.ClientSize = new Size(800, 600);this.ControlBox = false;this.Controls.Add(this.picture1);this.Controls.Add(this.word);this.FormBorderStyle = FormBorderStyle.None;this.KeyPreview = true;this.MaximizeBox = false;this.MinimizeBox = false;this.Name = "Screen";this.ShowInTaskbar = false;this.StartPosition = FormStartPosition.Manual;this.WindowState = FormWindowState.Maximized;this.Load += new EventHandler(this.Form1_Load);this.KeyDown += new KeyEventHandler(this.screen_KeyDown);this.MouseDown += new MouseEventHandler(this.screen_MouseDown);this.MouseMove += new MouseEventHandler(this.screen_MouseMove);((ISupportInitialize)(this.picture1)).EndInit();this.ResumeLayout(false);}#endregion/* 应用程序的主入口点。 */[STAThread]static void main(string[] args){if (args.Length == 1)if (args[0].Substring(0, 2).Equals("/c")){MessageBox.Show("没有设置项功能", "C# Screen Saver");Application.Exit();}else if (args[0] == "/s"){Application.Run(new Screen());}else if (args[0] == "/a"){MessageBox.Show("没有口令功能", "C# Screen saver");Application.Exit();}else{Application.Run(new Screen());}}private void Form1_Load(object sender, EventArgs e){speed = 0;Rectangle ssWorkArea = System.Windows.Forms.Screen.GetWorkingArea(this);/* 屏幕显示区域 */width1 = ssWorkArea.Width;      //屏幕宽度 height1 = ssWorkArea.Height;    //屏幕高度 }private void timerSaver_Tick(object sender, EventArgs e) {word.Visible = true;word.Text = str;word.Height = word.Font.Height;                              word.Width = word.Text.Length * (int)word.Font.Size * 2;     PlayScreenSaver();}private void PlayScreenSaver()        //自定义函数 {/* 下面设置文本显示框的位置坐标 */word.Location = new Point(width1 - iDistance, word.Location.Y);word.Visible = true;               //设置为可见 iDistance += iSpeed;if (word.Location.X <= -(word.Width)){iDistance = 0;if (word.Location.Y == 0){word.Location = new Point(word.Location.X, height1 / 2);}else if (word.Location.Y == height1 / 2){word.Location = new Point(word.Location.X, height1 - word.Height);}else{word.Location = new Point(word.Location.X, 0);}}//下面是计算图片框移动坐标 speed++;if (speed <= 2 * height1){x1 = Math.Abs(width1 - speed);y1 = Math.Abs(height1 - speed);}else if (speed > 2 * height1 && speed <= 2 * width1){x1 = Math.Abs(width1 - speed);y1 = Math.Abs(height1 - (speed - speed / height1 * height1));}else if (speed > 2 * width1 && speed <= 3 * height1){x1 = Math.Abs(width1 - (speed - speed / width1 * width1));y1 = Math.Abs(height1 - (speed - speed / height1 * height1));}else if (speed > 3 * height1 && speed < 4 * height1){x1 = Math.Abs(width1 - (speed - speed / width1 * width1));y1 = Math.Abs(speed - speed / height1 * height1);}else if (speed >= 4 * height1 && speed < 5 * height1){x1 = Math.Abs(speed - speed / width1 * width1);y1 = Math.Abs(height1 - (speed - speed / height1 * height1));}else if (speed >= 5 * height1 && speed < 4 * width1){x1 = Math.Abs(speed - speed / width1 * width1);y1 = Math.Abs(speed - speed / height1 * height1);}else if (speed >= 4 * width1 && speed < 6 * height1){x1 = Math.Abs(width1 - (speed - speed / width1 * width1));y1 = Math.Abs(speed - speed / height1 * height1);}else if (speed >= 6 * height1 && speed < 5 * width1){x1 = Math.Abs(width1 - (speed - speed / width1 * width1));y1 = Math.Abs(height1 - (speed - speed / height1 * height1));}else if (speed >= 5 * width1 && speed < 7 * height1){x1 = Math.Abs(speed - speed / width1 * width1);y1 = Math.Abs(height1 - (speed - speed / height1 * height1));}else if (speed >= 7 * height1 && speed < 6 * width1){x1 = Math.Abs(speed - speed / width1 * width1);y1 = Math.Abs(speed - speed / height1 * height1);}if (speed == 6 * width1) speed = 0;picture1.Location = new Point(x1, y1);}private void StopScreenSaver()    //停止屏幕保护程序运行 {Cursor.Show();timerSaver.Enabled = false;Application.Exit();}private void screen_MouseMove(object sender, MouseEventArgs e){if (ixStart == 0 && iyStart == 0){ixStart = e.X;iyStart = e.Y;return;}else if (e.X != ixStart || e.Y != iyStart)StopScreenSaver();}private void screen_MouseDown(object sender, MouseEventArgs e){StopScreenSaver();  }private void screen_KeyDown(object sender, KeyEventArgs e){StopScreenSaver();                     }}
}

按F5或者点击“运行”就能看见程序运行的样子了。在工程目录内找到相应的.exe文件,后缀名更改成.scr文件,再将其放入C:\Windows\system32目录下即可。

后话:
大家应该是都能成功运行出程序了,而这个屏保搭建在.NETFramework 3.5.0环境下,因为我之前用.NETFramework 4.5.2最后运行失败,才知道系统不支持这个框架,如下文:

默认情况下,.NET Framework 3.5 在 Windows 7 上是启用的,所以只有在之前禁用此功能的情况下才会出现此错误。若要重新启用 .NET Framework 3.5,请按照下列步骤操作:
从“开始”菜单中选择“控制面板”。
在“控制面板”中,选择“程序”(或者,如果您不是使用默认的分类视图,请选择“程序和功能”)。
在“程序和功能”中,选择“打开或关闭 Windows 功能”以打开“Windows 功能”对话框。
在“Windows 功能”中,选中“Microsoft .NET Framework 3.5.1”复选框,然后选择“确定”。

再按上述模式更改后,在此运行改程序,电脑管家提示其会更新注册表,这应该是软件执行时发现缺少了动态链接库,因此会强制加上,但是看起来还是很恐怖。我都忘了我在设置Fliqlo的时候有没有出现一样的情况了。

而且最重要的是,现在的屏保程序并没有想象中的那么好看,而是——特别Low。

在之后的文章,会进一步解决缠绕在我心头的问题。如果大家发现了文章中的什么问题,或者有什么看法,都可以在下面评论区留言,小生会虚心听取建议。

From .1:从屏保到Win平台开发 - 一个可运行的C#屏保程序相关推荐

  1. CaysnPrinter安卓平台开发包接口说明文档及打印示例程序 - 20160926

    接口说明文档下载地址: CaysnPrinter安卓平台开发包接口说明文档 - PrinterLibs For Android_20160926 打印示例程序下载地址: Caysn打印机安卓打印示例代 ...

  2. Caysn打印机安卓平台开发包接口说明文档及打印示例程序_20170609

    Caysn打印机打印开发包接口说明文档中文版:PrinterLibs_For_Android_zh_CN_20170630 Caysn打印机打印开发包接口说明文档英文版:PrinterLibs_For ...

  3. 基于Appian低代码平台开发一个SpaceX网站

    文章目录 Appian 背景摘要 Appian Designer SpaceX网站开发 新建Application 配置应用权限 创建Record Type Appian 背景摘要 国内几乎没有App ...

  4. ios运行html时黑屏,iOS13 ,xcode11新建项目真机运行出现黑屏及新出现的SceneDelegate的作用...

    iOS13之后,xcode 11新建项目,大家会发现项目中多出了SceneDelegate这个类,而且新建项目之后,在模拟器上运行没问题,真机上低于iOS13系统的手机就会出现黑屏(解决方法就是在Ap ...

  5. Android 平台开发一个输入法

    Android 1.5 新特色之一就是输入法框架(Input Method Framework,IMF),正是它的出现,才为诞生不带实体键盘的设备提供了可能.IMF设计用来支持不同的IME,包括了so ...

  6. 手把手教学:如何用低代码平台开发一个软件?

    编者按:作为近年来在IT界掀起一轮热议的快速开发工具,低代码一直为大家所好奇,本文以低代码平台为主题,谈一谈为什么要用低代码.怎么用低代码. 为什么要选择低代码开发 低代码快速开发这个概念火爆,大概要 ...

  7. 如何保证两个不同宽高的canvas用同一组坐标正常显示_如何1人5天开发完3D数据可视化大屏 【一】...

    相信从事过数据可视化开发的你对大屏并不陌生,那么开发一个酷炫的大屏一定是很多数据可视化开发者想要做的事情. 我们使用three.js,大约一周的时间开发出了一个酷炫的数据可视化大屏: 1. 前言 由于 ...

  8. 如何1人5天开发完3D数据可视化大屏 【一】

    相信从事过数据可视化开发的你对大屏并不陌生,那么开发一个酷炫的大屏一定是很多数据可视化开发者想要做的事情. 我们使用three.js,大约一周的时间开发出了一个酷炫的数据可视化大屏: 1. 前言 由于 ...

  9. 微信公共平台开发(1)

    最近与以前的同学闲聊,他有一个创业的想法.虽然其前景我没看到,但是也不愿意泼这位同学的凉水.我可能是他周围少有的会开发的人,所以就找我给他开发一个微信服务号(或者小程序),这重燃了我对后台开发的热情. ...

最新文章

  1. java opencv 环境_基于java的OpenCV环境搭建
  2. 使用rest_framework写api接口的一些注意事项(axios发送ajax请求)
  3. 三大平衡树(Treap + Splay + SBT)总结+模板
  4. iphone完整版的http上传请求协议
  5. / /* /**的区别
  6. doAcquireSharedInterruptibly
  7. .NET 并行(多核)编程系列之六 Task基础部分完结篇
  8. C语言中quot;##quot;的独特用法
  9. Js中的window.parent ,window.top,window.self 代表的对象
  10. 看雪CTF.TSRC 2018 团队赛 第六题 『追凶者也』 解题思路
  11. linux中逻辑块大小为,Linux 文件系统相关的基本概念
  12. 【PM2.5预测】基于matlab灰色模型PM2.5预测【含Matlab源码 499期】
  13. 数据库基础:select基本查询语句
  14. 百旺开票清单导入模板_半年来最爱的高效率工具滴答清单不为人知的使用技巧...
  15. callee与caller的区别
  16. 蓝牙低功耗音频技术--目录大纲
  17. office2022最新版本Microsoft 365
  18. 2000~2009十大创业新模式
  19. HTML+CSS静态页面网页设计作业——2019凡客服装店铺商城(1页) HTML+CSS+JavaScript HTML+CSS大作业_ 服装店铺网页制作作业_购物网页设计...
  20. MacOS 安装 Kettle(Data Integration)

热门文章

  1. Ansys Zemax / SPEOS | 3片式LCD投影仪的设计与仿真
  2. 嵌入式GPS模块,天线一体化GPS模块,GNSS G-Mouse测试指导
  3. 花了两天时间,解决安装升级 Windows 10 时 0x800707e7 - 0x3000d 错误
  4. Cisco路由器忘记密码
  5. 苹果Iphone4手机越狱及安装破解程序图文教程
  6. 剑指offer专项突破版
  7. 测试驱动开发(TDD)实战小例子(JAVA版)
  8. 一元线性回归模型的原理及实现
  9. 数据集标注(在线标注,方便快捷)/YOLOV5自建数据集
  10. 前端使用xlsx.core.min.js读取excel内容