I want the user to be able to select the text (just like in Commandprompt) where you right click on the console application's surface and a menu will show, the user can then choose same functions as in commandprompt:
Mark
Copy (Shortcut: Enter)
Paste
Select All
Scroll
Find
I have tried to Google after things like "C# Console Application select text" and other kind of things but can't seem to find a proper solution for this, since the user should be able to mark the text he/she wan't to copy or replace (with paste).
Do you have a solution for my question?
There are no managed methods to do this, but quick edit mode can be enabled through P/Invoke. Quick edit mode allows console text to be selected with the mouse and copied, and for text to be pasted with the right-moue button. (See this article for a description of quick edit mode.)
// using System.Runtime.InteropServices;
[DllImport("kernel32.dll")]
static extern bool SetConsoleMode(IntPtr hConsoleHandle, int mode);
[DllImport("kernel32.dll")]
static extern bool GetConsoleMode(IntPtr hConsoleHandle, out int mode);
[DllImport("kernel32.dll")]
static extern IntPtr GetStdHandle(int handle);
const int STD_INPUT_HANDLE = -10;
const int ENABLE_QUICK_EDIT_MODE = 0x40 | 0x80;
public static void EnableQuickEditMode()
{
int mode;
IntPtr handle = GetStdHandle(STD_INPUT_HANDLE);
GetConsoleMode(handle, out mode);
mode |= ENABLE_QUICK_EDIT_MODE;
SetConsoleMode(handle, mode);
}
maybe I didn't get you but when you execute your console application it will be hosted into a command-prompt window which allows you to copy end past text where ever you like.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With