0% found this document useful (0 votes)
15 views2 pages

Public Class ConsoleRectangle

This document defines a ConsoleRectangle class that represents a rectangle that can be drawn on a console with a width, height, location, and border color. The class contains properties for these attributes and a Draw method that generates a string representation of the rectangle and outputs it to the console at the specified location and border color.

Uploaded by

Shamil Ahmed
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
15 views2 pages

Public Class ConsoleRectangle

This document defines a ConsoleRectangle class that represents a rectangle that can be drawn on a console with a width, height, location, and border color. The class contains properties for these attributes and a Draw method that generates a string representation of the rectangle and outputs it to the console at the specified location and border color.

Uploaded by

Shamil Ahmed
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

public class ConsoleRectangle { private int hWidth; private int hHieght; private Point hLocation; private ConsoleColor hBorderColor;

public ConsoleRectangle(int width, int hieght, Point location, ConsoleColor borderColor) { hWidth = width; hHieght = hieght; hLocation = location; hBorderColor = borderColor; } public Point Location { get { return hLocation; } set { hLocation = value; } } public int Width { get { return hWidth; } set { hWidth = value; } } public int Hieght { get { return hHieght; } set { hHieght = value; } } public ConsoleColor BorderColor { get { return hBorderColor; } set { hBorderColor = value; } } public void Darw() { string s = "";

string space = ""; string temp = ""; for (int i = 0; i < Width; i++) { space += " "; s += ""; } for (int j = 0; j < Location.X ; 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 = hLocation.Y; Console.CursorLeft = hLocation.X; Console.Write(s); Console.ResetColor(); } }

You might also like