Redigeeri

Jagamisviis:


Padding Struct

Definition

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

public value class Padding
public value class Padding : IEquatable<System::Windows::Forms::Padding>
[System.ComponentModel.TypeConverter(typeof(System.Windows.Forms.PaddingConverter))]
[System.Serializable]
public struct Padding
[System.ComponentModel.TypeConverter(typeof(System.Windows.Forms.PaddingConverter))]
[System.Serializable]
public struct Padding : IEquatable<System.Windows.Forms.Padding>
[<System.ComponentModel.TypeConverter(typeof(System.Windows.Forms.PaddingConverter))>]
[<System.Serializable>]
type Padding = struct
Public Structure Padding
Public Structure Padding
Implements IEquatable(Of Padding)
Inheritance
Padding
Attributes
Implements

Examples

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;
}
' This code example demonstrates using the Padding property to 
' create a border around a RichTextBox control.
Public Sub New()
     InitializeComponent()

     Me.panel1.BackColor = System.Drawing.Color.Blue
     Me.panel1.Padding = New System.Windows.Forms.Padding(5)
     Me.panel1.Dock = System.Windows.Forms.DockStyle.Fill

     Me.richTextBox1.BorderStyle = System.Windows.Forms.BorderStyle.None
     Me.richTextBox1.Dock = System.Windows.Forms.DockStyle.Fill
 End Sub

Remarks

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.

Constructors

Padding(Int32, Int32, Int32, Int32)

Initializes a new instance of the Padding class using a separate padding size for each edge.

Padding(Int32)

Initializes a new instance of the Padding class using the supplied padding size for all edges.

Fields

Empty

Provides a Padding object with no padding.

Properties

All

Gets or sets the padding value for all the edges.

Bottom

Gets or sets the padding value for the bottom edge.

Horizontal

Gets the combined padding for the right and left edges.

Left

Gets or sets the padding value for the left edge.

Right

Gets or sets the padding value for the right edge.

Size

Gets the padding information in the form of a Size.

Top

Gets or sets the padding value for the top edge.

Vertical

Gets the combined padding for the top and bottom edges.

Methods

Add(Padding, Padding)

Computes the sum of the two specified Padding values.

Equals(Object)

Determines whether the value of the specified object is equivalent to the current Padding.

Equals(Padding)

Indicates whether the current object is equal to another object of the same type.

GetHashCode()

Generates a hash code for the current Padding.

Subtract(Padding, Padding)

Subtracts one specified Padding value from another.

ToString()

Returns a string that represents the current Padding.

Operators

Addition(Padding, Padding)

Performs vector addition on the two specified Padding objects, resulting in a new Padding.

Equality(Padding, Padding)

Tests whether two specified Padding objects are equivalent.

Inequality(Padding, Padding)

Tests whether two specified Padding objects are not equivalent.

Subtraction(Padding, Padding)

Performs vector subtraction on the two specified Padding objects, resulting in a new Padding.

Applies to

See also