String should get split on the right side of the page - c#

I have a path saved in string (datn1, datn2) and want to print the path on a page. So I have to look, if the string is too long for the width of the page and if it is too long, it should begin with a new line.
First of all I split the string and saved it in a string array:
String datn1 = dateiName1, datn2 = dateiName1;
char[] Trennzeichen = { '\\' };
String[] folders1 = datn1.Split(Trennzeichen);
String[] folders2 = datn2.Split(Trennzeichen);
I also have the margins of the page in variables:
float leftMargin, rightMargin, topMargin, bottomMargin, width, height;
Now I want to add a new string to parts of the string array and look, if it's on the page. When it reaches the right site it should make a new line... how can i do that?
my idea:
string path_new;
for (int i = 0; i <= folders1.Length; i++)
{
If()//How can i say that he should look if the string is inside the margins?
{
path_new= folders1[i]+"//";
}
else
{
path_new= "\n" + folders1[i]+ "//";
}
}

now i found a solution:
private void DrawGraphic(Graphics g)
{
g.PageUnit = GraphicsUnit.Millimeter;
String datn1 = dateiName1, datn2 = dateiName2;
char[] Trennzeichen = { '\\' };
String[] folders1, folders2;
if (vergl.X == 1)
folders1 = datn1.Split(Trennzeichen);
else
folders1 = new String[0];
if (vergl.Y == 1)
folders2 = datn2.Split(Trennzeichen);
else
folders2 = new String[0];
if (pageSetupDialog1.PageSettings.Landscape == false)
{
string path_new = "";
string path_new2 = "";
for (int i = 0; i < folders1.Length; i++)
{
string path_temp = path_new + folders1[i] + "//";
System.Drawing.Size size_path_temp = TextRenderer.MeasureText(path_temp, new Font("Verdana", 8f)); // get size of string path_temp (in pixel)
double size_path_temp_width = Convert.ToDouble(size_path_temp.Width);
double variable = Convert.ToDouble(rightMargin.ToString())*96/25.4d; //96 = dpi Anzahl
if (size_path_temp_width < variable)
{
path_new += folders1[i] + "//";
}
else
{
path_new += System.Environment.NewLine + folders1[i] + "//";
}
}
for (int i = 0; i < folders2.Length; i++)
{
string path_temp = path_new2 + folders2[i] + "//";
System.Drawing.Size size_path_temp = TextRenderer.MeasureText(path_temp, new Font("Verdana", 8f)); // get size of string path_temp (in pixel)
double size_path_temp_width = Convert.ToDouble(size_path_temp.Width);
double variable = Convert.ToDouble(rightMargin.ToString()) * 96 / 25.4d; //96 = dpi
if (size_path_temp_width < variable)
{
path_new2 += folders2[i] + "//";
}
else
{
path_new2 += System.Environment.NewLine + folders2[i] + "//";
}
}
g.DrawString(path_new, new Font("Verdana", 8f), new SolidBrush(Color.Black), leftMargin, topMargin+10);
g.DrawString(path_new2, new Font("Verdana", 8f), new SolidBrush(Color.Black), 20, topMargin + 10 + bmp1.Height / 6 + 25);
}
dateiName1 and dateiName2 is a string in which the paths are saved.
vergl.X and vergl.Y checks if there is a path read in

Related

Unable to grab values from text boxes on form

So i am trying to grab user input from my text boxes which are being printed to the screen through a loop and if Statements. When trying to print the values put into the textbox I only get one value. Here is the code for adding the textboxes to the grid:
private void InsertEasyNums()
{
int x = 70;
int y = 40;
for (int i = 0; i < 9; i++)
{
if (i == 3)
{
x = 70;
y = 160;
}
else if(i == 6)
{
x = 65;
y = 280;
}
if (easyNums[i] == '0')
{
DrawingField.SendToBack();
int panelX = x + 300;
int panelY = y + + 100;
Font newFont = new Font("Arial", 25);
Point tbLocation = new Point(panelX, panelY);
userInput[i] = new TextBox();
userInput[i].Name = "Row[i]TB";
userInput[i].Font = newFont;
userInput[i].Width = 50;
userInput[i].Location = tbLocation;
userInput[i].BorderStyle = BorderStyle.None;
userInput[i].BackColor = DefaultBackColor;
Controls.Add(userInput[i]);
DrawingField.SendToBack();
x = x + 145;
DrawingField.SendToBack();
}
else if (easyNums[i] != '0')
{
DrawingField.SendToBack();
Font drawFont = new Font("Arial", 30, FontStyle.Bold);
Brush Numbers = new SolidBrush(Color.Black);
Graphics g = DrawingField.CreateGraphics();
g.DrawString(Convert.ToString(easyNums[i]), drawFont,
Numbers, x, y);
x = x + 146;
}
}
}
Here is where I try to print the Textboxes:
foreach (Control c in DrawingField.Controls)
{
if (c is TextBox)
{
int i = 0;
TextBox txt = (TextBox)c;
string str = txt.Text;
TBValues[i] = str;
i++;
}
}
foreach (var key in TBValues)
{
MessageBox.Show(key);
}
ANSWER: I moved the declaration of userInput to the beginning of the method and looped through 9 time to give 9 textboxes then used the if statements to move them and change properties.
try to move i before the loop
int i = 0;
foreach (Control c in DrawingField.Controls)
{
if (c is TextBox)
{
TextBox txt = (TextBox)c;
string str = txt.Text;
TBValues[i] = str;
i++;
}
}
foreach (var key in TBValues)
{
MessageBox.Show(key);
}

C# I create a new Picturebox and now my Textboxes won't give me any values back

I'm creating a new Picturebox via code, but now my TextBoxes don't give me any values. I think they went out of focus, or their controls aren't working anymore, here's the code so far:
private void button1_Click(object sender, EventArgs e)
{
int ErrorCode = 0;
string NewName = NewPointName.Text;
int X, Y;
Application.DoEvents();
if (NewPointName.Text == "")
ErrorCode = 1;
else
for (int i = 0; i < Names + 1; i++)
{
if (PointName[i] == NewName)
ErrorCode = 2;
}
if (ErrorCode > 0)
MessageBox.Show("Error " + ErrorCode);
else
{
if (Convert.ToInt32(NewPointXBox.Text) > 60)
X = 60;
else if (Convert.ToInt32(NewPointXBox.Text) < -60)
X = -60;
else if (NewPointXBox.Text == "")
X = 0;
else
X = Convert.ToInt32(NewPointXBox.Text);
if (Convert.ToInt32(NewPointYBox.Text) > 60)
Y = 60;
else if (Convert.ToInt32(NewPointYBox.Text) < -60)
Y = -60;
else if (NewPointYBox.Text == "")
Y = 0;
else
Y = Convert.ToInt32(NewPointYBox.Text);
Punkt.GiveName(NewName, Names);
Punkt.GiveCoordinates(X, Y, Names);
PointName[Names] = NewName;
NewPointName.Text = "";
NewPointXBox.Text = "";
NewPointYBox.Text = "";
Application.DoEvents();
UpdatePoint();
CreatePoint(X, Y, NewName, Names);
Names++;
ErrorCode = 0;
NewName = "";
}
}
public void CreatePoint(int X, int Y, string name, int i)
{
int StartPointX = 450, StartPointY = 450, Factor = 7;
if (RadioG6060.Checked)
{
StartPointX = 454;
StartPointY = 449;
Factor = 7;
}
Dot[i] = new PictureBox();
this.Controls.Add(Dot[i]);
Dot[i].Name = "PB_" + name;
Dot[i].Size = new Size(10, 10);
Dot[i].Image = Image.FromFile("../Dot.png");
Dot[i].Anchor = AnchorStyles.Left;
Dot[i].Location = new Point(StartPointX, StartPointY);
Dot[i].Visible = true;
InitializeComponent();
Dot[i].BringToFront();
Dot[i].Location = new Point(Dot[i].Location.X + (X * Factor), Dot[i].Location.Y - (Y * Factor));
Application.DoEvents();
}
I think it's the this.controls.Add(Dot[i]) that throws it off, because now I can't access the text in my NewPointName textbox.
How can I focus the program back on the form or do generally anything that could activate the boxes again?
I just solved the problem, I just had to leave out the InitializeComponent(), then it worked. Turns out that if you do that, the already existing components get blocked and can't be changed in any options of themselves anymore.

WPF - Set Images to Grid

I am trying to set images to a grid I gave created, I am a noob, so please don't get mad at my coding :). I was wondering if there is a way to say set image to grid row 1, grid row 2, etc. I am trying to make a whack a mole game.
private void PopulateGrid()
{
double NumofImages = TUtils.GetIniInt(Moleini, "NumPictures", "pictures", 8);
int ImageSize = TUtils.GetIniInt(Moleini, "ImageSize", "imageSize", 50);
int ImageBorderSize = TUtils.GetIniInt(Moleini, "ImageBorder", "imageBorder", 2);
double NumberOfColumns = TUtils.GetIniInt(Moleini, "NumRowsColumns", "columnNum", 4);
// More Columns than Rows \\
if (NumberOfColumns > NumofImages)
{
MessageBox.Show("There is something wrong with the .ini file.");
Window1.Close();
}
// Math - Get Necessary Variables \\
int ColumnSize = (ImageSize + (4 * ImageBorderSize));
int RowSize = (ImageSize + (4 * ImageBorderSize));
int NumberofRows = (int)Math.Ceiling(NumofImages / NumberOfColumns);
int MainWindowWidth = (TUtils.ToInt(NumberOfColumns.ToString(), 4) * ColumnSize) + 15;
int MainWindowHeight = (NumberofRows * RowSize) + 35;
// Set Window Size \\
Window1.Width = MainWindowWidth;
Window1.Height = MainWindowHeight;
// Create Grid \\
Window1.Content = grid_Main;
grid_Main.Height = MainWindowHeight;
grid_Main.Width = MainWindowWidth;
// Grid Properties \\
for (int i = 0; i < NumberofRows; i++)
{
ColumnDefinition newColumn = new ColumnDefinition();
newColumn.Width = new GridLength(ColumnSize, GridUnitType.Pixel);
grid_Main.ColumnDefinitions.Add(newColumn);
}
for (int i = 0; i < NumberofRows; i++)
{
RowDefinition Row = new RowDefinition();
Row.Height = new GridLength(RowSize, GridUnitType.Pixel);
grid_Main.RowDefinitions.Add(Row);
}
// Fill Grid \\
int RowCount = 0;
int ColumnCount = 0;
for (int i = 0; i < NumofImages; i++)
{
grid_Main.Children.Add(grid_Main);
if (RowCount < NumberofRows)
{
if (ColumnCount < NumberOfColumns)
{
Console.WriteLine("ColumnCount: " + ColumnCount.ToString());
Grid.SetRow(grid_Main, ColumnCount);
Grid.SetColumn(grid_Main, ColumnCount);
ColumnCount++;
}
else
{
RowCount++;
ColumnCount = 0;
Grid.SetRow(grid_Main, ColumnCount);
Grid.SetColumn(grid_Main, ColumnCount);
ColumnCount++;
Console.WriteLine("RowCount: " + RowCount.ToString());
}
}
else
{
break;
}
}
}
...
private Image CreateImage(int ImageNum)
{
// Gets/Sets Necessary Variables \\
double ImageHeight = ImageSize * 0.7;
// Initialize Image \\
System.Windows.Controls.Image newImage = new Image();
// Image Properties \\
newImage.Width = ImageSize;
newImage.Height = ImageHeight;
// Define Name and Content \\
newImage.Name = "Image_" + ImageNum;
String ImageFunction = TUtils.GetIniString(Moleini, "Image" + ImageNum, "PictureFile", Root + "mole2.png");
if (File.Exists(ImageFunction))
{
newImage.Source = new BitmapImage(new Uri(ImageFunction));
}
else
{
MessageBox.Show("Cannot find " + ImageFunction + ".", "Please fix the ini file");
}
return newImage;
}

Need help in finding the cause of Index out of range exception message

Index was out of range. Must be non-negative and less than the size of the collection.
Parameter name: index
I have the class WireObjectAnimation:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Windows.Forms;
using DannyGeneral;
namespace AnimationEditor
{
class WireObjectAnimation
{
private List<WireObjectCoordinates> wocl = new List<WireObjectCoordinates>();
private WireObject wo1 = null;
string name;
int ndx;
public WireObjectAnimation(string name,WireObject wo)
{
this.name = name;
wo1 = wo;
WireObjectCoordinates woc;
woc = new WireObjectCoordinates(wo.woc);
wocl.Add(woc);
ndx = 0;
}
public void Save(string path , string fileName , PictureBox pb)
{
int framesNumberX = 0;
int framesNumberY = 0;
string fn;
string t = Path.GetFileNameWithoutExtension(this.name);
if (File.Exists(path + "\\" + "DATABASE" + "\\" + fileName + "\\" + t + ".txt"))
{
try
{
string f = Path.Combine(path + "\\" + "DATABASE" + "\\" + t + "\\" + fileName);
File.Delete(f);
}
catch (Exception ex)
{
MessageBox.Show("Error: Could not delete file from disk. Original error: " + ex.Message);
}
fn = path + "\\" + "DATABASE" + "\\" + t + "\\" + fileName;
}
else
{
fn = path + "\\" + "DATABASE" + "\\" + fileName + "\\" + this.name + ".txt";
}
OptionsFile setting_file = new OptionsFile(fn);
setting_file.SetKey("File Name", fn);
setting_file.SetKey("Object Name", fileName);
setting_file.SetKey("Animation Name", this.name);
setting_file.SetKey("picturebox.Width", pb.Width.ToString());
setting_file.SetKey("picturebox.Height", pb.Height.ToString());
string[] xFrames = new string[wocl.Count];
string[] yFrames = new string[wocl.Count];
string X="";
string Y="";
for (int i = 0; i < wocl.Count; i++)
{
X = string.Format("Frame_X_{0} ", i + 1);
Y = string.Format("Frame_Y_{0} ", i + 1);
framesNumberX ++;
framesNumberY ++;
for (int j = 0; j < wocl[i].Point_X.Count; j++)
{
xFrames[i] += string.Format("{0},", wocl[i].Point_X[j]);
yFrames[i] += string.Format("{0},", wocl[i].Point_Y[j]);
}
string tt = xFrames[i].Trim(",".ToCharArray());
string yy = yFrames[i].Trim(",".ToCharArray());
setting_file.SetKey(X, tt);
setting_file.SetKey(Y, yy);
}
int resultX = framesNumberX / 2;
int resultY = framesNumberY / 2;
setting_file.SetKey("Number Of Frames X", resultX.ToString());
setting_file.SetKey("Number Of Frames Y", resultY.ToString());
}
public void Load(string path,string fileName)
{
int numberofframesX = 0;
int numberofframesY = 0;
string framesX = "";
string framesY = "";
string X = "";
string Y = "";
string t = path + "\\" + fileName;
OptionsFile setting_file = new OptionsFile(t);
string XX = setting_file.GetKey("Number Of Frames X");
string YY = setting_file.GetKey("Number Of Frames Y");
numberofframesX = Convert.ToInt32(XX);
numberofframesY = Convert.ToInt32(YY);
for (int i = 1; i < numberofframesX ; i++)
{
X = string.Format("Frame_X_{0} ", i);
framesX = setting_file.GetKey(X);
List<string> floatStrings = new List<string>(framesX.Split(new char[] { ',' }));
List<float> test = floatStrings.Select(tempStr => (float)Convert.ToDouble(tempStr)).ToList();
wo1.woc.Point_X = test;
}
for (int i = 1; i < numberofframesY; i++)
{
Y = string.Format("Frame_Y_{0} ", i);
framesY = setting_file.GetKey(Y);
List<string> floatStrings = new List<string>(framesY.Split(new char[] { ',' }));
List<float> test = floatStrings.Select(tempStr => (float)Convert.ToDouble(tempStr)).ToList();
wo1.woc.Point_Y = test;
}
}
public void SetFrame(int frameNumber, WireObjectCoordinates woc)
{
wocl[frameNumber].Set(woc);
}
public WireObjectCoordinates GetFrame(int frameNumber)
{
if (frameNumber > wocl.Count)
{
throw new Exception("not allowed!");
}
if (frameNumber == wocl.Count)
{
WireObjectCoordinates woc;
woc = new WireObjectCoordinates(wocl[wocl.Count - 1]);
wocl.Add(woc);
return woc;
}
else
{
return wocl[frameNumber];
}
}
}
}
Now when im doing loading the Load function i see the points its loading it good.
But then im trying to move the trackBar bar scroll to the right and then im getting the exception. Now thisl ine: wo1.woc.Point_X = test; the woc have 4 indexs and in each index Point_X and Point_Y are filled with numbers in each index.
In this class i have the functions SetFrame and GetFrame and im using GetFrame in Form1 scroll event of the trackBar:
private void trackBar1_Scroll(object sender, EventArgs e)
{
currentFrameIndex = trackBar1.Value;
textBox1.Text = "Frame Number : " + trackBar1.Value;
wireObject1.woc.Set(wireObjectAnimation1.GetFrame(currentFrameIndex));
LoadPictureAt(trackBar1.Value, sender);
button1.Enabled = false;
button2.Enabled = false;
button3.Enabled = false;
button4.Enabled = false;
button8.Enabled = false;
SaveFormPicutreBoxToBitMapIncludingDrawings();
return;
}
Now when im moving the trackBar once to the right it should paint the next set of numbers from the Point_X and Point_Y instead its going to the WireObjectCoordinates class and throw there the exception:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace AnimationEditor
{
class WireObjectCoordinates
{
public List<float> Point_X = new List<float>();
public List<float> Point_Y = new List<float>();
public WireObjectCoordinates()
{
}
public WireObjectCoordinates(WireObjectCoordinates w)
{
Point_X.AddRange(w.Point_X);
Point_Y.AddRange(w.Point_Y);
}
public void Set(WireObjectCoordinates w)
{
for (int i = 0; i < Point_X.Count; i++)
{
Point_X[i] = w.Point_X[i];
Point_Y[i] = w.Point_Y[i];
}
}
}
}
The exception is on the line: Point_X[i] = w.Point_X[i];
Point_X[i] contain now 4 indexs from [0] to [3] each index contain a number like 332.0 333.0 334.0 335.0
And w.Point_X[i] contain now only one index [0] and this index have the number 332.0
i just dont understand why the exception is on this line.
The idea is that when im moving the trackBar to the right it should draw the next coordinates from the wo1.woc.Point_Y and wo1.woc.Point_X but i guess i did something wrong in the Load function ? Im not sure why its throwing the exception and its only when im moving the trackBar to the right once.
How do you expect your for loop to work? The loop variable i goes from 0 to the count of the Point_X list of this instance. But if the other instance w has a Point_X list of a lower count, or if the Point_Y list of this or the Point_Y list of w has, it will fail.
If you realize that Point_X.Count is 4 and w.Point_X.Count is only 1, then when i exceeds 0, the expression w.Point_X[i] will try to read an element of the list that does not exist. That throws the excpetion "Index was out of range".
But maybe you understand that?
throw a try catch around it it technically wont fix the problem but it wont crash anymore and just read over the error

How to draw a rectangle in console application?

I need to draw a rectangle, with a number inside, in a C# console app and using extended ASCII. How do I go about it?
This is for a demo.
public class ConsoleRectangle
{
private int hWidth;
private int hHeight;
private Point hLocation;
private ConsoleColor hBorderColor;
public ConsoleRectangle(int width, int height, Point location, ConsoleColor borderColor)
{
hWidth = width;
hHeight = height;
hLocation = location;
hBorderColor = borderColor;
}
public Point Location
{
get { return hLocation; }
set { hLocation = value; }
}
public int Width
{
get { return hWidth; }
set { hWidth = value; }
}
public int Height
{
get { return hHeight; }
set { hHeight = value; }
}
public ConsoleColor BorderColor
{
get { return hBorderColor; }
set { hBorderColor = value; }
}
public void Draw()
{
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 < Height; 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();
}
}
This is an extension method to String, which will draw a console box around a given string. Multi-line support included.
i.e.
string tmp = "some value"; Console.Write(tmp.DrawInConsoleBox());
public static string DrawInConsoleBox(this string s)
{
string ulCorner = "╔";
string llCorner = "╚";
string urCorner = "╗";
string lrCorner = "╝";
string vertical = "║";
string horizontal = "═";
string[] lines = s.Split(new char[] { '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries);
int longest = 0;
foreach(string line in lines)
{
if (line.Length > longest)
longest = line.Length;
}
int width = longest + 2; // 1 space on each side
string h = string.Empty;
for (int i = 0; i < width; i++)
h += horizontal;
// box top
StringBuilder sb = new StringBuilder();
sb.AppendLine(ulCorner + h + urCorner);
// box contents
foreach (string line in lines)
{
double dblSpaces = (((double)width - (double)line.Length) / (double)2);
int iSpaces = Convert.ToInt32(dblSpaces);
if (dblSpaces > iSpaces) // not an even amount of chars
{
iSpaces += 1; // round up to next whole number
}
string beginSpacing = "";
string endSpacing = "";
for (int i = 0; i < iSpaces; i++)
{
beginSpacing += " ";
if (! (iSpaces > dblSpaces && i == iSpaces - 1)) // if there is an extra space somewhere, it should be in the beginning
{
endSpacing += " ";
}
}
// add the text line to the box
sb.AppendLine(vertical + beginSpacing + line + endSpacing + vertical);
}
// box bottom
sb.AppendLine(llCorner + h + lrCorner);
// the finished box
return sb.ToString();
}
Output like this
Like this?
This worked for me:
Console.OutputEncoding = Encoding.GetEncoding(866);
Console.WriteLine("┌─┐");
Console.WriteLine("│1│");
Console.WriteLine("└─┘");
[EDIT]
Answer to the sub-question in the comment:
Console.OutputEncoding = Encoding.GetEncoding(866);
Console.WriteLine(" ┌─┐");
Console.WriteLine(" │1│");
Console.WriteLine("┌─┼─┘");
Console.WriteLine("│1│");
Console.WriteLine("└─┘");
You can use CsConsoleFormat† to draw with ASCII border symbols in console.
Drawing a number within a rectangle with "double" lines:
ConsoleRenderer.RenderDocument(
new Document()
.AddChildren(
new Border {
Stroke = LineThickness.Wide,
Align = HorizontalAlignment.Left
}
.AddChildren(1337)
)
);
You can change Stroke = LineThickness.Wide line to change the style of lines. LineThickness.Single would produce thin single lines, new LineThickness(LineWidth.Single, LineWidth.Wide) would produce single vertical and double horizontal lines.
Here's what it looks like:
You can also use ConsoleBuffer class to draw lines explicitly (argument names added for clarity):
using static System.ConsoleColor;
var buffer = new ConsoleBuffer(width: 6);
buffer.DrawHorizontalLine(x: 0, y: 0, width: 6, color: White);
buffer.DrawHorizontalLine(x: 0, y: 2, width: 6, color: White);
buffer.DrawVerticalLine(x: 0, y: 0, height: 3, color: White);
buffer.DrawVerticalLine(x: 5, y: 0, height: 3, color: White);
buffer.DrawString(x: 1, y: 1, color: White, text: "1337");
new ConsoleRenderTarget().Render(buffer);
† CsConsoleFormat was developed by me.
Problem with above code is extra spaces, if you draw multiple rectangles, it causes mess.
here is a code which draw rectangles recursively without extra spaces.
public class AsciDrawing
{
public static void TestMain() {
var w = Console.WindowWidth;
var h = Console.WindowHeight;
RecursiveDraw(16, 8, new Point(w/2-8, h/2-4), ConsoleColor.Black);
Console.CursorTop = h;
Console.CursorLeft = 0;
}
public static void RecursiveDraw(int Width, int Height, Point Location, ConsoleColor BorderColor) {
if(Width < 4 || Height < 2) return;
Draw(Width, Height, Location, BorderColor); //Commnet this draw and and Uncomment Draw bellow to see the difference.
Thread.Sleep(500);
//Comment or Uncomment to see how many recursive calls you want to make
//The best is to comment all execpt 1 and then uncomment 1 by 1
RecursiveDraw(Width/2, Height/2, new Point(Location.X-Width/4, Location.Y-Height/4), ConsoleColor.Green); //Left Top
RecursiveDraw(Width / 2, Height / 2, new Point(Location.X + 3* Width / 4, Location.Y + 3* Height / 4), ConsoleColor.Red); //Right Bottom
RecursiveDraw(Width / 2, Height / 2, new Point(Location.X + 3* Width / 4, Location.Y - Height / 4), ConsoleColor.Blue); //Right Top
RecursiveDraw(Width / 2, Height / 2, new Point(Location.X - Width / 4, Location.Y + 3* Height / 4), ConsoleColor.DarkMagenta); // Left Bottom
//Draw(Width, Height, Location, BorderColor);
}
public static void Draw(int Width, int Height, Point Location, ConsoleColor BorderColor)
{
Console.ForegroundColor = BorderColor;
string s = "╔";
string temp = "";
for (int i = 0; i < Width; i++)
s += "═";
s += "╗" + "\n";
Console.CursorTop = Location.Y;
Console.CursorLeft = Location.X;
Console.Write(s);
for (int i = 0; i < Height; i++) {
Console.CursorTop = Location.Y + 1 + i;
Console.CursorLeft = Location.X;
Console.WriteLine("║");
Console.CursorTop = Location.Y + 1 + i;
Console.CursorLeft = Location.X + Width+1;
Console.WriteLine("║");
}
s = temp + "╚";
for (int i = 0; i < Width; i++)
s += "═";
s += "╝" + "\n";
Console.CursorTop = Location.Y+Height;
Console.CursorLeft = Location.X;
Console.Write(s);
Console.ResetColor();
}
}
public record Point(int X, int Y);

Categories