欢迎光临
我们一直在努力

Beta2的ScreenSaver-.NET教程,Windows开发

建站超值云服务器,限时71元/月

namespace screen_saver
{
using system;
using system.drawing;
using system.collections;
using system.componentmodel;
//using system.winforms;
using system.windows.forms;
using system.data;
    
/// <summary>
///    summary description for form1.
/// </summary>
public class screensaver : system.windows.forms.form
{
  /// <summary>
  ///    required designer variable.
  /// </summary>
  private system.componentmodel.container components;
  //private system.winforms.timer timersaver;
  private system.windows.forms.timer timersaver;
  //private system.winforms.label lblmarquee;
        private system.windows.forms.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.windows.forms.cursor.hide();
   //system.drawing.cursor.hide();              
  }
  /// <summary>
  ///    clean up any resources being used.
  /// </summary>
  public override void dispose()
  {
   base.dispose();
   components.dispose();
  }
  /// <summary>
  ///    required method for designer support – do not modify
  ///    the contents of this method with the code editor.
  /// </summary>
  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.timersaver=new system.windows.forms.timer(this.components);
   this.lblmarquee=new system.windows.forms.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.startposition=system.windows.forms.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.windowstate=system.windows.forms.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.keydown+=new system.windows.forms.keyeventhandler(this.form1_keydown);
   //this.mousedown += new system.winforms.mouseeventhandler (this.form1_mousedown);
   this.mousedown+=new system.windows.forms.mouseeventhandler(this.form1_mousedown);
   //this.mousemove += new system.winforms.mouseeventhandler (this.form1_mousemove);
   this.mousemove+=new system.windows.forms.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);
   system.drawing.rectangle ssworkarea=system.windows.forms.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.windows.forms.mouseeventargs e)
  {
   stopscreensaver();
  }
  protected void form1_mousemove (object sender,system.windows.forms.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();  
   system.windows.forms.cursor.show();
   timersaver.enabled=false;
   application.exit();
  }
  protected void form1_keydown (object sender, system.windows.forms.keyeventargs e)
  {
   stopscreensaver();            
  }
  /// <summary>
  /// the main entry point for the application.
  /// </summary>
  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",system.windows.forms.messageboxbuttons.ok,system.windows.forms.messageboxicon.information);
      //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",system.windows.forms.messageboxbuttons.ok,system.windows.forms.messageboxicon.information);
      //messagebox.iconinformation);
     application.exit();
    }
   }            
    //for any other args –> start.
   else                 
    application.run(new screensaver());
  }
            
}
}

赞(0)
版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com 特别注意:本站所有转载文章言论不代表本站观点! 本站所提供的图片等素材,版权归原作者所有,如需使用,请与原作者联系。未经允许不得转载:IDC资讯中心 » Beta2的ScreenSaver-.NET教程,Windows开发
分享到: 更多 (0)