Show / Hide Table of Contents

# Class Pos

Describes the position of a View which can be an absolute value, a percentage, centered, or relative to the ending dimension. Integer values are implicitly convertible to an absolute Pos. These objects are created using the static methods Percent, AnchorEnd, and Center. The Pos objects can be combined with the addition and subtraction operators.

##### Inheritance

System.Object
Pos

##### Inherited Members

System.Object.Equals(System.Object)
System.Object.Equals(System.Object, System.Object)
System.Object.GetHashCode()
System.Object.GetType()
System.Object.MemberwiseClone()
System.Object.ReferenceEquals(System.Object, System.Object)
System.Object.ToString()

###### Namespace: Terminal.Gui

###### Assembly: Terminal.Gui.dll

##### Syntax

    public class Pos

##### Remarks

Use the Pos objects on the X or Y properties of a view to control the position.

These can be used to set the absolute position, when merely assigning an integer value (via the implicit integer to Pos conversion), and they can be combined to produce more useful layouts, like: Pos.Center - 3, which would shift the postion of the View 3 characters to the left after centering for example.

It is possible to reference coordinates of another view by using the methods Left(View), Right(View), Bottom(View), Top(View). The X(View) and Y(View) are aliases to Left(View) and Top(View) respectively.

### Methods

#### AnchorEnd(Int32)

Creates a Pos object that is anchored to the end (right side or bottom) of the dimension, useful to flush the layout from the right or bottom.

##### Declaration

    public static Pos AnchorEnd(int margin = 0)

##### Parameters

Type | Name | Description
--- | --- | ---
System.Int32 | margin | Optional margin to place to the right or below.

##### Returns

Type | Description
--- | ---
Pos | The Pos object anchored to the end (the bottom or the right side).

##### Examples

This sample shows how align a Button to the bottom-right of a View.

    // See Issue #502
    anchorButton.X = Pos.AnchorEnd () - (Pos.Right (anchorButton) - Pos.Left (anchorButton));
    anchorButton.Y = Pos.AnchorEnd (1);

#### At(Int32)

Creates an Absolute Pos from the specified integer value.

##### Declaration

    public static Pos At(int n)

##### Parameters

Type | Name | Description
--- | --- | ---
System.Int32 | n | The value to convert to the Pos.

##### Returns

Type | Description
--- | ---
Pos | The Absolute Pos.

#### Bottom(View)

Returns a Pos object tracks the Bottom (Y+Height) coordinate of the specified View

##### Declaration

    public static Pos Bottom(View view)

##### Parameters

Type | Name | Description
--- | --- | ---
View | view | The View that will be tracked.

##### Returns

Type | Description
--- | ---
Pos | The Pos that depends on the other view.

#### Center()

Returns a Pos object that can be used to center the View

##### Declaration

    public static Pos Center()

##### Returns

Type | Description
--- | ---
Pos | The center Pos.

##### Examples

This creates a TextFieldthat is centered horizontally, is 50% of the way down, is 30% the height, and is 80% the width of the View it added to.

    var textView = new TextView () {
    X = Pos.Center (),
    Y = Pos.Percent (50),
    Width = Dim.Percent (80),
    	Height = Dim.Percent (30),
    };

#### Left(View)

Returns a Pos object tracks the Left (X) position of the specified View.

##### Declaration

    public static Pos Left(View view)

##### Parameters

Type | Name | Description
--- | --- | ---
View | view | The View that will be tracked.

##### Returns

Type | Description
--- | ---
Pos | The Pos that depends on the other view.

#### Percent(Single)

Creates a percentage Pos object

##### Declaration

    public static Pos Percent(float n)

##### Parameters

Type | Name | Description
--- | --- | ---
System.Single | n | A value between 0 and 100 representing the percentage.

##### Returns

Type | Description
--- | ---
Pos | The percent Pos object.

##### Examples

This creates a TextFieldthat is centered horizontally, is 50% of the way down, is 30% the height, and is 80% the width of the View it added to.

    var textView = new TextView () {
    X = Pos.Center (),
    Y = Pos.Percent (50),
    Width = Dim.Percent (80),
    	Height = Dim.Percent (30),
    };

#### Right(View)

Returns a Pos object tracks the Right (X+Width) coordinate of the specified View.

##### Declaration

    public static Pos Right(View view)

##### Parameters

Type | Name | Description
--- | --- | ---
View | view | The View that will be tracked.

##### Returns

Type | Description
--- | ---
Pos | The Pos that depends on the other view.

#### Top(View)

Returns a Pos object tracks the Top (Y) position of the specified View.

##### Declaration

    public static Pos Top(View view)

##### Parameters

Type | Name | Description
--- | --- | ---
View | view | The View that will be tracked.

##### Returns

Type | Description
--- | ---
Pos | The Pos that depends on the other view.

#### X(View)

Returns a Pos object tracks the Left (X) position of the specified View.

##### Declaration

    public static Pos X(View view)

##### Parameters

Type | Name | Description
--- | --- | ---
View | view | The View that will be tracked.

##### Returns

Type | Description
--- | ---
Pos | The Pos that depends on the other view.

#### Y(View)

Returns a Pos object tracks the Top (Y) position of the specified View.

##### Declaration

    public static Pos Y(View view)

##### Parameters

Type | Name | Description
--- | --- | ---
View | view | The View that will be tracked.

##### Returns

Type | Description
--- | ---
Pos | The Pos that depends on the other view.

### Operators

#### Addition(Pos, Pos)

Adds a Pos to a Pos, yielding a new Pos.

##### Declaration

    public static Pos operator +(Pos left, Pos right)

##### Parameters

Type | Name | Description
--- | --- | ---
Pos | left | The first Pos to add.
Pos | right | The second Pos to add.

##### Returns

Type | Description
--- | ---
Pos | The Pos that is the sum of the values of `left` and `right`.

#### Implicit(Int32 to Pos)

Creates an Absolute Pos from the specified integer value.

##### Declaration

    public static implicit operator Pos(int n)

##### Parameters

Type | Name | Description
--- | --- | ---
System.Int32 | n | The value to convert to the Pos .

##### Returns

Type | Description
--- | ---
Pos | The Absolute Pos.

#### Subtraction(Pos, Pos)

Subtracts a Pos from a Pos, yielding a new Pos.

##### Declaration

    public static Pos operator -(Pos left, Pos right)

##### Parameters

Type | Name | Description
--- | --- | ---
Pos | left | The Pos to subtract from (the minuend).
Pos | right | The Pos to subtract (the subtrahend).

##### Returns

Type | Description
--- | ---
Pos | The Pos that is the `left` minus `right`.