Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- class Programm
- {
- static void Main(string[] args)
- {
- Window window = new Window(20, 15);
- window.SetTitle("title");
- window.SetTextColor(ConsoleColor.Green);
- window.SetBorderColor(ConsoleColor.Blue);
- window.SetPosition(5, 7);
- window.DrawWindow();
- window.PrintTitle();
- window.PrintInnerText();
- }
- }
- /*
- * Создание окна WxH
- * Задание заголовка окна (не больше 15 символов)
- * Задание цвета текста окна
- * Задание цвета обводки окна
- * Задание позиции окна (в пределах консоли)
- * Отрисовка
- */
- class Window
- {
- private string _title;
- private string _innerText;
- private int _width;
- private int _height;
- private ConsoleColor _border;
- private ConsoleColor _textColor;
- private int _positionX;
- private int _positionY;
- public Window(int width, int height)
- {
- if (width > Console.WindowWidth)
- {
- throw new Exception("Ширина окна превышает максимальную");
- }
- else
- {
- _width = width;
- }
- if (height > Console.WindowHeight)
- {
- throw new Exception("Высота окна превышает максимальную");
- }
- else
- {
- _height = height;
- }
- }
- public void PrintTitle()
- {
- for (int i = 0; i < _title.Length; i++)
- {
- Console.SetCursorPosition(_positionX + (_width - _title.Length) / 2 + i, 3 + _positionY);
- Console.ForegroundColor = _textColor;
- Console.Write(_title[i]);
- ResetCoursorPosition();
- }
- }
- public void PrintInnerText()
- {
- Console.WriteLine("Введите текст");
- _innerText = Console.ReadLine();
- if (_innerText.Length < _width - 2)
- {
- for (int i = 0; i < _innerText.Length; i++)
- {
- Console.SetCursorPosition(_positionX + (_width - _innerText.Length)/2 + i, _height/2 + _positionY + 4);
- Console.ForegroundColor = _textColor;
- Console.Write(_innerText[i]);
- ResetCoursorPosition();
- }
- }
- }
- public void SetTitle(string title)
- {
- if (title.Length <= 15)
- {
- _title = title;
- }
- }
- public void ResetCoursorPosition()
- {
- Console.SetCursorPosition(0, 4 + _height + _positionY);
- }
- public void SetTextColor(ConsoleColor color)
- {
- _textColor = color;
- }
- public void SetBorderColor(ConsoleColor color)
- {
- _border = color;
- }
- public void SetPosition(int positionX, int positionY)
- {
- if (positionX + _width < Console.WindowWidth)
- {
- _positionX = positionX;
- }
- if (positionY + _height < Console.WindowHeight)
- {
- _positionY = positionY;
- }
- }
- public void DrawWindow()
- {
- for (int i = 0; i < _width; i++)
- {
- for (int j = 0; j < _height +2; j++)
- {
- if (j == 0 || i == 0 || j == _height + 1 || i == _width - 1 || j == 2)
- {
- Console.SetCursorPosition(i+ _positionX, j + _positionY + 2);
- Console.ForegroundColor = _textColor;
- Console.Write('#');
- ResetCoursorPosition();
- }
- }
- }
- }
- }
- /*
- H - 10
- W - 5
- ##########
- #Title #
- ##########
- # #
- #Main #
- # #
- # #
- ##########
- */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement