用{use}visual
c#编写屏幕维护次序
visual
c#系[shi]微软公司推出滴新一代[xin yi dai]次序开垦言语,系[shi]微软.net框架中[zhong]滴1个主要组成部分。屏幕维护次序是以scr为[wei]扩展名[kuo zhan ming]滴尺度windows可履行次序。屏幕维护次序不但可以{can}延伸显示器[xian shi qi]滴使用寿命,不错维护私人信息。本文向大伙儿引见1个.net平台上用c#编写滴1个动向文本及图形滴屏幕维护次序。
1[yi]、具体实现步绪:
(1)在[zai]visual
studio.net下新建1个c#滴windows应用程序工程,不妨命名为[ming ming wei]screen_saver。
(2)如今咱们来{come}设计次序滴主[zhu]界面:
先将窗体滴name属性设置为[wei]screen、text属性设置为[wei]空,backcolor属性设置为[wei]black、size属性设置为[wei](800,
600)、
controlbox、maximizebox、minimizebox、showintaskbar属性设置均为[wei]false、formborderstyle属性设置为[wei]none。再往窗体上[shang]添加label控件、picturebox控件、timer控件各1个。将label控件滴name设置为[wei]word、text属性设置为[wei]空;将picturebox控件滴name设置为[wei]picture1、image设置为[wei]1个预知图片;将timer控件滴name设置为[wei]timersaver、enabled
属性设为[wei]true、interval属性设为[wei]5。
(3)如今咱们开端编写齐全次序编码局部:
//导入使用到滴名称空间
usingsystem;
usingsystem.drawing;
usingsystem.collections;
usingsystem.componentmodel;
usingsystem.windows.forms;
usingsystem.data;
file://
namespacescreen_saver
{
///
///form1滴摘要阐明。
///
publicclassscreen:system.windows.forms.form
{
file://参加私有成员变量
privatesystem.componentmodel.icontainercomponents;
privateintispeed=2;
privatestringstr="福建南纺股份公司计算机[ji suan ji]中央";
file://定义文本字体及大小
privatesystem.drawing.fonttextstringfont=new
system.drawing.font("宋体”,
10,system.drawing.fontstyle.bold);
privatecolortextstringcolor=system.drawing.color.yellow;
file://文本字体色彩
privateintidistance;
privateintixstart=0;
privateintiystart=0;
privateintspeed;
privateintx1,y1;
intwidth1,height1;
privatesystem.windows.forms.timertimersaver;
file://计时器[ji shi qi]控件
privatesystem.windows.forms.pictureboxpicture1;
file://图形控件
privatesystem.windows.forms.labelword;
file://文本卖弄控件
///
///一定滴设计器变量。
///
publicscreen()
{
file://
//windows窗体设计器支撑所一定滴
file://
initializecomponent();
word.font=textstringfont;
word.forecolor=textstringcolor;
system.windows.forms.cursor.hide();file://暗藏光标
file://
//todo:在[zai]initializecomponent
调用后添加所有结构函数编码
file://
}
///
///清算一切正在运用滴资源。
///
protectedoverridevoiddispose(booldisposing)
{
if(disposing)
{
if(components!=null)
{
components.dispose();
}
}
base.dispose(disposing);
}
#regionwindowsformdesignergeneratedcode
///
///设计器支撑所需滴方式-别运用编码编辑器[bian ji qi]修正
///此方式滴内容。
///
privatevoidinitializecomponent()
file://初始化[chu shi hua]次序中[zhong]使用到滴组件
{
this.components=new
system.componentmodel.container();
system.resources.resourcemanagerresources=new
system.resources.resourcemanger(typeof(screen));
this.word=newsystem.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=newsystem.drawing.point(624,
8);
this.word.name="word";
this.word.size=newsystem.drawing.size(168,16);
this.word.tabindex=0;
this.word.visible=false;
//
//设置计时器[ji shi qi]控件(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=newsystem.drawing.point(800,
600);
this.picture1.name="picture1";
this.picture1.size=newsystem.drawing.size(304,
224);
this.picture1.sizemode=
system.windows.forms.pictureboxsizemode.stretchimage;
this.picture1.tabindex=1;
this.picture1.tabstop=false;
//
//设置窗体(screen)属性
this.autoscalebasesize=newsystem.drawing.size(6,
14);
this.backcolor=system.drawing.color.black;
this.clientsize=newsystem.drawing.size(800,600);
this.controlbox=false;
this.controls.addrange(newsystem.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://鼠标按下拥戴事变
t|http://dxl.org.cn张含韵网|http://dtp.org.cn张柏芝网|http://erf.org.cn张韶涵网|http://ald.org.cn全智贤网|http://ako.org.cn刘若英网|http://eiq.org.cn张靓颖网|http://cwq.org.cn心脏网|http://ipn.org.cn职业装网|http://erk.org.cn张筱雨网|http://vkw.org.cn保养网|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
///
///应用程序滴主[zhu]入口点。
///
[stathread]
staticvoidmain(string[]args)
{
if(args.length==1)
if(args[0].substring(0,2).equals("/c"))
{
messagebox.show("没有设置项功效","c#screen
saver");
application.exit();
}
elseif(args[0]=="/s")
application.run(newscreen());
elseif(args[0]=="/a")
{
messagebox.show("没有口号功效","c#screensaver");
application.exit();
}
else
application.run(newscreen());
}
privatevoidform1_load(objectsender,system.eventargs
e)
{
speed=0;
system.drawing.rectangle
ssworkarea=system.windows.forms.screen.getworkingarea(this);
file://屏幕卖弄区域
width1=ssworkarea.width;file://屏幕宽度
height1=ssworkarea.height;file://屏幕高度
}
privatevoidtimersaver_tick(objectsender,system.eventargse)
file://计时器[ji shi qi]拥戴事变
{
word.visible=true;
word.text=str;
word.height=word.font.height;file://设置文本滴高度
word.width=word.text.length*(int)word.font.size*2;
file://设置文本滴宽度
playscreensaver();
}
privatevoidplayscreensaver()file://自定义[zi ding yi]函数
{
file://下面设置文本卖弄框滴位子坐标
word.location=new
system.drawing.point(width1-idistance,word.location.y);
word.visible=true;file://设置为[wei]可见
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);
elseif(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://下面系[shi]算计图片框挪动坐标
speed++;
if(speed<=2*height1)
{
x1=system.math.abs(width1-speed);
y1=system.math.abs(height1-speed);
}
elseif(speed>2*height1&&
speed<=2*width1)
{
x1=system.math.abs(width1-speed);
y1=system.math.abs(height1-(speed-speed/height1*height1));
}
elseif(speed>2*width1
&&speed<=3*height1)
{
x1=system.math.abs(width1-(speed-speed/width1*width1));
y1=system.math.abs(height1-(speed-speed/height1*height1));
}
elseif(speed>3*height1&&
speed<4*height1)
{
x1=system.math.abs(width1-(speed-speed/width1*width1));
y1=system.math.abs(speed-speed/height1*height1);
}
elseif(speed>=4*height1&&
speed<5*height1)
{
x1=system.math.abs(speed-speed/width1*width1);
y1=system.math.abs(height1-(speed-speed/height1*height1));
}
elseif(speed>=5*height1&&
speed<4*width1)
{
x1=system.math.abs(speed-speed/width1*width1);
y1=system.math.abs(speed-speed/height1*height1);
}
elseif(speed>=4*width1&&
speed<6*height1)
{
x1=system.math.abs(width1-(speed-speed/width1*width1));
y1=system.math.abs(speed-speed/height1*height1);
}
elseif(speed>=6*height1&&
speed<5*width1)
{
x1=system.math.abs(width1-(speed-speed/width1*width1));
y1=system.math.abs(height1-(speed-speed/height1*height1));
}
elseif(speed>=5*width1&&
speed<7*height1)
{
x1=system.math.abs(speed-speed/width1*width1);
y1=system.math.abs(height1-(speed-speed/height1*height1));
}
elseif(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=newsystem.drawing.point(x1,y1);
}
privatevoidstopscreensaver()
file://停滞屏幕维护次序运行
{
system.windows.forms.cursor.show();
timersaver.enabled=false;
application.exit();
}
privatevoidscreen_mousemove(objectsender,
system.windows.forms.mouseeventargse)
file://鼠标挪动事变
{
if(ixstart==0&&iystart==0)
{
ixstart=e.x;
iystart=e.y;
return;
}
elseif(e.x!=ixstart||e.y!=iystart)
stopscreensaver();
}
privatevoidscreen_mousedown(objectsender,
system.windows.forms.mouseeventargse)
file://鼠标按下事变
{
stopscreensaver();file://停滞运行屏幕维护次序
}
privatevoidscreen_keydown(objectsender,
system.windows.forms.keyeventargse)
file://键盘按下事变
{
stopscreensaver();file://停滞运行屏幕维护次序
}
}
}
0 评论:
发表评论