新书推介:《语义网技术体系》
作者:瞿裕忠,胡伟,程龚
   XML论坛     W3CHINA.ORG讨论区     计算机科学论坛     SOAChina论坛     Blog     开放翻译计划     新浪微博  
 
  • 首页
  • 登录
  • 注册
  • 软件下载
  • 资料下载
  • 核心成员
  • 帮助
  •   Add to Google

    >> 本版讨论高级C/C++编程、代码重构(Refactoring)、极限编程(XP)、泛型编程等话题
    [返回] 计算机科学论坛计算机技术与应用『 C/C++编程思想 』 → 用C#做ScreenSaver 查看新帖用户列表

      发表一个新主题  发表一个新投票  回复主题  (订阅本版) 您是本帖的第 2437 个阅读者浏览上一篇主题  刷新本主题   树形显示贴子 浏览下一篇主题
     * 贴子主题: 用C#做ScreenSaver 举报  打印  推荐  IE收藏夹 
       本主题类别:     
     卷积内核 帅哥哟,离线,有人找我吗?
      
      
      威望:8
      头衔:总统
      等级:博士二年级(版主)
      文章:3942
      积分:27590
      门派:XML.ORG.CN
      注册:2004/7/21

    姓名:(无权查看)
    城市:(无权查看)
    院校:(无权查看)
    给卷积内核发送一个短消息 把卷积内核加入好友 查看卷积内核的个人资料 搜索卷积内核在『 C/C++编程思想 』的所有贴子 访问卷积内核的主页 引用回复这个贴子 回复这个贴子 查看卷积内核的博客楼主
    发贴心情 用C#做ScreenSaver


    /* Program : A Simple Screen Saver
    * File Name : ScreenSaver.cs
    */

    namespace Screen_Saver
    {
    using System;
    using System.Drawing;
    using System.Collections;
    using System.ComponentModel;
    using System.WinForms;
    using System.Data;


    ///
    /// Summary description for Form1.
    ///
    public class ScreenSaver : System.WinForms.Form
    {
    ///
    /// Required designer variable.
    ///
    private System.ComponentModel.Container components;
    private System.WinForms.Timer timerSaver;
    private System.WinForms.Label lblMarquee;

    private int iSpeed = 2;
    private string strMarqueeText="C Sharp Screen Saver";

    private System.Drawing.Font fontMarquee = new System.Drawing.Font ("Arial", 20,
    System.Drawing.FontStyle.Bold);
    private Color colorMarquee = System.Drawing.Color.FromARGB(255,255,255);

    private int iDistance;
    private int ixStart= 0;
    private int iyStart= 0;

    public ScreenSaver()
    {
    InitializeComponent();

    lblMarquee.Font=fontMarquee;
    lblMarquee.ForeColor=colorMarquee;
    System.Drawing.Cursor.Hide();
    }

    ///
    /// Clean up any resources being used.
    ///
    public override void Dispose()
    {
    base.Dispose();
    components.Dispose();
    }

    ///
    /// Required method for Designer support - do not modify
    /// the contents of this method with the code editor.
    ///
    private void InitializeComponent()
    {
    System.Resources.ResourceManager resources = new System.Resources.ResourceManager (typeof
    (ScreenSaver));
    this.components = new System.ComponentModel.Container ();
    this.timerSaver = new System.WinForms.Timer (this.components);
    this.lblMarquee = new System.WinForms.Label ();
    //@this.TrayHeight = 90;
    //@this.TrayLargeIcon = false;
    //@this.TrayAutoArrange = true;
    //@timerSaver.SetLocation (new System.Drawing.Point (7, 7));
    timerSaver.Interval = 1;
    timerSaver.Enabled = true;
    timerSaver.Tick += new System.EventHandler (this.timerSaver_Tick);
    lblMarquee.Location = new System.Drawing.Point (88, 0);
    lblMarquee.Size = new System.Drawing.Size (128, 48);
    lblMarquee.ForeColor = System.Drawing.Color.White;
    lblMarquee.TabIndex = 0;
    lblMarquee.Visible = false;
    this.MaximizeBox = false;
    this.StartPosition = System.WinForms.FormStartPosition.Manual;
    this.AutoScaleBaseSize = new System.Drawing.Size (5, 13);
    this.BorderStyle = System.WinForms.FormBorderStyle.None;
    this.KeyPreview = true;
    this.WindowState = System.WinForms.FormWindowState.Maximized;
    this.ShowInTaskbar = false;
    this.Icon = (System.Drawing.Icon) resources.GetObject ("$this.Icon");
    this.ControlBox = false;
    this.MinimizeBox = false;
    this.BackColor = System.Drawing.Color.Black;
    this.ClientSize = new System.Drawing.Size (300, 300);
    this.KeyDown += new System.WinForms.KeyEventHandler (this.Form1_KeyDown);
    this.MouseDown += new System.WinForms.MouseEventHandler (this.Form1_MouseDown);
    this.MouseMove += new System.WinForms.MouseEventHandler (this.Form1_MouseMove);
    this.Controls.Add (this.lblMarquee);
    }

    protected void timerSaver_Tick (object sender, System.EventArgs e)
    {
    lblMarquee.Text=strMarqueeText;
    lblMarquee.Height=lblMarquee.Font.Height;
    lblMarquee.Width=lblMarquee.Text.Length*(int)lblMarquee.Font.Size;

    PlayScreenSaver();
    }

    private void PlayScreenSaver()
    {
    //Get the working area of the the computer screen.
    System.Drawing.Rectangle ssWorkArea = System.WinForms.Screen.GetWorkingArea(this);

    lblMarquee.Location=new System.Drawing.Point(ssWorkArea.Width - iDistance,
    lblMarquee.Location.Y);

    //Make the label visible if it is not currently visible.
    lblMarquee.Visible=true;

    // Increment the label distance based on the speed set by the user.
    iDistance += iSpeed;
    // If the label is offscreen, then we want to reposition it to the right.
    if (lblMarquee.Location.X <= -(lblMarquee.Width))
    {
    //Reset the distance to 0.
    iDistance = 0;

    //If the label is at the top, move it to the middle.
    if (lblMarquee.Location.Y == 0)
    lblMarquee.Location=new System.Drawing.Point(lblMarquee.Location.X,
    (ssWorkArea.Height / 2));

    // If label is in the middle of the screen move it to the bottom.
    else if(lblMarquee.Location.Y== ssWorkArea.Height /2)
    lblMarquee.Location=new System.Drawing.Point(lblMarquee.Location.X,ssWorkArea.Height -
    lblMarquee.Height);
    //Move the label back to the top.
    else
    lblMarquee.Location=new System.Drawing.Point(lblMarquee.Location.X,0);
    }
    }

    protected void Form1_MouseDown (object sender, System.WinForms.MouseEventArgs e)
    {
    StopScreenSaver();
    }

    protected void Form1_MouseMove (object sender, System.WinForms.MouseEventArgs e)
    {
    // Determine if the mouse cursor position has been stored previously.
    if (ixStart == 0 && iyStart == 0)
    {
    //Store the mouse cursor coordinates.
    ixStart = e.X;
    iyStart = e.Y;
    return;
    }
    // Has the mouse cursor moved since the screen saver was started?
    else if (e.X != ixStart || e.Y != iyStart)
    StopScreenSaver();

    }

    private void StopScreenSaver()
    {
    System.Drawing.Cursor.Show();
    timerSaver.Enabled=false;
    Application.Exit();
    }

    protected void Form1_KeyDown (object sender, System.WinForms.KeyEventArgs e)
    {
    StopScreenSaver();
    }

    ///
    /// The main entry point for the application.
    ///
    public static void Main(string[] args)
    {
    if (args.Length==1)
    {
    //Display the options dialog box.
    if (args[0].Substring(0,2).Equals("/c"))
    {
    MessageBox.Show("Options are not available for this screen saver",
    " C# Screen Saver",
    MessageBox.IconInformation);
    Application.Exit();
    }
    //Start the screen saver normally.
    else if (args[0]=="/s")
    Application.Run(new ScreenSaver());

    //Diaplay the password dialog
    else if (args[0]=="/a")
    {
    MessageBox.Show("Passwords are not available for this screen saver",
    " C# Screen Saver",
    MessageBox.IconInformation);
    Application.Exit();
    }
    }
    //For any other args --> start.
    else
    Application.Run(new ScreenSaver());
    }

    }
    }


       收藏   分享  
    顶(0)
      




    ----------------------------------------------
    事业是国家的,荣誉是单位的,成绩是领导的,工资是老婆的,财产是孩子的,错误是自己的。

    点击查看用户来源及管理<br>发贴IP:*.*.*.* 2007/12/13 14:01:00
     
     GoogleAdSense
      
      
      等级:大一新生
      文章:1
      积分:50
      门派:无门无派
      院校:未填写
      注册:2007-01-01
    给Google AdSense发送一个短消息 把Google AdSense加入好友 查看Google AdSense的个人资料 搜索Google AdSense在『 C/C++编程思想 』的所有贴子 访问Google AdSense的主页 引用回复这个贴子 回复这个贴子 查看Google AdSense的博客广告
    2025/7/25 12:12:16

    本主题贴数1,分页: [1]

    管理选项修改tag | 锁定 | 解锁 | 提升 | 删除 | 移动 | 固顶 | 总固顶 | 奖励 | 惩罚 | 发布公告
    W3C Contributing Supporter! W 3 C h i n a ( since 2003 ) 旗 下 站 点
    苏ICP备05006046号《全国人大常委会关于维护互联网安全的决定》《计算机信息网络国际联网安全保护管理办法》
    2,464.844ms