Padding 结构

定义

表示与用户界面 (UI) 元素关联的空白或边距信息。Represents padding or margin information associated with a user interface (UI) element.

public value class Padding
[System.ComponentModel.TypeConverter(typeof(System.Windows.Forms.PaddingConverter))]
[System.Serializable]
public struct Padding
type Padding = struct
Public Structure Padding
继承
Padding
属性

示例

下面的代码示例演示如何使用 "填充" 属性来创建围绕RichTextBox控件的轮廓。The following code example demonstrates how to use the Padding property to create an outline around a RichTextBox control.

有关完整的代码清单, 请参阅如何:使用填充围绕 Windows 窗体控件创建边框。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

注解

Padding结构表示与矩形 UI 元素 (例如控件) 关联的填充或边距。The Padding structure represents the padding or margin associated with a rectangular UI element such as a control. 填充是 UI 元素的正文与其边缘之间的内部空间。The padding is the internal space between the body of the UI element and its edge. 与此相反, 边距是指分离两个相邻 UI 元素的相邻边缘的距离。In contrast, a margin is the distance separating the adjoining edges of two adjacent UI elements. 由于结构上的相似性Padding , 用于表示填充和边距。Because of structural similarities, Padding is used to represent both padding and margins.

有关演示控件上的和Padding Margin属性的关系图, 请参阅Windows 窗体控件中的边距和填充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. 例如, 在Panel控件中Padding , 属性定义Panel及其子控件的边框之间的间距。For example, in a Panel control, the Padding property defines the spacing between the border of the Panel and its child controls. 对于控件, 属性定义Button控件边框和其包含的文本之间的间距。 Padding ButtonFor a Button control, the Padding property defines the spacing between the border of the Button control and its contained text.

除了典型的方法和属性之外, Padding还定义以下类型级成员:In addition to typical methods and properties, Padding also defines the following type-level members:

  • 字段, 表示预定义Padding的, 无填充。 EmptyThe Empty field, which represents a predefined Padding with no padding.

  • 一组用于执行类的常见算术运算的运算符, 例如将两个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.

  • Horizontal、和属性Size , 提供可方便在自定义布局计算中使用的组合值。 VerticalThe Horizontal, Vertical, and Size properties, which provide combined values that are convenient for use in custom layout calculations.

构造函数

Padding(Int32)

初始化 Padding 类的新实例,对所有边缘使用提供的空白大小。Initializes a new instance of the Padding class using the supplied padding size for all edges.

Padding(Int32, Int32, Int32, Int32)

初始化 Padding 类的新实例,对每个边缘使用各自的空白大小。Initializes a new instance of the Padding class using a separate padding size for each edge.

字段

Empty

提供没有空白的 Padding 对象。Provides a Padding object with no padding.

属性

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

获取 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.

方法

Add(Padding, Padding)

计算两个指定的 Padding 值的总和。Computes the sum of the two specified Padding values.

Equals(Object)

确定指定对象的值是否等效于当前的 PaddingDetermines whether the value of the specified object is equivalent to the current Padding.

GetHashCode()

生成当前 Padding 的哈希代码。Generates a hash code for the current Padding.

Subtract(Padding, Padding)

从一个 Padding 值中减去指定的另一个这种类型的值。Subtracts one specified Padding value from another.

ToString()

返回表示当前 Padding 的字符串。Returns a string that represents the current Padding.

操作员

Addition(Padding, Padding)

对两个指定的 Padding 对象执行向量加法,得到新的 PaddingPerforms vector addition on the two specified Padding objects, resulting in a new Padding.

Equality(Padding, Padding)

测试两个指定的 Padding 对象是否等效。Tests whether two specified Padding objects are equivalent.

Inequality(Padding, Padding)

测试两个指定的 Padding 对象是否不等效。Tests whether two specified Padding objects are not equivalent.

Subtraction(Padding, Padding)

对两个指定的 Padding 对象执行向量减法,得到新的 PaddingPerforms vector subtraction on the two specified Padding objects, resulting in a new Padding.

适用于

另请参阅