Well i need to make a program which would display a certain string in a triangle form in the middle of the console something like this:

t
   eee
  sssss
   ttttttt

it wont display right here but i think you get the point.

I am somewhat able to do that but i need to slow the display so that it looks like it is a triangle and want to be able to run it for as long as possible as this program is just for show...

using System;
class test {
     //Creating global variables
     protected static int orix;
     protected static int oriy;
 
     //Function to print string in diffrent areas
     protected static void echo(string s, int x, int y) {
      try {
       Console.SetCursorPosition(orix+x, oriy+y);
          Console.Write(s);       
      }
      catch(ArgumentOutOfRangeException error) {
       Console.Clear();
         Console.WriteLine(error.Message);
      }
     }
 
     //MAIN PROGRAM
     static void Main()
      {
       string str = Console.ReadLine();
       int strlength = str.Length;//variable that keep string length
       int width = Console.WindowWidth, height = Console.WindowHeight;
 
       //check to see if string is exist
       if(strlength != 0) {
        Console.Clear();
        orix = Console.CursorTop;
        oriy = Console.CursorLeft;
 
        //check to see if the console width is 80 or set it
        if(width != 80) {
         Console.SetWindowSize(80, height);
        }
 
 
        int y = 0;
        while(true) {
        int hw = Console.WindowWidth/2;
        int halfway = hw;
        int ht = hw - strlength;
        int inc = 2;
        int incy = 0;
        int s = 1;
 
 
 
        for(int i=0;i<strlength;i++) {
         if(i == strlength-1) {
          inc = -2;
         }
 
         string stri = "";
         for(int n=0;n<s;n++) {
          stri += str[i];
         }
         s += inc;
 
         echo(stri,halfway,y);
         y++;
         if(i == 0) {
          incy = -1;
         }
         if(halfway == ht) {
          incy = 1;
         }
         halfway = halfway+incy;
        }
        Console.WriteLine(strlength-1);
 
       }
}
       else {
        System.Console.WriteLine("A string needs to be entered for this program to work");
          System.Console.ReadKey();
       }
 
      }
}

it works for like a sec and there is text but it is so fast you cant read the text and then i get a error after that.

error:
The value must be greater than or equal to zero and less than the console's buffer size in that dimension.
Parameter name: top
Actual value was 3420.

Put
Console.ReadLine() when your app is exiting while loop. By that way you can keep your app running till user enter something.

You're setting a cursor position beyond the bounds of your console window, it wont like that

This article has been dead for over six months. Start a new discussion instead.