首页 | 互联网 | IT动态 | IT培训 | Cisco | Windows | Linux | Java | .Net | Oracle | 软件测试 | C/C++ | 嵌入式开发 | 存储世界 | 服务器
网络设备 | IDC | 安全 | 求职招聘 | 数字网校 | 网页设计 | 平面设计 | 技术专题 | 电子书下载 | 教学视频 | 源码下载 | 搜索 | 博客 | 论坛
中国IT实验室Dotnet频道
中国IT教育
Google
首页 ASP.NET  C#  XML/WebService ADO.NET VC.NET VB.NET .NET 资讯动态 专题 RSS订阅 讨论 下载
您现在的位置: 中国IT实验室 >> Dotnet >> C# >> 正文

用Visual C#编写屏幕保护程序

Visual C#是微软公司推出的新一代程序开发语言,是微软.Net框架中的一个重要组成部分。屏幕保护程序是以scr为扩展名的标准Windows可执行程序。屏幕保护程序不仅可以延长显示器的使用寿命,还可以保护私人信息。本文向大家介绍一个.Net平台上用C#编写的一个动态文本及图形的屏幕保护程序。

  一、具体实现步骤:

  (1)在Visual Studio.Net下新建一个C#的Windows应用程序工程,不妨命名为screen_saver。

  (2)现在我们来设计程序的主界面:

  先将窗体的Name属性设置为screen、Text属性设置为空,BackColor属性设置为Black、Size属性设置为(800, 600)、 ControlBox、MaximizeBox、MinimizeBox、ShowInTaskbar属性设置均为false、 FormBorderStyle属性设置为None。再往窗体上添加Label控件、PictureBox控件、Timer控件各一个。将Label控件的Name设置为word、Text属性设置为空;将PictureBox控件的Name设置为picture1、Image设置为一个预知图片;将 Timer控件的Name设置为timerSaver、Enabled 属性设为true、Interval属性设为5。

  (3)现在我们开始编写完整程序代码部分:
//导入使用到的名称空间

using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
file://

    namespace screen_saver
    {
///
/// Form1 的摘要说明。
///

public class screen : System.Windows.Forms.Form
{
  file://加入私有成员变量

  private System.ComponentModel.IContainer components;
  private int iSpeed = 2;
  private string str="福建南纺股份公司计算机中心";
  file://定义文本字体及大小

  private System.Drawing.Font TextStringFont = new System.Drawing.Font ("宋体”, 10,System.Drawing.FontStyle.Bold);

  private Color TextStringcolor =System.Drawing.Color.Yellow; file://文本字体颜色

  private int iDistance;
  private int ixStart= 0;
  private int iyStart= 0;
  private int speed;
  private int x1,y1;
  int width1,height1;
  private System.Windows.Forms.Timer timerSaver;  file://计时器控件

  private System.Windows.Forms.PictureBox picture1; file://图形控件

  private System.Windows.Forms.Label word; file://文本显示控件

///
/// 必需的设计器变量。
///

  public screen()
  {
  file://
  // Windows 窗体设计器支持所必需的

  file://

   InitializeComponent();
   word.Font=TextStringFont;
   word.ForeColor=TextStringcolor;
   System.Windows.Forms.Cursor.Hide(); file://隐藏光标

   file://
   // TODO: 在 InitializeComponent 调用后添加任何构造函数代码

   file://

  }
  ///
  /// 清理所有正在使用的资源。
  ///

  protected override void Dispose( bool disposing )
  {
   if( disposing )
   {
    if (components != null)
    {
     components.Dispose();
    }
   }
   base.Dispose( disposing );
  }
  #region Windows Form Designer generated code
  ///
  /// 设计器支持所需的方法 - 不要使用代码编辑器修改
  /// 此方法的内容。
  ///

 

 


[1] [2] [3] [4] 下一页

【责编:Luzi】

中国IT教育

相关产品和培训
文章评论
 友情推荐链接
 认证培训
 专题推荐

 ·WEB程序开发--ASP.NET和PHP、JSP究竟学哪个?
 ·五步带你入门XML
 ·关于Java框架技术专题
 ·XML全攻略技术专题
 ·JAVA开源技术介绍专题
 ·Java嵌入式开发之J2ME技术专题
 ·超前体验 Oracle 11g的5个新特性…
 ·揭密使用VB.NET的五个实用技巧
 ·Oracle和SQL Server常用函数对比专题…
 ·展现C#世界 C#程序设计专题…
 今日更新
 社区讨论
 博客论点
 频道精选
 Dotnet频道相关导航