DataGridViewCell.BorderWidths(DataGridViewAdvancedBorderStyle) DataGridViewCell.BorderWidths(DataGridViewAdvancedBorderStyle) DataGridViewCell.BorderWidths(DataGridViewAdvancedBorderStyle) DataGridViewCell.BorderWidths(DataGridViewAdvancedBorderStyle) Method

定義

すべてのセル マージンの幅を表す Rectangle を返します。Returns a Rectangle that represents the widths of all the cell margins.

protected:
 virtual System::Drawing::Rectangle BorderWidths(System::Windows::Forms::DataGridViewAdvancedBorderStyle ^ advancedBorderStyle);
protected virtual System.Drawing.Rectangle BorderWidths (System.Windows.Forms.DataGridViewAdvancedBorderStyle advancedBorderStyle);
abstract member BorderWidths : System.Windows.Forms.DataGridViewAdvancedBorderStyle -> System.Drawing.Rectangle
override this.BorderWidths : System.Windows.Forms.DataGridViewAdvancedBorderStyle -> System.Drawing.Rectangle
Protected Overridable Function BorderWidths (advancedBorderStyle As DataGridViewAdvancedBorderStyle) As Rectangle

パラメーター

戻り値

すべてのセル マージンの幅を表す RectangleA Rectangle that represents the widths of all the cell margins.

次のコード例は、 BorderWidths DataGridViewCellクラスのメソッドを使用して、セル内の使用可能な描画領域を決定する方法を示しています。The following code example demonstrates how to use the BorderWidths method of the DataGridViewCell class to determine the available drawing area in a cell. このコード例は、次の方法で提供される大規模な例の一部です。Windows フォーム DataGridView コントロールのボタン列にあるボタンを無効にします。This code example is part of a larger example provided in How to: Disable Buttons in a Button Column in the Windows Forms DataGridView Control.

protected override void Paint(Graphics graphics,
    Rectangle clipBounds, Rectangle cellBounds, int rowIndex,
    DataGridViewElementStates elementState, object value,
    object formattedValue, string errorText,
    DataGridViewCellStyle cellStyle,
    DataGridViewAdvancedBorderStyle advancedBorderStyle,
    DataGridViewPaintParts paintParts)
{
    // The button cell is disabled, so paint the border,  
    // background, and disabled button for the cell.
    if (!this.enabledValue)
    {
        // Draw the cell background, if specified.
        if ((paintParts & DataGridViewPaintParts.Background) ==
            DataGridViewPaintParts.Background)
        {
            SolidBrush cellBackground =
                new SolidBrush(cellStyle.BackColor);
            graphics.FillRectangle(cellBackground, cellBounds);
            cellBackground.Dispose();
        }

        // Draw the cell borders, if specified.
        if ((paintParts & DataGridViewPaintParts.Border) ==
            DataGridViewPaintParts.Border)
        {
            PaintBorder(graphics, clipBounds, cellBounds, cellStyle,
                advancedBorderStyle);
        }

        // Calculate the area in which to draw the button.
        Rectangle buttonArea = cellBounds;
        Rectangle buttonAdjustment =
            this.BorderWidths(advancedBorderStyle);
        buttonArea.X += buttonAdjustment.X;
        buttonArea.Y += buttonAdjustment.Y;
        buttonArea.Height -= buttonAdjustment.Height;
        buttonArea.Width -= buttonAdjustment.Width;

        // Draw the disabled button.                
        ButtonRenderer.DrawButton(graphics, buttonArea,
            PushButtonState.Disabled);

        // Draw the disabled button text. 
        if (this.FormattedValue is String) 
        {
            TextRenderer.DrawText(graphics,
                (string)this.FormattedValue,
                this.DataGridView.Font,
                buttonArea, SystemColors.GrayText);
        }
    }
    else
    {
        // The button cell is enabled, so let the base class 
        // handle the painting.
        base.Paint(graphics, clipBounds, cellBounds, rowIndex,
            elementState, value, formattedValue, errorText,
            cellStyle, advancedBorderStyle, paintParts);
    }
}
Protected Overrides Sub Paint(ByVal graphics As Graphics, _
    ByVal clipBounds As Rectangle, ByVal cellBounds As Rectangle, _
    ByVal rowIndex As Integer, _
    ByVal elementState As DataGridViewElementStates, _
    ByVal value As Object, ByVal formattedValue As Object, _
    ByVal errorText As String, _
    ByVal cellStyle As DataGridViewCellStyle, _
    ByVal advancedBorderStyle As DataGridViewAdvancedBorderStyle, _
    ByVal paintParts As DataGridViewPaintParts)

    ' The button cell is disabled, so paint the border,  
    ' background, and disabled button for the cell.
    If Not Me.enabledValue Then

        ' Draw the background of the cell, if specified.
        If (paintParts And DataGridViewPaintParts.Background) = _
            DataGridViewPaintParts.Background Then

            Dim cellBackground As New SolidBrush(cellStyle.BackColor)
            graphics.FillRectangle(cellBackground, cellBounds)
            cellBackground.Dispose()
        End If

        ' Draw the cell borders, if specified.
        If (paintParts And DataGridViewPaintParts.Border) = _
            DataGridViewPaintParts.Border Then

            PaintBorder(graphics, clipBounds, cellBounds, cellStyle, _
                advancedBorderStyle)
        End If

        ' Calculate the area in which to draw the button.
        Dim buttonArea As Rectangle = cellBounds
        Dim buttonAdjustment As Rectangle = _
            Me.BorderWidths(advancedBorderStyle)
        buttonArea.X += buttonAdjustment.X
        buttonArea.Y += buttonAdjustment.Y
        buttonArea.Height -= buttonAdjustment.Height
        buttonArea.Width -= buttonAdjustment.Width

        ' Draw the disabled button.                
        ButtonRenderer.DrawButton(graphics, buttonArea, _
            PushButtonState.Disabled)

        ' Draw the disabled button text. 
        If TypeOf Me.FormattedValue Is String Then
            TextRenderer.DrawText(graphics, CStr(Me.FormattedValue), _
                Me.DataGridView.Font, buttonArea, SystemColors.GrayText)
        End If

    Else
        ' The button cell is enabled, so let the base class 
        ' handle the painting.
        MyBase.Paint(graphics, clipBounds, cellBounds, rowIndex, _
            elementState, value, formattedValue, errorText, _
            cellStyle, advancedBorderStyle, paintParts)
    End If
End Sub

注釈

セルの境界線の既定の幅は1ピクセルです。The default width of the cell border is one pixel. 境界線のDataGridViewAdvancedCellBorderStyle幅を変更するには、次の値を使用します。Use the following DataGridViewAdvancedCellBorderStyle values to modify the width of the border:

  • このNone値は、幅が0ピクセルであることを示します。The None value denotes a width of 0 pixels.

  • またOutsetDoubleInsetDoubleの値によって、既定の幅が1ピクセル増加します。The OutsetDouble or InsetDouble values increase the default width by 1 pixel.

さらに、セルのDividerHeight所有している行に対してプロパティが設定されている場合、四角形の高さDividerHeightはの値によって増加します。In addition, if the DividerHeight property is set for the cell's owning row, the rectangle's height is increased by the value of DividerHeight. セルの所有列に対してDividerWidthプロパティが設定されている場合、四角形の幅はの値によって増加します。DividerWidthIf the DividerWidth property is set for the cell's owning column, the rectangle's width will be increased by the value of DividerWidth.

適用対象

こちらもご覧ください