Click here to Skip to main content
12,944,475 members (51,366 online)
Click here to Skip to main content
Add your own
alternative version

Tagged as


1 bookmarked
Posted 5 Dec 2011

How to create a screensaver in Core C#

, 5 Dec 2011 CPOL
Rate this:
Please Sign up or sign in to vote.
Create a screensaver in Core C#
This program was written as an old style screensaver as a part of a training course. The screen saver is a simple program which uses random numbers to display dots on screen in different colors. It also uses a simple logic to keep removing dots by overwriting them with blank spaces, so that the screen does not fill up. There is a for loop to slow down the appearance of dots, i.e., stars.

This code is not the last code, suggestions and improvements are welcome.

Note: The % operator is used to generate actual randomness on screen, using many if-elses. Only later was it discovered that one can also pass a seed number for effective random values.

Note: This program generates only 10000 times. One can also pass a command line argument to run the loop indefinitely and prompt user to press Control+c to exit from the program.

using System;
class set_cursor2
int lastnum;
private int RandomNumber(int min, int max)
   Random random = new Random();
   lastnum = random.Next(min, max); 
   if (lastnum%3 == 0 || lastnum%4==0 )
      lastnum = random.Next(min, max); 
   if (lastnum%5 == 0 || lastnum%6==0 || lastnum%7==0 ) 
      lastnum = random.Next(min, max); 
   return lastnum;
static void Main(string[] args)
   set_cursor2 obj = new set_cursor2();
   int lastrow,lastcol;
   int i,j,t;
   Console.BufferHeight = 500;
   Console.BufferWidth = 200;
   Console.CursorSize = 50;
   Console.CursorVisible = true;
   i = 1;
      j=  obj.RandomNumber(1,99);
      Console.CursorLeft = j;
      lastcol = j;
      j=  obj.RandomNumber(1,49);
      lastrow = j;
      Console.CursorTop = j;
      if (i%3 == 0)
	Console.ForegroundColor = ConsoleColor.White;
      else if (i%4 == 0)
         Console.ForegroundColor = ConsoleColor.Cyan;
         Console.ForegroundColor = ConsoleColor.DarkBlue;
      if ((i+j) % 2 == 0 || (i+j) % 3 == 0  || (i+j) % 5 == 0)	
         Console.WriteLine(" ");
//    Console.WriteLine(". {0} {1}",lastrow,lastcol);
   while (i<=10000);	
   Console.WriteLine("\n\n Finish");

Anyone can use the color codes to change the layout of the screen. The following are some popular color codes:

BlackThe color black.
BlueThe color blue.
CyanThe color cyan (blue-green).
DarkBlueThe color dark blue.
DarkCyanThe color dark cyan (dark blue-green).
DarkGrayThe color dark gray.
DarkGreenThe color dark green.
DarkMagentaThe color dark magenta (dark purplish-red).
DarkRedThe color dark red.
DarkYellowThe color dark yellow (ochre).
GrayThe color gray.
GreenThe color green.
MagentaThe color magenta (purplish-red).
RedThe color red.
WhiteThe color white.
YellowThe color yellow.


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Technical Lead Erls Corporation
India India
I am Dinesh kumar Choudhary by Name, a software Designer and Developer by Work, a Indian Hindu by Religion, Co-Founder of DSFoundation located at by profession, a Loving husband and a Caring Father by Relation.

I have a blog Website at DSFoundation is the Autonomous body to serve for the management of Local shops located at New Delhi, India. Now a days DSFoundation and its subsidiaries are managed by Erls Corporation, an Another initiative by me and my colleagues, in which i am the another CO-Founder of the Organization. Erls Corporation can be located at

You may also be interested in...

Comments and Discussions

GeneralReason for my vote of 3 1 Pin
ARAVINDA R12-Dec-11 22:59
memberARAVINDA R12-Dec-11 22:59 
Generalfor(t=0;t<19999999;t++); too hard for any CPU.. :) Why not u... Pin
Alexander Voronin12-Dec-11 21:28
memberAlexander Voronin12-Dec-11 21:28 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.170518.1 | Last Updated 5 Dec 2011
Article Copyright 2011 by Denno.Secqtinstien
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid