This article describes the method of using C # to make screen saver, which is to emulate the subtitle screensaver that comes with the Windows system.
The screen saver extension, although "SCR", is actually an executable "EXE" file. But he is also a more unique "EXE" file. Here's a look at how C # is the whole process of writing screen saver.
A The program design and operating environment introduced in this paper
(1). Microsoft Windows 2000 Server Edition
(2). Net Framework SDK Official edition
Two C # key steps and solutions for writing subtitles screen-keeping programs:
(1). The Setup program's form meets the requirements for screen protection:
Because the screen saver is an executable program, when you write a screen saver, you first design it according to the executable program. But screen protection has its own characteristics. For example: screen protection is full of the entire screen, and there is no boundless. The taskbar cannot be displayed when screen saver is running. In the design of the implementation of these features, the key is the form of some of the properties of the setting. The following are the settings for the properties of the form to meet screen protection requirements, as follows:
this.Name = "ScreenSaver" ;
//窗体运行后无边界
this.FormBorderStyle = FormBorderStyle.None ;
//程序运行后不显示在任务栏上
this.ShowInTaskbar = false ;
//窗体运行后,最大化,充满整个屏幕
(2). Enables the character to move continuously on the screen:
The implementation of the character on the screen like the word Fu Shi keep moving, is done through a timer. The constantly moving character is actually a label component. When you set the character to display for the label component, you set the character to be moved on the screen. Timer every time, the label component of the horizontal axis minus a fixed value, so in the timer driver, the label component position changed, bring the visual effect, is the character constantly moving.
When the position of the label component has been moved outside the screen, this is to return the horizontal axis of the label component to the starting value (that is, the screen's rightmost), and then determine whether the ordinate of the label component is at the top of the screen and, if at the top, reset the ordinate position to the middle; , reset to the bottom, or at the bottom, reset to the top. Through these judgments, the character can not only move from right to left, but also can transform the character into the screen position. It also enriches the content of screen protection. In fact, to achieve these judgments, you must first know the work area of the screen, because only first know the work area of the screen, in the ability to achieve the label components of the horizontal and vertical coordinates of the work. Here is the specific code to implement this step:
//得到计算机屏幕的工作区域
Rectangle ssWorkArea = Screen.GetWorkingArea ( this ) ;
lblMarquee.Location = new Point ( ssWorkArea.Width - iDistance ,
lblMarquee.Location.Y ) ;
//显示标签
lblMarquee.Visible = true ;
// 增加2个象素点,你可以通过修改speed的值来改变标签的移动速度
iDistance += speed ;
// 如果标签已经走出屏幕,则把标签的位置重定位到屏幕的右边
if ( lblMarquee.Location.X <= -( lblMarquee.Width ) )
{
//Reset the distance to 0.
iDistance = 0 ;
//判断标签的位置是否在顶部,如果在,则重定位到中部
if ( lblMarquee.Location.Y == 0)
lblMarquee.Location = new Point ( lblMarquee.Location.X , ( ssWorkArea.Height / 2 ) ) ;
//判断标签的位置是否在中部,如果在,则重定位到底部
else if ( lblMarquee.Location.Y == ssWorkArea.Height / 2 )
lblMarquee.Location = new Point ( lblMarquee.Location.X , ssWorkArea.Height - lblMarquee.Height ) ;
//重定位到顶部
else
lblMarquee.Location = new Point ( lblMarquee.Location.X , 0 ) ;
}