共用方式為


NamedRange.Deselected 事件

當選取範圍從 NamedRange 控制項移至 NamedRange 控制項外的區域時,便會發生。

命名空間:  Microsoft.Office.Tools.Excel
組件:  Microsoft.Office.Tools.Excel (在 Microsoft.Office.Tools.Excel.dll 中)

語法

'宣告
Event Deselected As DocEvents_SelectionChangeEventHandler
event DocEvents_SelectionChangeEventHandler Deselected

備註

只有當 NamedRange 控制項擁有焦點時,才會引發這個事件,然後焦點會從 NamedRange 控制項移開。

範例

下列程式碼範例會示範 Deselected 事件的處理常式,顯示選取範圍所移至之儲存格的位址。

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

Private deselectedRange As Microsoft.Office.Tools.Excel.NamedRange

Private Sub DeselectRange()
    deselectedRange = Me.Controls.AddNamedRange( _
        Me.Range("B1", "D4"), "deselectedRange")
    deselectedRange.Select()
    AddHandler Me.deselectedRange.Deselected, _
        AddressOf deselectedRange_Deselected
End Sub


Sub deselectedRange_Deselected(ByVal Target As Excel.Range)
    Dim targetRange As String = Target.Address(, , _
        Excel.XlReferenceStyle.xlA1, , )

    MessageBox.Show("The NamedRange control was deselected." & _
        " Selection transferred to " & Me.Name & ":" & _
        targetRange & ".")
End Sub
Microsoft.Office.Tools.Excel.NamedRange deselectedRange;
private void DeselectRange()
{
    deselectedRange = this.Controls.AddNamedRange(
        this.Range["B1", "D4"], "deselectedRange");
    deselectedRange.Select();
    this.deselectedRange.Deselected += new
        Microsoft.Office.Interop.Excel.
        DocEvents_SelectionChangeEventHandler(
        deselectedRange_Deselected);
}

void deselectedRange_Deselected(Excel.Range Target)
{
    string targetRange = Target.get_Address(
        Excel.XlReferenceStyle.xlA1);

    MessageBox.Show("The NamedRange control was deselected." +
        " Selection transferred to " + this.Name + ":" + 
        targetRange + ".");
}

這是示範應用程式層級增益集的版本。

.NET Framework 安全性

請參閱

參考

NamedRange 介面

Microsoft.Office.Tools.Excel 命名空間