다음을 통해 공유


Button.Width 속성

Button의 너비(포인트)를 가져오거나 설정합니다.

네임스페이스:  Microsoft.Office.Tools.Excel.Controls
어셈블리:  Microsoft.Office.Tools.Excel.v4.0.Utilities(Microsoft.Office.Tools.Excel.v4.0.Utilities.dll)

구문

‘선언
Public Property Width As Double
public double Width { get; set; }

속성 값

형식: System.Double
Button 의 너비(포인트)입니다.

설명

Width 및 left 속성 값을 변경하면 ButtonRight 속성 값이 변경됩니다.

Button.Width 속성은 포인트를 사용하지만 Control.Width 속성은 픽셀을 사용합니다.

음수나 12288보다 큰 수로 값을 설정하면 예외가 throw되지 않지만 컨트롤이 1에서 12288 사이의 값으로 설정됩니다.

예제

다음 코드 예제에서는 워크시트에 대한 두 Button 컨트롤의 크기 조정 및 재배치 동작을 비교합니다.첫 번째 단추의 Click 이벤트 처리기에서 단추의 Height와 Width 속성을 조정하여 단추 크기를 변경하되, 단추의 위치는 워크시트에서 동일하게 유지합니다.두 번째 단추의 Click 이벤트 처리기에서 단추의 TopLeft 속성을 조정하여 워크시트의 단추 위치를 변경해도 같은 크기를 유지하도록 합니다.

이 예제는 문서 수준 사용자 지정을 위한 것입니다.

Private Sub ModifySizeAndLocation()

    Dim SizeButton As Microsoft.Office.Tools.Excel.Controls.Button = _
        Me.Controls.AddButton(25, 30, 100, 25, "SizeButton")
    SizeButton.Name = "SizeButton"
    SizeButton.Text = "Click to resize"
    AddHandler SizeButton.Click, AddressOf PointButtons_Click

    Dim LocationButton As Microsoft.Office.Tools.Excel.Controls.Button = _
        Me.Controls.AddButton(25, 150, 100, 25, "LocationButton")
    LocationButton.Name = "LocationButton"
    LocationButton.Text = "Click to move"
    AddHandler LocationButton.Click, AddressOf PointButtons_Click
End Sub

' Represents the toggle states of the buttons.
Private toggleState1 As Boolean = True
Private toggleState2 As Boolean = True

Private Sub PointButtons_Click(ByVal sender As Object, ByVal e As EventArgs)
    Dim ClickedButton As Microsoft.Office.Tools.Excel.Controls.Button = _
        CType(sender, Microsoft.Office.Tools.Excel.Controls.Button)

    ' Toggle the Height and Width of sizeButton.
    If ClickedButton.Name = "SizeButton" Then
        If toggleState1 Then
            ClickedButton.Height = 40
            ClickedButton.Width = 80
            toggleState1 = False
        Else
            ClickedButton.Height = 25
            ClickedButton.Width = 100
            toggleState1 = True
        End If

    ' Toggle the Left and Top of locationButton.
    Else
        If toggleState2 Then
            ClickedButton.Left = 50
            ClickedButton.Top = 100
            toggleState2 = False
        Else
            ClickedButton.Left = 25
            ClickedButton.Top = 150
            toggleState2 = True
        End If
    End If
End Sub
private void ModifySizeAndLocation()
{
    Microsoft.Office.Tools.Excel.Controls.Button sizeButton =
        this.Controls.AddButton(25, 30, 100, 25,
        "sizeButton");
    sizeButton.Name = "sizeButton";
    sizeButton.Text = "Click to resize";
    sizeButton.Click += new EventHandler(pointButtons_Click);

    Microsoft.Office.Tools.Excel.Controls.Button locationButton =
        this.Controls.AddButton(25, 150, 100, 25,
        "locationButton");
    locationButton.Name = "locationButton";
    locationButton.Text = "Click to move";
    locationButton.Click += new EventHandler(pointButtons_Click);
}

// Represents the toggle states of the buttons.
bool toggleState1 = true;
bool toggleState2 = true;

void pointButtons_Click(object sender, EventArgs e)
{
    Microsoft.Office.Tools.Excel.Controls.Button clickedButton =
        (Microsoft.Office.Tools.Excel.Controls.Button)sender;

    // Toggle the Height and Width of sizeButton.
    if (clickedButton.Name == "sizeButton")
    {
        if (toggleState1)
        {
            clickedButton.Height = 40;
            clickedButton.Width = 80;
            toggleState1 = false;
        }
        else
        {
            clickedButton.Height = 25;
            clickedButton.Width = 100;
            toggleState1 = true;
        }
    }

    // Toggle the Left and Top of locationButton.
    else
    {
        if (toggleState2)
        {
            clickedButton.Left = 50;
            clickedButton.Top = 100;
            toggleState2 = false;
        }
        else
        {
            clickedButton.Left = 25;
            clickedButton.Top = 150;
            toggleState2 = true;
        }
    }
}

.NET Framework 보안

  • 직접 실행 호출자의 경우 완전히 신뢰합니다. 이 멤버는 부분적으로 신뢰할 수 있는 코드에서 사용할 수 없습니다. 자세한 내용은 부분 신뢰 코드에서 라이브러리 사용을 참조하십시오.

참고 항목

참조

Button 클래스

Microsoft.Office.Tools.Excel.Controls 네임스페이스