Button.ZOrder Property
Gets the z-order position of the Button.
Namespace: Microsoft.Office.Tools.Excel.Controls
Assembly: Microsoft.Office.Tools.Excel.v4.0.Utilities (in Microsoft.Office.Tools.Excel.v4.0.Utilities.dll)
Syntax
'Declaration
Public ReadOnly Property ZOrder As Integer
Get
public int ZOrder { get; }
Property Value
Type: System.Int32
The z-order position of the Button.
Remarks
The z-order is determined by the OLEObjects collection.
In any collection of objects, the object at the back of the z-order is collection(1), and the object at the front of the z-order is collection(collection.Count).
Examples
The following code example uses the ZOrder property to set the z-order of three Button controls on a worksheet. If the button currently at the front of the z-order is clicked, then the button is moved to the back of the collection. Otherwise, the button is moved to the front of the collection. Note that the z-order of the three buttons initially range from 2 to 4. The Runtime Storage Control on the worksheet initially has the z-order position of 1. For more information, see Runtime Storage Control Overview.
This example is for a document-level customization.
Private Sub ToggleZOrder()
Dim Button1 As Microsoft.Office.Tools.Excel.Controls.Button = _
Me.Controls.AddButton(Me.Range("A1", "B2"), "Button1")
Button1.BackColor = Color.Blue
Dim Button2 As Microsoft.Office.Tools.Excel.Controls.Button = _
Me.Controls.AddButton(Me.Range("B2", "C3"), "Button2")
Button2.BackColor = Color.Red
Dim Button3 As Microsoft.Office.Tools.Excel.Controls.Button = _
Me.Controls.AddButton(Me.Range("C3", "D4"), "Button3")
Button3.BackColor = Color.Green
AddHandler Button1.Click, AddressOf ZOrderButton_Click
AddHandler Button2.Click, AddressOf ZOrderButton_Click
AddHandler Button3.Click, AddressOf ZOrderButton_Click
End Sub
Private Sub ZOrderButton_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)
If ClickedButton.ZOrder = 4 Then
ClickedButton.SendToBack()
Else
ClickedButton.BringToFront()
End If
End Sub
private void ToggleZOrder()
{
Microsoft.Office.Tools.Excel.Controls.Button button1 =
this.Controls.AddButton(this.Range["A1", "B2"],
"button1");
button1.BackColor = Color.Blue;
Microsoft.Office.Tools.Excel.Controls.Button button2 =
this.Controls.AddButton(this.Range["B2", "C3"],
"button2");
button2.BackColor = Color.Red;
Microsoft.Office.Tools.Excel.Controls.Button button3 =
this.Controls.AddButton(this.Range["C3", "D4"],
"button3");
button3.BackColor = Color.Green;
button1.Click += new EventHandler(zOrderButton_Click);
button2.Click += new EventHandler(zOrderButton_Click);
button3.Click += new EventHandler(zOrderButton_Click);
}
void zOrderButton_Click(object sender, EventArgs e)
{
Microsoft.Office.Tools.Excel.Controls.Button clickedButton =
(Microsoft.Office.Tools.Excel.Controls.Button)sender;
if (clickedButton.ZOrder == 4)
{
clickedButton.SendToBack();
}
else
{
clickedButton.BringToFront();
}
}
.NET Framework Security
- Full trust for the immediate caller. This member cannot be used by partially trusted code. For more information, see Using Libraries from Partially Trusted Code.