Condividi tramite


Proprietà Button.Width

Ottiene o imposta la larghezza della classe Button espressa in punti.

Spazio dei nomi:  Microsoft.Office.Tools.Word.Controls
Assembly:  Microsoft.Office.Tools.Word.v4.0.Utilities (in Microsoft.Office.Tools.Word.v4.0.Utilities.dll)

Sintassi

'Dichiarazione
Public Property Width As Single
    Get
    Set
public float Width { get; set; }

Valore proprietà

Tipo: System.Single
Larghezza della classe Button espressa in punti.

Note

Le modifiche apportate ai valori della proprietà Left e della proprietà Width determinano la modifica del valore della proprietà Right della classe Button.

La proprietà Button.Width utilizza i punti mentre la proprietà Control.Width utilizza i pixel.

Esempi

Nell'esempio di codice seguente viene illustrata la proprietà Width del controllo Button. Vengono aggiunti due controlli Button denominati sizeButton e locationButton a un documento. Quando si fa clic su sizeButton, le proprietà Height e Width verranno regolate in modo da modificare le dimensioni del pulsante. Quando si fa clic su locationButton, le proprietà Top e Left verranno regolate in modo da modificare la posizione del pulsante. Dopo la modifica di ciascun pulsante, vengono inoltre visualizzati in una finestra di messaggio i nuovi valori delle proprietà Right, Bottom, Height, Width, Top e Left del pulsante selezionato.

Questo esempio è valido per una personalizzazione a livello di documento.

Private Sub ModifySizeAndLocation()

    ' Create a button that resizes when clicked.
    Dim SizeButton As Microsoft.Office.Tools.Word.Controls.Button = _
        Me.Controls.AddButton(25, 25, 80, 30, "SizeButton")
    SizeButton.Name = "SizeButton"
    SizeButton.Text = "Click to change size"
    AddHandler SizeButton.Click, AddressOf ModifyButtons_Click

    ' Create a button that moves when clicked.
    Dim LocationButton As Microsoft.Office.Tools.Word.Controls.Button = _
        Me.Controls.AddButton(50, 100, 80, 30, "LocationButton")
    LocationButton.Name = "LocationButton"
    LocationButton.Text = "Click to change location"
    AddHandler LocationButton.Click, AddressOf ModifyButtons_Click
End Sub

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

' Modify the appearance of the clicked button.
Private Sub ModifyButtons_Click(ByVal sender As Object, ByVal e As EventArgs)
    Dim ClickedButton As Microsoft.Office.Tools.Word.Controls.Button = _
        CType(sender, Microsoft.Office.Tools.Word.Controls.Button)

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

        ' Toggle the Left and Top of LocationButton.
    Else
        If toggleState2 Then
            ClickedButton.Left = 25
            ClickedButton.Top = 150
            toggleState2 = False
        Else
            ClickedButton.Left = 50
            ClickedButton.Top = 100
            toggleState2 = True
        End If
    End If

    ' Display the new Right and Bottom.
    MsgBox("Right: " & ClickedButton.Right.ToString() & _
        vbCr + "Bottom: " & ClickedButton.Bottom.ToString() & _
        vbCr + "Top: " & ClickedButton.Top.ToString() & _
        vbCr + "Left: " & ClickedButton.Left.ToString() & _
        vbCr + "Height: " & ClickedButton.Height.ToString() & _
        vbCr + "Width: " & ClickedButton.Width.ToString())
End Sub
private void ModifySizeAndLocation()
{
    // Create a button that resizes when clicked.
    Microsoft.Office.Tools.Word.Controls.Button sizeButton =
        this.Controls.AddButton(25, 25, 80, 30, "sizeButton");
    sizeButton.Name = "sizeButton";
    sizeButton.Text = "Click to change size";
    sizeButton.Click += new EventHandler(modifyButtons_Click);

    // Create a button that moves when clicked.
    Microsoft.Office.Tools.Word.Controls.Button locationButton =
        this.Controls.AddButton(50, 100, 80, 30, "locationButton");
    locationButton.Name = "locationButton";
    locationButton.Text = "Click to change location";
    locationButton.Click += new EventHandler(modifyButtons_Click);
}

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

// Modify the appearance of the clicked button.
void modifyButtons_Click(object sender, EventArgs e)
{
    Microsoft.Office.Tools.Word.Controls.Button clickedButton =
        (Microsoft.Office.Tools.Word.Controls.Button)sender;

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

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

    // Display the new property values.
    MessageBox.Show("Right: " +
        clickedButton.Right.ToString() +
        "\nBottom: " + clickedButton.Bottom.ToString() +
        "\nTop: " + clickedButton.Top.ToString() +
        "\nLeft: " + clickedButton.Left.ToString() +
        "\nHeight: " + clickedButton.Height.ToString() +
        "\nWidth: " + clickedButton.Width.ToString());
}

Sicurezza di .NET Framework

Vedere anche

Riferimenti

Button Classe

Spazio dei nomi Microsoft.Office.Tools.Word.Controls