Author: Xu Changyou
C # builder is another .NET-based development tool launched by Borland. Let's use it to make a simple screen saver. The screen saver is a standard Windows executor with SCR's extension. The screen saver can not only extend the life of the display, but also protect private information. This article introduces you a dynamic text and graphic screen saver written in C # Builder. Specific implementation Step 1) New C # Windows Application Engineering under C # Builder, named Screensaver. Start C # Builder, the design of the menu file-> new-> c # Application 2) first set the form's backcolor property to the Black, the size property is set to (800, 600), ControlBox, MaximizeBox, MinimizeBox, showintaskbar property settings To false, the FormBorderstyle property is set to None, and WindowsTaus is set to maximized, and StartPosition is set to CENTERSCREEN. Add the Label control, the PictureBox control, and each of the Timer controls. Set the Text property of the Label control to "Welcome to Youwang!"; Set the Name of the PictureBox control to Picture1, Image is set to a predictive picture; set the enabled property of the Timer control to true, the interval property is set to 5. 3) Program encoding // Add the following private member variable private int ispeed = 2; private int ixstance; private int ixstart = 0; private int = 0; private int speted; private int x1, y1; private int width1, height1;
/ / Double-click Form, enter the following code in its Load event: speed = 0; system.drawing.rectangle ssworkarea = system.windows.Forms.Screen.getWorkingArea (this); // screen display area width1 = SSWORKAREA.WIDTH; / / Screen Width Height1 = SSWORKAREA.HEIGHT; / / Screen Height
// from the keydown, mousedown, MouseMove events are entered in the following code: Application.exit (); // Timer1 Tick Event Enter below the code:
// Set the location coordinate 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);} // below is calculating picture frame mobile coordinate SPEED ; if (speted <= 2 * height1) {x1 = system.math.abs (width1-speted); Y1 = system.math .Abs (Height1-speed);} else if (speted> 2 * height1 && speted <= 2 * width1) {x1 = system.math.abs (width1-speted); Y1 = system.math.abs (Height1-) SPEED-speed / height1 * height1));} else if (speed> 2 * width1 && speted <= 3 * height1) {x1 = system.math.abs (Width1- (speted-speted / width1 * width1)); y1 = System.math.abs (Height1- (Speed-Speed / HEI) GHT1 * height1));} else if (speed> 3 * height1 && speted <4 * height1) {x1 = system.math.abs (Width1- (speted-speted / width1 * width1)); y1 = system.math. ABS (Speed-Speed / Height1 * Height1); Else IF (Speed> = 4 * Height1 && Speed <5 * Height1) {x1 = system.math.abs (speed-speted / width1 * width1); y1 = system. Math.abs (Height1- (speted-speted / height1 * height1));} else if (speed> = 5 * height1 && speted <4 * width1) {x1 = system.math.abs (speed-speted / width1 * width1 ); Y1 = system.math.abs (speed-speted / height1 * height1);
} Else if (speted> = 4 * width1 && speed <6 * height1) {x1 = system.math.abs (Width1- (speted-speted / width1 * width1)); Y1 = system.math.abs (Speed-Speed / height1 * height1);} else if (speted> = 6 * height1 && speted <5 * width1) {x1 = system.math.abs (Width1- (speted-speted / width1 * width1)); y1 = system.math .Abs (speted-speted / height1 * height1);} else if (speted> = 5 * width1 && speted <7 * height1) {x1 = system.math.abs (speed-speted / width1 * width1) Y1 = system.math.abs (Height1- (speted-speted / height1 * height1));} else if (speted> = 7 * height1 && speted <6 * width1) {x1 = system.math.abs (Speed- Speed / width1 * width1); y1 = system.math.abs (speted-speted / height1 * height1);} if (speted == 6 * width1) speed = 0; PictureBox1.Location = new system.drawing.point (x1 , Y1); 4) Compile the program, the final compiler, C # Builder will change ScreenSaver.exe to ScreenSaver.SCR in the project where the project is located, and we will copy the screensaver.exe to ScreenSaver.scr, copy it into the Windows system directory, so You can run the screen saver. Set to ScreenSaver in screen protection, look at how the effect! Source code can go to my home page to download http://yousoft.hi.com.cn