本文為機器翻譯文章。如需檢視英文版,請選取 [原文] 核取方塊。您也可以將滑鼠指標移到文字上,即可在快顯視窗顯示英文原文。
譯文
原文

Button.Height 屬性

 

取得或設定 Button 的高度。

命名空間:   Microsoft.Office.Tools.Word.Controls
組件:  Microsoft.Office.Tools.Word.v4.0.Utilities (在 Microsoft.Office.Tools.Word.v4.0.Utilities.dll 中)

[DesignerSerializationVisibilityAttribute(DesignerSerializationVisibility.Hidden)]
public float Height { get; set; }

屬性值

Type: System.Single

Button 的高度 (以點為單位)。

HeightTop 屬性值所做的變更,會造成 ButtonBottom 屬性值變更。

Button.Height 屬性使用點數,而 Control.Height 屬性則使用像素。

下列程式碼範例會示範 Button 控制項的 Height 屬性。此範例會將兩個名為 sizeButtonlocationButtonButton 控制項加入文件中。當按下 sizeButton 時,會調整 HeightWidth 屬性,好讓按鈕得以變更大小。當按下 locationButton 時,會調整 TopLeft 屬性,好讓按鈕得以變更位置。在修改每個按鈕後,此範例便會在訊息方塊中顯示已按下按鈕的新 RightBottomHeightWidthTopLeft 屬性值。

這是示範文件層級自訂的範例。

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());
}
回到頁首
顯示: