'Hide scrollbars in Console without flickering
I write in a console window multiple times a second.
I figured out how to remove the scrollbars:
Console.BufferWidth = Console.WindowWidth = 35;
Console.BufferHeight = Console.WindowHeight;
But when I want to write into the last column of a line, it adds a new line. It's logical, but how to avoid this?
I tried to resize the console:
Console.BufferWidth++;
Console.BufferHeight++;
// Write to the last column of a line
Console.BufferWidth--;
Console.BufferHeight--;
But this flickers because these lines will get executed multiple times a second.
Any ideas?
Solution 1:[1]
Try with Console.SetBufferSize(width, height); I think it will help.
Solution 2:[2]
The problem is not that the cursor goes to the next line directly. What it really does is, it goes one character to the right and because the buffer ends it goes to the next line.
So I tried to do something like Console.WriteLine("C\r"); To set the cursor back but it still flickered
Than I thought about using some sneaky trick and using an Arabic Right to Left Marker but didn't worked.
So the best way i could figured out was to move the character to the bottom right with the Console.MoveBufferArea method because this doesn't set the cursor to the next right position and avoids the new line.
Solution 3:[3]
i have a working code if u want completely hide vertical scrollbar of console app.
here we go ..
this works with any resolution.
Tested by me.
class Program
{
private const int MF_BYCOMMAND = 0x00000000;
public const int SC_CLOSE = 0xF060;
public const int SC_MINIMIZE = 0xF020;
public const int SC_MAXIMIZE = 0xF030;
public const int SC_SIZE = 0xF000;
[DllImport("user32.dll")]
public static extern int DeleteMenu(IntPtr hMenu, int nPosition,intwFlags);
[DllImport("user32.dll")]
private static extern IntPtr GetSystemMenu(IntPtr hWnd, bool bRevert);
[DllImport("kernel32.dll", ExactSpelling = true)]
private static extern IntPtr GetConsoleWindow();
static void Main(string[] args)
{
var largestWindowX = Console.WindowWidth;
var largestWindowY = Console.WindowHeight;
Console.BufferWidth = Console.WindowWidth = largestWindowX;
Console.BufferHeight = Console.WindowHeight = largestWindowY;
IntPtr handle = GetConsoleWindow();
IntPtr sysMenu = GetSystemMenu(handle, false);
if (handle != IntPtr.Zero)
{
DeleteMenu(sysMenu, SC_CLOSE, MF_BYCOMMAND);
DeleteMenu(sysMenu, SC_MINIMIZE, MF_BYCOMMAND);
DeleteMenu(sysMenu, SC_MAXIMIZE, MF_BYCOMMAND);
DeleteMenu(sysMenu, SC_SIZE, MF_BYCOMMAND);
}
}
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | |
| Solution 2 | Sam |
| Solution 3 | haseakash |
