vb.net vb如何做屏保关闭屏保和睡眠

vb怎样设置窗体充满屏幕(盖住状态栏)?
[问题点数:40分,结帖人gene_huang]
本版专家分:75
CSDN今日推荐
本版专家分:33913
本版专家分:75
本版专家分:33913
本版专家分:1508
本版专家分:1508
本版专家分:52539
2012年2月 扩充话题大版内专家分月排行榜第一2012年1月 挨踢职涯大版内专家分月排行榜第一2011年12月 挨踢职涯大版内专家分月排行榜第一
2012年2月 挨踢职涯大版内专家分月排行榜第三2011年11月 挨踢职涯大版内专家分月排行榜第三2011年10月 挨踢职涯大版内专家分月排行榜第三
本版专家分:55
本版专家分:20
本版专家分:0
本版专家分:1508
本版专家分:75
匿名用户不能发表回复!|
CSDN今日推荐如何使程序阻止计算机休眠?
[问题点数:100分,结帖人mycatlove]
本版专家分:29
结帖率 100%
CSDN今日推荐
本版专家分:57445
本版专家分:7247
本版专家分:816296
2012年 荣获名人称号
2010年 总版技术专家分年内排行榜第一2009年 总版技术专家分年内排行榜第一
2011年 总版技术专家分年内排行榜第二
2011年3月 总版技术专家分月排行榜第一2011年2月 总版技术专家分月排行榜第一2011年1月 总版技术专家分月排行榜第一2010年12月 总版技术专家分月排行榜第一2010年11月 总版技术专家分月排行榜第一2010年10月 总版技术专家分月排行榜第一2010年9月 总版技术专家分月排行榜第一2010年8月 总版技术专家分月排行榜第一2010年7月 总版技术专家分月排行榜第一2010年6月 总版技术专家分月排行榜第一2010年5月 总版技术专家分月排行榜第一2010年3月 总版技术专家分月排行榜第一2010年4月 总版技术专家分月排行榜第一2010年2月 总版技术专家分月排行榜第一2010年1月 总版技术专家分月排行榜第一2009年12月 总版技术专家分月排行榜第一2009年11月 总版技术专家分月排行榜第一2009年10月 总版技术专家分月排行榜第一2009年8月 总版技术专家分月排行榜第一2009年7月 总版技术专家分月排行榜第一2009年6月 总版技术专家分月排行榜第一
本版专家分:426
本版专家分:391
2013年8月 VB大版内专家分月排行榜第一2013年3月 VB大版内专家分月排行榜第一2012年10月 VB大版内专家分月排行榜第一2012年9月 VB大版内专家分月排行榜第一2012年8月 VB大版内专家分月排行榜第一2012年7月 VB大版内专家分月排行榜第一2012年6月 VB大版内专家分月排行榜第一2012年5月 VB大版内专家分月排行榜第一2012年4月 VB大版内专家分月排行榜第一2012年3月 VB大版内专家分月排行榜第一2012年2月 VB大版内专家分月排行榜第一2012年1月 VB大版内专家分月排行榜第一2011年12月 VB大版内专家分月排行榜第一2011年11月 VB大版内专家分月排行榜第一2011年10月 VB大版内专家分月排行榜第一2011年9月 VB大版内专家分月排行榜第一2011年8月 VB大版内专家分月排行榜第一2011年7月 VB大版内专家分月排行榜第一
2011年1月 VB大版内专家分月排行榜第二2010年10月 VB大版内专家分月排行榜第二
2013年1月 VB大版内专家分月排行榜第三2012年12月 VB大版内专家分月排行榜第三2011年6月 VB大版内专家分月排行榜第三2011年2月 VB大版内专家分月排行榜第三2010年12月 VB大版内专家分月排行榜第三2010年11月 VB大版内专家分月排行榜第三2009年7月 VB大版内专家分月排行榜第三
本版专家分:19645
本版专家分:1768
本版专家分:29
结帖率 100%
本版专家分:29
结帖率 100%
本版专家分:0
本版专家分:29
结帖率 100%
本版专家分:1768
本版专家分:29
结帖率 100%
匿名用户不能发表回复!|
CSDN今日推荐利用Visual Basic.NET编程控制屏幕显示设置
查看: 1254|
摘要: 应用程序在Windows系统运行过程中,要向显示器输出信息.而显示器有多种尺寸和形式,某些支持彩色;某些分辨率较高等等.针对这些问题,本文利用Windows API和Visual Basic.net编程来实现自动获取当前的显示分辨率并切换到 ...
·22·2005年12月下半月刊中国西部科技
利用Visual Basic.NET编程控制屏幕显示设置
陈文青1 王涛2 、
(1绍兴托普信息技术学院绍兴绍兴文理学院计算机系绍兴312000)
摘要:应用程序在Windows系统运行过程中,要向显示器输出信息。而显示器有多种尺寸和形式,某些支持彩色;某些
分辨率较高等等。针对这些问题,本文利用WindowsAPI和VisualBasic.rlet编程来实现自动获取当前的显示分辨
率并切换到使用者所需要的显示设置。从而使自己的程序在合适的条件下运行.
关键词:分辨率屏幕设置API函数VB.NET
基于Windows平台开发的应用程序,尤其是多媒体应
用程序和游戏软件,对显示属性(分辨率和颜色数)都有
定的要求。但许多情况下用户当前的屏幕设置不能满足
用户的需求.这时就需要用户更改机器的屏幕设置,给用
户工作和娱乐带来了不便。理想的做法是在软件运行的
过程中需要更改用户的屏幕设置时程序自动更改设置,当
软件运行结束时,再恢复到原来的屏幕设置。这里就提供
一种解决这种问题的方法。
VB NET是微软公司的一门比较新的程序开发语言,
这里就是利用VB.NET结合Windows API函数的方法来
实现本文功能。所谓API就是“应用程序接口”,是~些用
C语言编写、由Windows操作系统自身调用的函数,它主
要包括在User32.dll、Kernel32.dll、Gdi32.dll三个动态链
接库中,可以在多种编程语言中调用。对于VB.NET应用
程序而言,通过调用获得屏幕的设置比较容易,而要想更
改这些设置就比较麻烦了,这是因为.NET的类库没有将
EnumDisplaySetfings和ChangeDisplaySetfings这两个API
函数进行封装,但要想调用这些函数,VB.NET还是能够
2实例程序设计过程
打开VB.NET开发环境,新建一个项目,在窗体Forml
上添加四个文本框,名称分别是txtX,txtY,txtFrequency,
lxtColor。再在Forml卜添加两个按钮,一个名为
bmGetI)isp,将其Text属性设置为“得到屏幕设置”;另一
个按钮名为bmSetDisp,Text属性为“改变屏幕设置”。然
后在代码窗口里添加程序代码。主要程序清单如下:
Dim nOrgWidth As Integer,nOrgHeight As Integer
Private Const DM BrrSPERPEL=&HS0000
Private Const CCDEVICEN^ME As Short=32
Private Const CCFORMNAME As Short=32
Private Const DM PELSWIDTH As Integer=&
Private Const DM PEkSHEIGHT As Integer=&
CURRENT SETTINGS As Inte—
DM_DISPLAYFREQUENCY AS Integer=&
’调用API函数
Private Declare Function EnumDisplaySettings Lib“
user32”Alias”EnumDisplaySettingsA”(ByVal IpszDev—
iceName As Integer,ByVal iModeNum As Integer,ByRef
lpDevMode As DEVMeDE)As Boolean
Private Declare Function EnumDisplaySetting Lib”
user32”Alias”EnumDisplaySetdngsA“(ByVal iModeNum
As Integer,ByRef lpDevMode As DEVMODE)As Integer
’调用AH函数
Pfivate Declare Function ChangeDisplaySettings Lib”
user32” Alias”ChangeDisplaySettingsA” (ByRef
lpDevMode As DEVMODE,ByVal dwflags As Integer)As
’定义结构
Public Structure DEVMODE
Public dmDeviceName As String
Dim dmSpecVersion As Short
Dim dmDriverVersion As Shoft
Dim dmSize As Short
Dim dmDriverExtra As Short
Dim dmFields As Integer
Dim dmOrientation As Short
Dim dmPaperSize As Short
Dim dropaperLength As Short
Dira dmPaperWidth As Short
Dim dmSeale As Short
Dim dmCopies As Short
Dim dmDefaultSource As Short
Diln dmPrintQuality As Short
Dim dmColor As Short
Dim dmDuplex As Short
Dim dmYResolution As Short
Dilll dmTTOption As Short
Dim dmCollate As Short
Publie dmFomlName As String
Dim dmUnusedPadding As Short
Dim dmBitsPerPel As short
Dim dmPelsWidth As Integer
Dim dmPelsHeight As Integer
Dim dmDisplayFlags As Integer
Dim dmDisplayFrequency As Integer
End Structure
’改变分辩率
Private Sub ChangeDisp(ByRef iWIdm As Single.By—
Ref iHeight As Sir珥e,ByRef color As Short)
Dim blnWorked As BOOleall
DimiAsInteger
Dim DevM As DEVMODE
blnWorked=EnumDisplaySettings(0,i,DevM)
LooD Umil(blnWorked=False)
dmFiel出=DM PELSWIDTH Or DM PELSHEIG_
HT Or DM DISPLAYFREQUENCY
If color=0 Then’Color=0时不更改屏幕颜色
.dmFields;DM PELSWⅡ)TH Or DM PELSHEIG—
dmFields=DM BITSPERPEL Or DM PELSWIDTH
Or DM PELSHEIGHT
.dmPelsWidth=iWidtll
dmPelsHeight=iHeight
’刷新频率设定为自己定义的
.dmDisplayFrequency=Val(txtFrequency Tex0
If color0Then
.dmBitsPerPel=COlor
Call ChangeDisplaySettings(DevM.1)
Prirate Sub bmGetDisp Click(ByVal sender As Object,
ByVal e As System.EventArgs)Handles btnGetDisp.
Dim DevM As DEVMODE
Call EnumDisplaySettings(0,3,DevM)
Dim X As short 1代表设计系统的水平分辨率
Dim Y As Short’代表设计系统的垂直分辨率
X=System Windows.Farms.Screen.PrimaryScreen.
Bounds.Width
信息技术与网络服务NO.12.2005·23·
Y=System.Windows.Forms.Screen.PrimaryScreen.
Bounds.Height
GroupBoxl.Text=”您的显示器分辨率是”
txlX.Tbxt=X
txtY.Text=Y
Dim blIIWOrked As Boolean
DimiAsInteger 、
binWorked=EnumDisplaySettings(0,DM—DIS—
PLAYFREQUENCY.DevM)
Looo Until(blnWorked=False)
txtFrequency.Text=.dmDisplayFrequency
txtColor.Text=.dmBitsPerPel
Private Sub bmSetDisp_Click(ByVal sender As Sys—
tem.Object,ByVal e As System.EventArgs)Handles
btnSetDisp Click
Dim xAs Single
Dim YAs Single
Dim color As Short
X=Val(txtX.Text)
Y=Val(txtY.Text)
COlor=Val(txtColor.Text)
If MsgBox(“您确认要将显示器分辨率改为”&x&。
X”&Y&”吗?”.MsgBoxStyle OKCancel,”系统消息”)=
MsgBoxRestflt.oK Then
’调用过程,改变分辨率
ChangeDisp(x.Y.color)
运行界面如下:
这个程序完成了屏幕显示分辨率及刷新频率等设置
的获取以及修改过程。读者可根据自己的情况适当修改
即可使用。在本程序的编写中,有的地方可能还可以用更
好的方式实现,希望读者能提出不同的方案,以便优化程
参考文献:
1.【美】纳比(Nebben.G.)著,刘舒创作室译.Windows NT/2000本机API参考手册机械工业出版社,2001
2.[&lBfllEvjen,BillyHollis著,杨浩译.VB.NET高级缟程(第3版),2005
3.马志波应用VB6编写屏幕保护程序石家庄师范专科学校学报,)】
Copyright &如何获的从屏保或待机恢复的通知
[问题点数:100分,结帖人magic7004]
本版专家分:1782
CSDN今日推荐
本版专家分:38418
2006年2月 VC/MFC大版内专家分月排行榜第三
本版专家分:1782
本版专家分:1918
本版专家分:1782
本版专家分:681
本版专家分:24100
2010年2月 VC/MFC大版内专家分月排行榜第一
2010年3月 VC/MFC大版内专家分月排行榜第三
本版专家分:1782
本版专家分:5727
本版专家分:3745
结帖率 89.33%
本版专家分:400
本版专家分:3045
本版专家分:867
本版专家分:1083
结帖率 100%
本版专家分:1782
本版专家分:5865
本版专家分:1782
本版专家分:631
本版专家分:1782
本版专家分:1782
本版专家分:2430
本版专家分:1782
本版专家分:0
本版专家分:7
本版专家分:0
匿名用户不能发表回复!|用vb,net怎么做屏幕保护程序啊_百度知道
用vb,net怎么做屏幕保护程序啊
要交的,各位大哥大姐帮帮忙啊。我不会做。要个详细的代码文件
我有更好的答案
用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 S using System.D using System.C using System.ComponentM using System.Windows.F using System.D file://
namespace screen_saver
{ /// /// Form1 的摘要说明。 /// public class screen : System.Windows.Forms.Form {
file://加入私有成员变量
private System.ComponentModel.IC
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.Y file://文本字体颜色
private int iD
private int ixStart= 0;
private int iyStart= 0;
private int x1,y1;
int width1,height1;
private System.Windows.Forms.Timer timerS
file://计时器控件
private System.Windows.Forms.PictureBox picture1; file://图形控件
private System.Windows.Forms.L file://文本显示控件 /// /// 必需的设计器变量。 /// public screen()
// Windows 窗体设计器支持所必需的
InitializeComponent();
word.Font=TextStringF
word.ForeColor=TextS
System.Windows.Forms.Cursor.Hide(); file://隐藏光标
// TODO: 在 InitializeComponent 调用后添加任何构造函数代码
/// 清理所有正在使用的资源。
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.Y
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 =
// 设置计时器控件(timerSaver)属性
this.timerSaver.Enabled =
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.StretchI
this.picture1.TabIndex = 1;
this.picture1.TabStop =
// 设置窗体(screen)属性
this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
this.BackColor = System.Drawing.Color.B
this.ClientSize = new System.Drawing.Size(800, 600);
this.ControlBox =
this.Controls.AddRange(new System.Windows.Forms.Control[] {this.picture1,this.word});
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.N
this.KeyPreview =
this.MaximizeBox =
this.MinimizeBox =
this.Name = &screen&;
this.ShowInTaskbar =
this.StartPosition = System.Windows.Forms.FormStartPosition.M
this.WindowState = System.Windows.Forms.FormWindowState.M
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();
Application.Run(new screen());
} private void Form1_Load(object sender, System.EventArgs e)
System.Drawing.Rectangle ssWorkArea=System.Windows.Forms.Screen.GetWorkingArea(this);
file://屏幕显示区域
width1=ssWorkArea.W file://屏幕宽度
height1=ssWorkArea.H file://屏幕高度
} private void timerSaver_Tick(object sender, System.EventArgs e) file://计时器响应事件
word.Visible=
word.Text=
word.Height=word.Font.H 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= file://设置为可见
iDistance+=iS
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);
word.Location=new System.Drawing.Point(word.Location.X,0);
file://下面是计算图片框移动坐标
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)
picture1.Location=new System.Drawing.Point(x1,y1);
private void StopScreenSaver() file://停止屏幕保护程序运行
System.Windows.Forms.Cursor.Show();
timerSaver.Enabled=
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;
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://停止运行屏幕保护程序
} } } 最后运行该程序,把screen_saver.exe改为screen_saver.scr,拷入Windows系统目录中,这样就可以运行该屏幕
为您推荐:
其他类似问题
您可能关注的内容
屏幕保护程序的相关知识
换一换
回答问题,赢新手礼包
个人、企业类
违法有害信息,请在下方选择后提交
色情、暴力
我们会通过消息、邮箱等方式尽快将举报结果通知您。

我要回帖

更多关于 vb.net 关闭其他窗体 的文章

 

随机推荐