用C#Builder編寫螢幕保護程式 (轉)
作者:徐長友
Builder是Borland公司推出的又一款基於的開發工具。我們下面就用它做個簡單的螢幕保護。螢幕保護程式是以scr為副檔名的標準可程式。螢幕保護程式不僅可以延長顯示器的使用壽命,還可以保護私人資訊。本文向大家介紹一個用C# Builder編寫的一個動態文字及圖形的螢幕保護程式。
具體實現步驟
1)在C# Builder下新建一個C#的Windows應用程式工程,這裡命名為screensaver。
啟動C# Builder,透過選單File->New->C# Application
2)介面的設計
先將窗體的BackColor屬性設定為Black、Size屬性設定為(800, 600)、 ControlBox、MaximizeBox、MinimizeBox、ShowInTaskbar屬性設定均為false、FormBorderStyle屬性設定為None, WindowStaus設為Maximized,StartPosition設定為CenterScreen。
再往窗體上新增Label、PictureBox控制元件、Timer控制元件各一個。將Label控制元件的Text屬性設定為“悠遊線上歡迎您!”;將PictureBox控制元件的Name設定為picture1、Image設定為一個預知圖片;將Timer控制元件的Enabled 屬性設為true、Interval屬性設為5。
3)程式的編碼
//加入以下私有成員變數
private int iSpeed = 2;
private int iDistance;
private int ixStart= 0;
private int iyStart= 0;
private int speed;
private int x1,y1;
private int width1,height1;
//雙擊Form,在其Load事件輸入下面的程式碼:
speed=0;
System.Drawing.Rectangle ssWorkArea=System.Windows.Forms.Screen.GetWorkingArea(this);
//螢幕顯示區域
width1=ssWorkArea.Width; //螢幕寬度
height1=ssWorkArea.Height; //螢幕高度
//From的KeyDown,MouseDown,MouseMove事件中都輸入以下程式碼:
Application.Exit();
//timer1的Tick事件輸入下面程式碼:
//下面設定文字顯示框的位置座標
label1.Location =new System.Drawing.Point(width1-iDistance,label1.Location.Y);
label1.Visible=true; //設定為可見
iDistance+=iSpeed;
if(label1.Location.X<=-(label1.Width))
{
iDistance=0;
if(label1.Location.Y==0)
label1.Location=new System.Drawing.Point(label1.Location.X,height1/2);
else if(label1.Location.Y==height1/2)
label1.Location=new System.Drawing.Point(label1.Location.X,height1-label1.Height);
else
label1.Location=new System.Drawing.Point(label1.Location.X,0);
}
//下面是計算圖片框移動座標
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;
pictureBox1.Location=new System.Drawing.Point(x1,y1);
4)程式的編譯
最後編譯程式,C# Builder會在工程所在目錄的BINDeScreenSaver.exe,我們把ScreenSaver.exe改為ScreenSaver.scr,拷入Windows目錄中,這樣就可以執行該螢幕保護程式。
在螢幕保護設定為ScreenSaver,看看效果怎麼樣!
原始碼可以到我的主頁
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/10752043/viewspace-998908/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- Aerial for Mac鳥瞰螢幕保護程式Mac
- Mac簡單時鐘螢幕保護程式Mac
- 保護您的Flutter應用程式:實現隱私螢幕Flutter
- 螢幕保護控制工具:ScreenSaverNow for MacMac
- w10螢幕保護怎麼取消_win10關閉螢幕保護的方法Win10
- Aerial for Mac(mac最美的鳥瞰螢幕保護程式)Mac
- Aerial for Mac(mac高畫質鳥瞰螢幕保護程式)Mac
- Word Clock for Mac(mac螢幕保護軟體) v1.0.7啟用版Mac
- linux 觸控式螢幕驅動編寫Linux
- win10螢幕保護時間怎麼設定Win10
- Python編寫守護程式程式Python
- PHP 編寫守護程式PHP
- ubuntu螢幕旋轉Ubuntu
- Android 禁止螢幕旋轉Android
- orientationchange 螢幕旋轉事件事件
- ios一句程式碼搞定螢幕旋轉iOS
- div 螢幕居中的寫法
- 貝爾金Belkin為iPhone 13系列打造UltraGlass與防眩光螢幕保護膜iPhone
- mui 控制旋轉螢幕方向UI
- iOS螢幕旋轉解決方案iOS
- ScreenFlow for Mac(螢幕錄製和編輯)Mac
- windows 10如何把螢幕翻轉過來_win10顯示螢幕翻轉怎麼操作WindowsWin10
- 用PHP編寫Android應用程式PHPAndroid
- Win10系統設定接投影儀演示時自動禁用螢幕保護的方法Win10
- win10系統如何設定屏保_win10設定螢幕保護的步驟Win10
- WebRTC本地分享螢幕,錄製螢幕Web
- 自己動手從零寫桌面作業系統GrapeOS系列教程——17.用匯編語言清空螢幕作業系統
- Swift橫豎屏切換、自動旋轉螢幕、手動旋轉螢幕、鎖定當前螢幕禁止轉屏、橫豎屏頁面跳轉過度、橫豎屏UI適配SwiftUI
- 雲應用程式如何加強隱私保護
- 螢幕錄影編輯工具:iShowU Studio 2 for macMac
- Movavi Screen Recorder 螢幕錄影編輯軟體
- 自己動手從零寫桌面作業系統GrapeOS系列教程——15.用匯編向螢幕輸出字元作業系統字元
- Systemd設定程式保護
- Filmage Screen for Mac(最好的螢幕錄製投屏影片編輯影片轉換軟體)Mac
- 電腦螢幕旋轉90度怎麼復原win10 win10螢幕翻轉了怎麼辦Win10
- CVS for mac(眼睛保護程式) v2.20啟用版Mac
- 編寫可維護的JSJS
- Mac螢幕錄製編輯工具——iShowU Studio 2 for MacMac
- Movavi Screen Recorder for mac螢幕錄影編輯軟體Mac