I am developing a console application. I need to emulate the way how the command line utility behaves when the F7 button is pressed, like shown below:
Is it possible in C# 2008? If not, is there any workaround available?
Any help much appreciated.
I am developing a console application. I need to emulate the way how the command line utility behaves when the F7 button is pressed, like shown below:
Is it possible in C# 2008? If not, is there any workaround available?
Any help much appreciated.
I'm not sure if .NET includes wrappers for them or if you'll have to use them via P/Invoke, but the Win32 API includes functions for this. For example, you could use ReadConsoleOutput
to read the block of the display you're going to cover up. Then you'd use WriteConsoleOutput
to display your list (including the border). Once you're done with the overlay, you'd restore the previous content with another call to WriteConsoleOutput
, specifying the block where you saved the underlying data.
Edit: doing a quick check, the right functionality isn't jumping out at me anyway. Maybe I'm missing something obvious though...
On Windows there is a whole API for writing "Console Mode" applications. It allows you to listen for mouse or keyboard input in an event driven way, and also to set the text foreground and background colours, position the cursor, etc.
To make a box like the one displayed by CMD.EXE, you use certain special characters to make the border (there are various corner pieces and edge pieces - use the Character Map application to see them all).
To use the Console API from C# you probably need to use pinvoke, e.g.
[DllImport("kernel32.dll")]
public static extern bool SetConsoleTextAttribute(
IntPtr hConsoleOutput, int wAttributes);
See the docs for SetConsoleTextAttribute to see how to use it to set the colour.