当前位置:编程学习 > C#/ASP.NET >>

C#winForm中,怎样添加屏幕保护特效?

要做一个特效,FLash制作那边基本上不会。

想要那种屏幕保护的效果,是在一个考试系统中,答错一道题目就触发那个屏幕保护效果:锁屏,屏幕开始碎裂,一块一块掉下来。。。

怎样才能把屏幕保护直接给搞到程序中啊?或者说,能不能实现啊?

小女不才,高手帮助~
--------------------编程问答-------------------- 取到当前屏幕的截图,然后随机替换颜色,然后将被替换的颜色往下移动,应该这么写就行了吧?
--------------------编程问答-------------------- 先把特效做成gif格式的图片,然后在winfrom中做一个窗口,这个窗口就显示那gif图片,在答错题目就弹出这个窗口(弹出时一模式窗口弹出这样就操能操作当前窗口) --------------------编程问答-------------------- >>2楼
不会gif特效啊。。。能不能直接调用屏幕保护程序呢? --------------------编程问答-------------------- 努力回帖,学习中…… --------------------编程问答-------------------- 纠结。。。求回答啊!!!!!!!!!~~~~~~~~~~~~~~~~ --------------------编程问答-------------------- 先将窗体的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。 

//导入使用到的名称空间 

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 

 /// 

 /// 设计器支持所需的方法 - 不要使用代码编辑器修改 

 /// 此方法的内容。 

 /// 

 private void InitializeComponent() file://初始化程序中使用到的组件 

 { 

  this.components = new System.ComponentModel.Container(); 

  System.Resources.ResourceManager resources = new   system.Resources.ResourceManger(typeof(screen));       

  this.word = new System.Windows.Forms.Label(); 

  this.timerSaver = new System.Windows.Forms.Timer(this.components); 

  this.picture1 = new System.Windows.Forms.PictureBox(); 

  this.SuspendLayout(); 

  // 

  // 设置文本显示控件(word)属性 

  this.word.ForeColor = System.Drawing.Color.Yellow; 

  this.word.Location = new System.Drawing.Point(624, 8); 

  this.word.Name = "word"; 

  this.word.Size = new System.Drawing.Size(168, 16); 

  this.word.TabIndex = 0; 

  this.word.Visible = false; 

  // 

  // 设置计时器控件(timerSaver)属性 

  this.timerSaver.Enabled = true; 

  this.timerSaver.Interval = 5; 

  this.timerSaver.Tick += new System.EventHandler(this.timerSaver_Tick); 

  // 

  // 设置图片控件(picture1)属性 

  this.picture1.Image = ((System.Drawing.Bitmap)(resources.GetObject("picture1.Image"))); 

  this.picture1.Location = new System.Drawing.Point(800, 600); 

  this.picture1.Name = "picture1"; 

  this.picture1.Size = new System.Drawing.Size(304, 224); 

  this.picture1.SizeMode = System.Windows.Forms.PictureBoxSizeMode.StretchImage; 

  this.picture1.TabIndex = 1; 

  this.picture1.TabStop = false; 

  // 

  // 设置窗体(screen)属性 

  this.AutoScaleBaseSize = new System.Drawing.Size(6, 14); 

  this.BackColor = System.Drawing.Color.Black; 

  this.ClientSize = new System.Drawing.Size(800, 600); 

  this.ControlBox = false; 

  this.Controls.AddRange(new System.Windows.Forms.Control[] {this.picture1,this.word}); 

  this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None; 

  this.KeyPreview = true; 

  this.MaximizeBox = false; 

  this.MinimizeBox = false; 

  this.Name = "screen"; 

  this.ShowInTaskbar = false; 

  this.StartPosition = System.Windows.Forms.FormStartPosition.Manual; 

  this.WindowState = System.Windows.Forms.FormWindowState.Maximized; 

  file://键盘按下响应事件 

  this.KeyDown += new System.Windows.Forms.KeyEventHandler(this.screen_KeyDown); 

            file://鼠标按下响应事件 
  
  this.MouseDown += new System.Windows.Forms.MouseEventHandler(this.screen_MouseDown); 

  file://窗体启动调用事件 

  this.Load += new System.EventHandler(this.Form1_Load); 

            file://鼠标移动响应事件 

  this.MouseMove += new System.Windows.Forms.MouseEventHandler(this.screen_MouseMove); 

  this.ResumeLayout(false); 

 } 

 #endregion 

 /// 

 /// 应用程序的主入口点。 

 /// 

 [STAThread] 

 static void Main(string[] args) 

 { 

  if(args.Length==1) 

   if(args[0].Substring(0,2).Equals("/c")) 

   { 

    MessageBox.Show("没有设置项功能","C# Screen Saver"); 

    Application.Exit(); 

   } 

   else if(args[0]=="/s") 

   Application.Run(new screen()); 

  else if(args[0]=="/a") 

  { 

   MessageBox.Show("没有口令功能","C# Screen saver"); 

   Application.Exit(); 

  } 

  else 

  Application.Run(new screen()); 

 } 



 private void Form1_Load(object sender, System.EventArgs e) 

 { 

  speed=0; 

  System.Drawing.Rectangle ssWorkArea=System.Windows.Forms.Screen.GetWorkingArea(this); 
  file://屏幕显示区域 

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

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

 } 


 private void timerSaver_Tick(object sender, System.EventArgs e) file://计时器响应事件 

 { 

  word.Visible=true; 

  word.Text=str; 

  word.Height=word.Font.Height; file://设置文本的高度 

  word.Width=word.Text.Length*(int)word.Font.Size*2; file://设置文本的宽度 

  PlayScreenSaver(); 

 } 

 private void PlayScreenSaver() file://自定义函数 

 { 

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

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

  word.Visible=true; file://设置为可见 

  iDistance+=iSpeed; 

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

  { 

   iDistance=0; 

   if(word.Location.Y==0) 

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

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

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

   else 

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

  } 

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

  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; 

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

 } 

 private void StopScreenSaver() file://停止屏幕保护程序运行 

 { 

  System.Windows.Forms.Cursor.Show(); 

  timerSaver.Enabled=false; 

  Application.Exit(); 

 } 


 private void screen_MouseMove(object sender, System.Windows.Forms.MouseEventArgs e)  
 file://鼠标移动事件 

 { 

  if(ixStart==0 && iyStart==0) 

  { 

   ixStart=e.X; 

   iyStart=e.Y; 

   return; 

  } 

  else if(e.X!=ixStart||e.Y!=iyStart) 

  StopScreenSaver(); 

 } 

 private void screen_MouseDown(object sender, System.Windows.Forms.MouseEventArgs e) 
 file://鼠标按下事件 

 { 

  StopScreenSaver(); file://停止运行屏幕保护程序 

 } 

 private void screen_KeyDown(object sender, System.Windows.Forms.KeyEventArgs e)  
 file://键盘按下事件 

 { 

  StopScreenSaver(); file://停止运行屏幕保护程序 

 } 





--------------------编程问答--------------------
引用 6 楼 rjianfeili 的回复:
先将窗体的Name属性设置为screen、Text属性设置为空,BackColor属性设置为Black、Size属性设置为(800, 600)、 ControlBox、MaximizeBox、MinimizeBox、ShowInTaskbar属性设置均为false、FormBorderStyle属性设置为None。再往窗体上添加Label控件、PictureBox控件、Timer控件各一个。将La……


太谢谢啦!不过有点小迷糊,我抽空再看看!~先谢过~ --------------------编程问答-------------------- 你可以直接掉windoows的锁屏
补充:.NET技术 ,  C#
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,