I'm creating a Windows Console application in VB.NET, and I am unable to set the window position relative to the screen. In short, I want a function to centre the window to the screen.
I have tried to use Console.SetWindowPosition(w, h)
method and Console.WindowTop
, Console.WindowLeft
properties. When returning the values for WindowTop
and WindowLeft
, they both return 0, and if I attempt to change these values with Console.WindowLeft = n
(n > 0), the program throws an OutOfBounds exception, stating that the Window's size must fit within the console's buffer.
I run Console.SetWindowSize(80, 35)
and Console.SetBufferSize(80, 35)
before attempting to position the window, yet it still throws the exception if n
is greater than 0. When returning both WindowTop
and WindowLeft
values, both of them are 0, even if the console window has been moved before returning those values.