'c# Console App Print Text at Last Column at bottom of console (Right Bottom Corner)

i have following sample code. Here i want to print value from void method at right bottom of Visable console window. i dont want to set specific position value like +20 +30 etc bcoz, I will use this app for universal resolutions (different size monitors). means i want to make it accurate for 800x600,1024x768 or others. i dont want fullscreen window. just want to Measure CURRUNT CMD and print running time from void at right bottom side.(last column)

This code works. but it is printing at leftside at bottom. I just want to set it rightside bottom for any resolution (i will disable fullscreen for cmd window)

im using .net 2.0


using System;
using System.Timers;
using threadTimer = System.Threading;

namespace TimerExample
{
    class Program
    {
        
        static Timer timer = new Timer(1000);
        static int i = 0;


        static void Main(string[] args)
        {     
          
            var largestWindowX = Console.WindowWidth;
            var largestWindowY = Console.WindowHeight;
            
            Console.BufferWidth = Console.WindowWidth = largestWindowX;
            Console.BufferHeight = Console.WindowHeight = largestWindowY;
            
  
         timer.Elapsed+=timer_Elapsed;
         timer.Start(); 
         Console.WriteLine("1st");
            
            
         threadTimer.Thread.Sleep (10000);  
         Console.Clear ();
         Console.Clear ();
         Console.WriteLine("2nd");
           threadTimer.Thread.Sleep (3000);  
            
        }

        private static void timer_Elapsed(object sender, ElapsedEventArgs e)
        {
            
             int x = Console.CursorLeft;
        int y = Console.CursorTop;
        
            float TimeToMissionsReady =  i++;
            TimeSpan ts = TimeSpan.FromSeconds(TimeToMissionsReady);
            string elapsedTime = String.Format("{0:00 Minutes} and {1:00 Seconds}",
            ts.Minutes, ts.Seconds);
            Console.SetCursorPosition((Console.CursorLeft + elapsedTime.Length) , Console.WindowHeight -1);
                 Console.Write("\r   Time Passed:  " + elapsedTime);
                 Console.SetCursorPosition(x, y);
        }

        
 
        
        
}
}


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source