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 属性值会使 Button 的 Right 属性值发生更改。
Button.Width 属性使用磅值,而 Control.Width 属性使用像素值。
将该值设置为负数或大于 12288 的数不会引发异常,但会导致将控件设置为 1 到 12288 之间的数。
示例
下面的代码示例对两个 Button 控件相对于工作表的大小调整和重定位行为进行比较。 第一个按钮的 Click 事件处理程序调整该按钮的 Height 和 Width 属性,从而更改按钮的大小,但仍保持其在工作表上原来的位置。 第二个按钮的 Click 事件处理程序调整该按钮的 Top 和 Left 属性,从而更改按钮在工作表上的位置,但仍保持其原来的大小。
此示例针对的是文档级自定义项。
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 安全性
- 对直接调用方的完全信任。此成员不能由部分信任的代码使用。有关更多信息,请参见通过部分受信任的代码使用库。