设为首页 友情链接
在线留言 发表文章
加入收藏 广告联系

刺猬首页

| 专案技术 | 网络技术 | 图形图象 | 网络编程 | 网页设计 | 操作系统 | 服务器 | 技术白皮书 | 在线实验室 | 刺猬论坛 |
  | 数据库 | 设计赏析 | 存储频道 | 网络安全 | 私服架设 |  Solaris | 网站评估 | PC维护技巧 | 下载中心 | 博 客 |
专题: | Linux | java | cisco | 防病毒 | 刀片 | SOA | iscsi | ASP.NET | SQL | Oracle |
您现在的位置: IT公社 IT community >> 网络编程 >> C# >> 教程正文 用户登录 新用户注册
专 题 栏 目
最 新 热 门
最 新 推 荐
相 关 文 章
变脸:用CSS+JS打造的网…
用CSS实现动态显示的五角…
用css实现文字的自动隐藏
PHP中使用crypt()实现用…
使用C#开发SmartPhone程…
用C#实现智能设备上的No…
用CSS样式表控制鼠标显示…
制作网页学习之常用CSS实…
VS2005中使用C#的新特性…
C#获取WAVE文件文件头信…
  用C#Builder编写屏幕保护程序         ★★★★★
用C#Builder编写屏幕保护程序
 

【导读】屏幕保护程序是以scr为扩展名的标准Windows可执行程序。屏幕保护程序不仅可以延长显示器的使用寿命,还可以保护私人信息。本文向大家介绍一个用C# Builder编写的一个动态文本及图形的屏幕保护程序。 屏幕保护程序是以scr为扩展名的标准Windows可执行程序。屏幕保护程序不仅可以延长显示器的使用寿命,还可以保护私人信息。本文向大家介绍一个用C# Builder编写的一个动态文本及图形的屏幕保护程序。

具体实现步骤 

(1)在C# Builder下新建一个C#的Windows应用程序工程,这里命名为screensaver。

启动C# Builder,通过菜单File->New->C# Application 

(2)界面的设计

先将窗体的BackColor属性设置为Black、Size属性设置为(800, 600)、 ControlBox、MaximizeBox、MinimizeBox、ShowInTaskbar属性设置均为false、FormBorderStyle属性设置为None, WindowStaus设为Maximized,StartPosition设置为CenterScreen。

再往窗体上添加Label控件、PictureBox控件、Timer控件各一个。将Label控件的Text属性设置为“悠游在线欢迎您!”;将PictureBox控件的Name设置为picture1、Image设置为一个预知图片;将Timer控件的Enabled 属性设为true、Interval属性设为5。

(3)程序的编码

//加入以下私有成员变量

private int iSpeed = 2;

private int iDistance;

private int ixStart= 0;

private int iyStart= 0;

private int speed;

private int x1,y1;

private int width1,height1;

//双击Form,在其Load事件输入下面的代码:

speed=0;

System.Drawing.Rectangle ssWorkArea=System.Windows.Forms.Screen.GetWorkingArea(this);

//屏幕显示区域

width1=ssWorkArea.Width; //屏幕宽度

height1=ssWorkArea.Height; //屏幕高度

//From的KeyDown,MouseDown,MouseMove事件中都输入以下代码:

Application.Exit();

//timer1的Tick事件输入下面代码:

//下面设置文本显示框的位置坐标

label1.Location =new System.Drawing.Point(width1-iDistance,label1.Location.Y);

label1.Visible=true; //设置为可见

iDistance+=iSpeed;

if(label1.Location.X<=-(label1.Width))

{

iDistance=0;

if(label1.Location.Y==0)

label1.Location=new System.Drawing.Point(label1.Location.X,height1/2);

else if(label1.Location.Y==height1/2)

label1.Location=new System.Drawing.Point(label1.Location.X,height1-label1.Height);

else

label1.Location=new System.Drawing.Point(label1.Location.X,0);

}

//下面是计算图片框移动坐标

speed++;

if(speed<=2*height1)

{

x1=System.Math.Abs(width1-speed);

y1=System.Math.Abs(height1-speed);

}

else if(speed>2*height1 && speed<=2*width1)

{

x1=System.Math.Abs(width1-speed);

y1=System.Math.Abs(height1-(speed-speed/height1*height1));

}

else if(speed>2*width1 &&speed<=3*height1)

{

x1=System.Math.Abs(width1-(speed-speed/width1*width1));

y1=System.Math.Abs(height1-(speed-speed/height1*height1));

}

else if(speed>3*height1 && speed<4*height1)

{

x1=System.Math.Abs(width1-(speed-speed/width1*width1));

y1=System.Math.Abs(speed-speed/height1*height1);

}

else if(speed>=4*height1 && speed<5*height1)

{

x1=System.Math.Abs(speed-speed/width1*width1);

y1=System.Math.Abs(height1-(speed-speed/height1*height1));

}

else if(speed>=5*height1 && speed<4*width1)

{

x1=System.Math.Abs(speed-speed/width1*width1);

y1=System.Math.Abs(speed-speed/height1*height1);

}

else if(speed>=4*width1 && speed<6*height1)

{

x1=System.Math.Abs(width1-(speed-speed/width1*width1));

y1=System.Math.Abs(speed-speed/height1*height1);

}

else if(speed>=6*height1 && speed<5*width1)

{

x1=System.Math.Abs(width1-(speed-speed/width1*width1));

y1=System.Math.Abs(height1-(speed-speed/height1*height1));

}

else if(speed>=5*width1 && speed<7*height1)

{

x1=System.Math.Abs(speed-speed/width1*width1);

y1=System.Math.Abs(height1-(speed-speed/height1*height1));

}

else if(speed>=7*height1 && speed<6*width1)

{

x1=System.Math.Abs(speed-speed/width1*width1);

y1=System.Math.Abs(speed-speed/height1*height1);

}

if(speed==6*width1)

speed=0;

pictureBox1.Location=new System.Drawing.Point(x1,y1);

( 4)程序的编译 

最后编译程序,C# Builder会在工程所在目录的BIN\Debug\ScreenSaver.exe文件,我们把ScreenSaver.exe改为ScreenSaver.scr,拷入Windows系统目录中,这样就可以运行该屏幕保护程序。

在屏幕保护设置为ScreenSaver,看看效果怎么样!

频道声明:本频道的文章除部分特别声明禁止转载的专稿外,可以自由转载.但请务必注明出出处和原始作者 文章版权归本频道与文章作者所有.对于被频道转载文章的个人和网站,我们表示深深的谢意。

原始作者:佚名 录入时间:2006-10-10
信息来源:不详 投稿信箱:itqoo@126.com
教程录入:admin    责任编辑:admin 
  • 上一个教程:

  • 下一个教程:
  • 【字体: 】【发表评论】【加入收藏】【告诉好友】【打印此文】【关闭窗口
      网友评论:(只显示最新10条。评论内容只代表网友观点,与本站立场无关!)
    - 关于我们 - 合作伙伴 - 友情链接 - 广告刊登 - 投稿热线 - 在线留言版权声明联系方式 -
    IT公社版权所有 粤ICP备05127012号
    Copyrigh@2005-2006 itqoo.com.Inc All Rights Reserved  推荐分辨率 1024*768
    联系站长:E-Mail:itqoo@126.com     MSN:urchincc@hotmail.com    QQ:点击这里给我发消息
    特别感谢:亿太网络提供空间支持