Use C # Builder to write Screen Saver

Source: Internet
Author: User

Author: Xu Changyou

C # Builder is another. NET-based development tool launched by Borland. Let's use it to create a simple screen saver. Screen Saver is a standard Windows executable program with the scr extension. Screen Saver can not only prolong the service life of the monitor, but also protect private information. This article introduces a screen saver for dynamic text and graphics written in C # Builder.
Implementation steps
1) create a C # Windows application project under C # Builder. Name it screensaver.
Start C # Builder and choose File> New> C # Application.
2) Interface Design
First, set the BackColor attribute of the form to Black, the Size attribute to (800,600), ControlBox, MaximizeBox, MinimizeBox, ShowInTaskbar, And the FormBorderStyle attribute to None, set WindowStaus to Maximized and StartPosition to CenterScreen.
Add one Label control, one PictureBox control, and one Timer control to the form. Set the Text attribute of the Label control to "Welcome to youyou online !"; Set the Name of the PictureBox control to picture1 and Image to a predicted Image. Set the Enabled attribute of the Timer control to true and the Interval attribute to 5.
3) program Encoding
// Add the following private member variables
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;

// Double-click Form and enter the following code in its Load event:
Speed = 0;
System. Drawing. Rectangle ssWorkArea = System. Windows. Forms. Screen. GetWorkingArea (this );
// Display area
Width1 = ssWorkArea. Width; // screen Width
Height1 = ssWorkArea. Height; // screen Height

// Enter the following code in the From KeyDown, MouseDown, and MouseMove events:
Application. Exit ();
// Enter the following code for the Tick event of timer1:

// Set the coordinates of the text display box below
Label1.Location = new System. Drawing. Point (width1-iDistance, label1.Location. Y );
Label1.visible = true; // set to visible
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 );
}
// The following is the coordinate for calculating the movement of the image box.
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) program Compilation
Finally, compile the program. C # builder will change screensaver.exe to screensaver. scr in the bin/debug/screensaver.exe file in the directory where the project is located, and then paste it into the Windows System directory to run the screen saver.
Set screen saver to screensaver to see how it works!

Source code can go to my home page to download http://yousoft.hi.com.cn

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.