C# Console SetWindowPosition() Method

Beginner
5 min read
Updated: Nov 2026
3 examples
Console

Definition

In C#, Console.SetWindowPosition sets the origin of the visible window inside the larger screen buffer—similar to scrolling which region you see.

Arguments are the left and top of that origin. Values must keep the whole window inside the buffer. Like other window APIs, unsupported hosts may throw.

This is a static member of System.Console. You call it with the type name, such as Console.SetWindowPosition(...). Console is the everyday API for reading from standard input and writing to standard output in C# console apps.

Syntax

Pass the buffer coordinates for the window’s upper-left.

C#
Console.SetWindowPosition(0, 0);
Console.SetWindowPosition(0, 10);
CallWhat it does
Console.SetWindowPosition(left, top)Sets the visible window origin in the buffer.

This is not the same as moving the OS window on the desktop; it selects the visible slice of the buffer.

Library declarations
C#
public static void SetWindowPosition(int left, int top);

Parameters

ParameterDescription
leftBuffer column for the window origin.
topBuffer row for the window origin.

Return Value

Return ValueDescription
voidVisible region updates when supported.

C# Examples

Example 1 — Reset Window Origin to 0,0

Move the visible area back to the top of the buffer.

C#
using System;

class Program {
    static void Main() {
        try {
            Console.SetWindowPosition(0, 0);
            Console.WriteLine("WindowTop=" + Console.WindowTop);
            Console.WriteLine("WindowLeft=" + Console.WindowLeft);
        } catch (Exception ex) {
            Console.WriteLine("Not supported: " + ex.GetType().Name);
        }
    }
}

How It Works

  1. Origin home. (0,0) shows the top-left of the buffer.
  2. Confirm properties. WindowTop/Left reflect the origin.
  3. Try/catch. Keeps demos safe in IDEs.
  4. Sample success. Both values report 0.

Example 2 — Shift the Visible Region Down

If the buffer is taller than the window, move the origin down.

C#
using System;

class Program {
    static void Main() {
        try {
            int maxTop = Math.Max(0, Console.BufferHeight - Console.WindowHeight);
            int top = Math.Min(5, maxTop);
            Console.SetWindowPosition(0, top);
            Console.WriteLine("WindowTop=" + Console.WindowTop);
        } catch (Exception) {
            Console.WriteLine("SetWindowPosition unavailable");
        }
    }
}

How It Works

  1. Max top. Keep the window fully inside the buffer.
  2. Clamp. Use at most 5, or less if the buffer is short.
  3. Effect. Visible text region scrolls down.
  4. Fallback. Unsupported hosts print the unavailable message.

Example 3 — Print WindowLeft and WindowTop

Inspect the current origin without changing it.

C#
using System;

class Program {
    static void Main() {
        Console.WriteLine("WindowLeft=" + Console.WindowLeft);
        Console.WriteLine("WindowTop=" + Console.WindowTop);
    }
}

How It Works

  1. Read-only demo. Safe everywhere.
  2. Typical zeros. Fresh consoles often start at the origin.
  3. Before scrolling. Check values prior to SetWindowPosition.
  4. Pairs with size. Origin + window size must fit the buffer.

Frequently Asked Questions

No. It selects which part of the character buffer is visible.
An exception is thrown if the window would leave the buffer.
When the buffer is larger than the window and you want to scroll programmatically.
SetWindowSize and SetBufferSize.
No. Wrap in try/catch for hosts that lack a classic console window.

Next: SetWindowSize()

Change the visible console window width and height with System.Console.

SetWindowSize() tutorial →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

13 people found this page helpful