draw a rectangle in a C# console application with variable numbers and using extended ASCII
You also like this: Draw a circle in c# console
C# Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
using System; namespace ConsoleApplicationX { class Program { private static int Width; private static int Hieght; private static int LocationX; private static int LocationY; private static ConsoleColor BorderColor; public static void Draw() { string s = "╔"; string space = ""; string temp = ""; for (int i = 0; i < Width; i++) { space += " "; s += "═"; } for (int j = 0; j < LocationX; j++) temp += " "; s += "╗" + "\n"; for (int i = 0; i < Hieght; i++) s += temp + "║" + space + "║" + "\n"; s += temp + "╚"; for (int i = 0; i < Width; i++) s += "═"; s += "╝" + "\n"; Console.ForegroundColor = BorderColor; Console.CursorTop = LocationY; Console.CursorLeft = LocationX; Console.Write(s); Console.ResetColor(); } private static void ConsoleRectangle(int width, int hieght,int locationX, int locationY, ConsoleColor borderColor) { Width = width; Hieght = hieght; LocationX = locationX; LocationY = locationY; BorderColor = borderColor; } static void Main(string[] args) { ConsoleRectangle(20, 10, 7, 8, ConsoleColor.DarkRed); Draw(); Console.ReadLine(); } } } |
Output:
You can find more similar examples of programming for this programming language in the site.