This topic has not yet been rated Rate this topic

Padding Structure

Represents padding or margin information associated with a user interface (UI) element.

Namespace:  System.Windows.Forms
Assembly:  System.Windows.Forms (in System.Windows.Forms.dll)
[SerializableAttribute]
[TypeConverterAttribute(typeof(PaddingConverter))]
public struct Padding

The Padding type exposes the following members.

  Name Description
Public method Padding(Int32) Initializes a new instance of the Padding class using the supplied padding size for all edges.
Public method Padding(Int32, Int32, Int32, Int32) Initializes a new instance of the Padding class using a separate padding size for each edge.
Top
  Name Description
Public property All Gets or sets the padding value for all the edges.
Public property Bottom Gets or sets the padding value for the bottom edge.
Public property Horizontal Gets the combined padding for the right and left edges.
Public property Left Gets or sets the padding value for the left edge.
Public property Right Gets or sets the padding value for the right edge.
Public property Size Gets the padding information in the form of a System.Drawing.Size.
Public property Top Gets or sets the padding value for the top edge.
Public property Vertical Gets the combined padding for the top and bottom edges.
Top
  Name Description
Public method Static member Add Computes the sum of the two specified Padding values.
Public method Equals Determines whether the value of the specified object is equivalent to the current Padding. (Overrides ValueType.Equals(Object).)
Protected method Finalize Allows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection. (Inherited from Object.)
Public method GetHashCode Generates a hash code for the current Padding. (Overrides ValueType.GetHashCode.)
Public method GetType Gets the Type of the current instance. (Inherited from Object.)
Protected method MemberwiseClone Creates a shallow copy of the current Object. (Inherited from Object.)
Public method Static member Subtract Subtracts one specified Padding value from another.
Public method ToString Returns a string that represents the current Padding. (Overrides ValueType.ToString.)
Top
  Name Description
Public operator Static member Addition Performs vector addition on the two specified Padding objects, resulting in a new Padding.
Public operator Static member Equality Tests whether two specified Padding objects are equivalent.
Public operator Static member Inequality Tests whether two specified Padding objects are not equivalent.
Public operator Static member Subtraction Performs vector subtraction on the two specified Padding objects, resulting in a new Padding.
Top
  Name Description
Public field Static member Empty Provides a Padding object with no padding.
Top

The Padding structure represents the padding or margin associated with a rectangular UI element such as a control. The padding is the internal space between the body of the UI element and its edge. In contrast, a margin is the distance separating the adjoining edges of two adjacent UI elements. Because of structural similarities, Padding is used to represent both padding and margins.

For a diagram that illustrates the Padding and Margin properties on a control, see Margin and Padding in Windows Forms Controls.

Padding has a different effect on controls that are containers than on controls that are not. For example, in a Panel control, the Padding property defines the spacing between the border of the Panel and its child controls. For a Button control, the Padding property defines the spacing between the border of the Button control and its contained text.

In addition to typical methods and properties, Padding also defines the following type-level members:

  • The Empty field, which represents a predefined Padding with no padding.

  • A set of operators for performing common arithmetic operations for the class, such as adding two Padding objects together. For languages that do not support operator overloading, you can invoke these members by using alternative method syntax.

  • The Horizontal, Vertical, and Size properties, which provide combined values that are convenient for use in custom layout calculations.

The following code example demonstrates how to use the Padding property to create an outline around a RichTextBox control.

For a full code listing, see How to: Create a Border Around a Windows Forms Control Using Padding.


// This code example demonstrates using the Padding property to 
// create a border around a RichTextBox control.
public Form1()
{
    InitializeComponent();

    this.panel1.BackColor = System.Drawing.Color.Blue;
    this.panel1.Padding = new System.Windows.Forms.Padding(5);
    this.panel1.Dock = System.Windows.Forms.DockStyle.Fill;

    this.richTextBox1.BorderStyle = System.Windows.Forms.BorderStyle.None;
    this.richTextBox1.Dock = System.Windows.Forms.DockStyle.Fill;
}


.NET Framework

Supported in: 4, 3.5, 3.0, 2.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows XP SP2 x64 Edition, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.
Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.
Did you find this helpful?
(2000 characters remaining)
Community Content Add
Annotations FAQ