Ad

Saturday, August 10, 2013

Console Class in C#.Net

Overview:
                In this article i would like to publish an article related to console Class available in c#.Net.


Description:
                    Console is nothing but a black color screen.It is defined as a standard input,output error streams for a console applications.
 For More Article Related To Console Class
It consists of different properties methods and events.

Properties:
 
Name of Property Description
BackgroundColor Gets or sets the background color of the console.
BufferHeight Gets or sets the height of the buffer area.
BufferWidth Gets or sets the width of the buffer area.
CapsLock Gets a value indicating whether the CAPS LOCK keyboard toggle is turned on or turned off.
CursorLeft Gets or sets the column position of the cursor within the buffer area.
CursorSize Gets or sets the height of the cursor within a character cell.
CursorTop Gets or sets the row position of the cursor within the buffer area.
CursorVisible Gets or sets a value indicating whether the cursor is visible.
ForegroundColor Gets or sets the foreground color of the console.
In Gets the standard input stream.
KeyAvailable Gets a value indicating whether a key press is available in the input stream.
NumberLock Gets a value indicating whether the NUM LOCK keyboard toggle is turned on or turned off.
Out Gets the standard output stream.
Title Gets or sets the title to display in the console title bar.

Example Related To Properties:


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Threading;
namespace Consolecls
{
    class Class4
    {
        protected static int origRow;
        protected static int origCol;
        protected static void WriteAt(string s, int x, int y)
        {
            try
            {
                Console.SetCursorPosition(origCol + x, origRow + y);
                Console.Write(s);
            }
            catch (ArgumentOutOfRangeException e)
            {
                Console.Clear();
                Console.WriteLine(e.Message);
            }
        }
        static void Main(string[] args)
        {
            //background and foreground Color
            Console.BackgroundColor = ConsoleColor.Black;
            Console.WriteLine("Example on Console Class");
            Console.ForegroundColor = ConsoleColor.Red;
            //Buffer Height and width
            Console.WriteLine("The current buffer height is {0} rows.",
                      Console.BufferHeight);
            Console.WriteLine("The current buffer width is {0} columns.",
                              Console.BufferWidth);
            Console.WriteLine("*******************************************************");
            Console.WriteLine(" ");
            //Capslock
            if (Console.CapsLock)
            {
                Console.WriteLine("Your Caps Lock is On");
            }
            else
            {
                Console.WriteLine("Your Caps Lock is Off");
            }
            Console.WriteLine("*******************************************************");
            Console.WriteLine(" ");
            //Numlock
            if (Console.NumberLock)
            {
                Console.WriteLine("Your Number Lock is On");
            }
            else
            {
                Console.WriteLine("Your Number Lock is Off");
            }
            Console.WriteLine("*******************************************************");
            Console.WriteLine(" ");
            //Cursor Left cursor Top
            //Console.Clear();
            origRow = Console.CursorTop;
            origCol = Console.CursorLeft;

            // Draw the left side of a 5x5 rectangle, from top to bottom.
            WriteAt("+", 0, 0);
            WriteAt("|", 0, 1);
            WriteAt("|", 0, 2);
            WriteAt("|", 0, 3);
            WriteAt("+", 0, 4);

            // Draw the bottom side, from left to right.
            WriteAt("-", 1, 4); // shortcut: WriteAt("---", 1, 4)
            WriteAt("-", 2, 4); // ...
            WriteAt("-", 3, 4); // ...
            WriteAt("+", 4, 4);

            // Draw the right side, from bottom to top.
            WriteAt("|", 4, 3);
            WriteAt("|", 4, 2);
            WriteAt("|", 4, 1);
            WriteAt("+", 4, 0);

            // Draw the top side, from right to left.
            WriteAt("-", 3, 0); // shortcut: WriteAt("---", 1, 0)
            WriteAt("-", 2, 0); // ...
            WriteAt("-", 1, 0); // ...
            //
            WriteAt("All done!", 0, 6);
            Console.WriteLine();
            Console.WriteLine("*******************************************************");
            Console.WriteLine(" ");
            //Title
            Console.Title = "Console Class Properties";
            Console.WriteLine("*******************************************************");
            Console.WriteLine(" ");
            //In and Out (You Must Use "System.IO" namespace)
            TextReader tIn = Console.In;
            TextWriter tOut = Console.Out;

            tOut.WriteLine("Hai readers!");
            tOut.Write("What is your name: ");
            String name = tIn.ReadLine();

            tOut.WriteLine("Welcome to My Blog, {0}!", name);
           
            Console.ReadLine();
        }
    }
}

Key Related Properties Click Here

  For More Article Related To Console Class

Output:

Console Class

 

 



 For More Article Related To Console Class

No comments: