VB.NET & C++.NET

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

When developing a console application how do I place the cursor at a specific
colomn and row?
 
survivor said:
When developing a console application how do I place the cursor at a specific
colomn and row?

If you're using the beta of the new .NET Framework 2.0, then you can use the
Console.SetCursorPosition() method to do this, or alternatively, assign the
properties Console.CursorLeft and Console.CursorTop. There's no
functionality in the .NET Framework 1.0 for this, but you can invoke the
Win32 API call SetConsoleCursorPosition() instead. This function should do
the trick:

void SetCursorPosition(int row, int col) {
COORD coord;
coord.X = col;
coord.Y = row;
SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), coord);
}

Make sure you "#include <windows.h>"; this should usually be put in
stdafx.h. In other languages like Visual Basic and C# you would need to use
DllImport to import the appropriate native calls. I hope this helps.
 
Back
Top