Dela via


Document.BeforeRightClick Event (2007 System)

Occurs when the editing area of the document window is right-clicked, before the default right-click action.

Namespace:  Microsoft.Office.Tools.Word
Assembly:  Microsoft.Office.Tools.Word.v9.0 (in Microsoft.Office.Tools.Word.v9.0.dll)

Syntax

'Declaration
Public Event BeforeRightClick As ClickEventHandler
'Usage
Dim instance As Document 
Dim handler As ClickEventHandler 

AddHandler instance.BeforeRightClick, handler
public event ClickEventHandler BeforeRightClick
public:
 event ClickEventHandler^ BeforeRightClick {
    void add (ClickEventHandler^ value);
    void remove (ClickEventHandler^ value);
}
JScript does not support events.

Remarks

To prevent the default right-click action from occurring, set the Cancel argument of the provided CancelEventArgs object to true.

Examples

The following code example displays a message when you right-click the document.

This version is for a document-level customization.

Private Sub DocumentBeforeRightClick()
    AddHandler Me.BeforeRightClick, AddressOf ThisDocument_BeforeRightClick
End Sub 

Private Sub ThisDocument_BeforeRightClick(ByVal sender As Object, ByVal e _
    As Microsoft.Office.Tools.Word.ClickEventArgs)
    MessageBox.Show(Me.Name & " was right-clicked.")
    e.Cancel = True 
End Sub
private void DocumentBeforeRightClick()
{
    this.BeforeRightClick += new Microsoft.Office.Tools.Word.ClickEventHandler(ThisDocument_BeforeRightClick);
}

void ThisDocument_BeforeRightClick(object sender, Microsoft.Office.Tools.Word.ClickEventArgs e)
{
    MessageBox.Show(this.Name + " was right-clicked.");
    e.Cancel = true;
}

This version is for an application-level add-in.

Private Sub DocumentBeforeRightClick()
    Dim vstoDoc As Document = Me.Application.ActiveDocument.GetVstoObject()
    AddHandler vstoDoc.BeforeRightClick, AddressOf ThisDocument_BeforeRightClick
End Sub 

Private Sub ThisDocument_BeforeRightClick(ByVal sender As Object, ByVal e _
    As Microsoft.Office.Tools.Word.ClickEventArgs)
    Dim vstoDoc As Document = Me.Application.ActiveDocument.GetVstoObject()
    System.Windows.Forms.MessageBox.Show(vstoDoc.Name & " was right-clicked.")
    e.Cancel = True 
End Sub
private void DocumentBeforeRightClick()
{
    Document vstoDoc = this.Application.ActiveDocument.GetVstoObject();
    vstoDoc.BeforeRightClick += new Microsoft.Office.Tools.Word.ClickEventHandler(ThisDocument_BeforeRightClick);
}

void ThisDocument_BeforeRightClick(object sender, Microsoft.Office.Tools.Word.ClickEventArgs e)
{
    Document vstoDoc = this.Application.ActiveDocument.GetVstoObject();
    System.Windows.Forms.MessageBox.Show(vstoDoc.Name + " was right-clicked.");
    e.Cancel = true;
}

.NET Framework Security

See Also

Reference

Document Class

Document Members

Microsoft.Office.Tools.Word Namespace

Change History

Date

History

Reason

July 2008

Added a version of the code example for an application-level add-in.

SP1 feature change.