Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6
Default Cannot seem to Cancel EXCEL App Right Click Event using C#

I am trying to use Excel from C# and need to disable the menu that appears when clicking the right mouse button on a cell.

I am trying to do this using the Excel.AppEvents_SheetBeforeRightClickEventHandler from my C# WinForm application.

I have a MessageBox that pops up that proves my event handler actually fires via my delegate but after setting the "Cancel" variable to "true" it has no effect for me. The Excel RMB menu appears when it should not. The Cancel parameter is declared as "ref bool".

I am wondering if there is a problem with the marshalling of this variable in the Office PIA which I am using. I would be happy to send code that demos my problem. Can someone please let me know if they can make it work ?

By the way I have already written some VB6 code that works fine and VBA code in an Excel Workbook that also works just fine as well. Both disable the menu as I require when I set "Cancel" to "True". The problem is that I need to do this from a C# application.

Can anyone shed some light on this at all ?

I am using...

Microsoft Excel 2002 (10.4302.4219) SP-2
Visual Studio 2003 v7.1.3088
Microsoft .NET Framework 1.1 v1.1.4322

I obtained the Office XP Primary Interop Assemblies from the following link

http://www.microsoft.com/downloads/d...displaylang=en


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 400
Default Cannot seem to Cancel EXCEL App Right Click Event using C#

I don't believe you can disable the right click on the activesheet. If you set the AllowPropertyToolbox to false, it disables the Property Toolbox on the right click menu. There is no other property that can be set. The list of properties is:

ActiveCell ActivePane ActiveSheet
AllowPropertyToolbox AutoFit BuildNumber
CSVData CSVURL CanUndo
Cells Columns Constants
DataType Dirty DisplayColHeaders
DisplayGridlines DisplayHorizontalScrollBar DisplayPropertyToolbox
DisplayRowHeaders DisplayTitleBar DisplayToolbar
DisplayVerticalScrollBar EnableAutoCalculate EnableEvents
EnableUndo HTMLData HTMLURL
MajorVersion MaxHeight MaxWidth
MinorVersion MoveAfterReturn MoveAfterReturnDirection
Range RevisionNumber RightToLeft
Rows ScreenUpdating Selection
TitleBar Version ViewableRange

I can't see that there is a right click event.The list of events is:

BeforeCommand Calculate CancelEdit
Change Click Command
DblClick EndEdit KeyDown
KeyPress KeyUp MouseDown
MouseOut MouseOver MouseUp
SelectionChange SelectionChanging StartEdit
ViewChange

Like you, I think the OWC PIA is screwed up. Can you help with my post "OWC Web Component Spreadsheet: C#" in this news group?
"Nick Biggs" wrote:

I am trying to use Excel from C# and need to disable the menu that appears when clicking the right mouse button on a cell.

I am trying to do this using the Excel.AppEvents_SheetBeforeRightClickEventHandler from my C# WinForm application.

I have a MessageBox that pops up that proves my event handler actually fires via my delegate but after setting the "Cancel" variable to "true" it has no effect for me. The Excel RMB menu appears when it should not. The Cancel parameter is declared as "ref bool".

I am wondering if there is a problem with the marshalling of this variable in the Office PIA which I am using. I would be happy to send code that demos my problem. Can someone please let me know if they can make it work ?

By the way I have already written some VB6 code that works fine and VBA code in an Excel Workbook that also works just fine as well. Both disable the menu as I require when I set "Cancel" to "True". The problem is that I need to do this from a C# application.

Can anyone shed some light on this at all ?

I am using...

Microsoft Excel 2002 (10.4302.4219) SP-2
Visual Studio 2003 v7.1.3088
Microsoft .NET Framework 1.1 v1.1.4322

I obtained the Office XP Primary Interop Assemblies from the following link

http://www.microsoft.com/downloads/d...displaylang=en


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,824
Default Cannot seem to Cancel EXCEL App Right Click Event using C#

I think you're speaking the Greek here!

But I can disable the rightclick option on a worksheet by disabling the "Cell"
commandbar.

Maybe it'll work for you:

Dim myIndex As Long
myIndex = Application.CommandBars("cell").Index
Application.CommandBars(myIndex).Enabled = False
Application.CommandBars(myIndex + 3).Enabled = False

The +3 refers to the "cell" commandbar when you're in View|PageBreak Preview
mode.

(Don't forget to turn it back to True when you're done. This setting will be
kept the next time excel opens!)

Nick Biggs wrote:

I am trying to use Excel from C# and need to disable the menu that appears when clicking the right mouse button on a cell.

I am trying to do this using the Excel.AppEvents_SheetBeforeRightClickEventHandler from my C# WinForm application.

I have a MessageBox that pops up that proves my event handler actually fires via my delegate but after setting the "Cancel" variable to "true" it has no effect for me. The Excel RMB menu appears when it should not. The Cancel parameter is declared as "ref bool".

I am wondering if there is a problem with the marshalling of this variable in the Office PIA which I am using. I would be happy to send code that demos my problem. Can someone please let me know if they can make it work ?

By the way I have already written some VB6 code that works fine and VBA code in an Excel Workbook that also works just fine as well. Both disable the menu as I require when I set "Cancel" to "True". The problem is that I need to do this from a C# application.

Can anyone shed some light on this at all ?

I am using...

Microsoft Excel 2002 (10.4302.4219) SP-2
Visual Studio 2003 v7.1.3088
Microsoft .NET Framework 1.1 v1.1.4322

I obtained the Office XP Primary Interop Assemblies from the following link

http://www.microsoft.com/downloads/d...displaylang=en


--

Dave Peterson

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 115
Default Cannot seem to Cancel EXCEL App Right Click Event using C#

Hi Snark,

There is an known issue in the Office XP PIA which will cause the problem
and the problem has been fixed in the Office 2003 PIA.
Now to workaround the problem, I think we can try to sink the problem
ourselves.

private UCOMIConnectionPoint m_oConnectionPoint;
private int m_Cookie;
private Excel.ApplicationClass exApp;


private void button1_Click(object sender, System.EventArgs e) //sink the
events
{
// QI for IConnectionPointContainer.
UCOMIConnectionPointContainer oConnPointContainer =
(UCOMIConnectionPointContainer)exApp;
// Get the GUID of the EApplication interface.
Guid guid=typeof(Excel.AppEvents).GUID;
// Find the connection point.
oConnPointContainer.FindConnectionPoint(ref guid,out m_oConnectionPoint);
// Call Advise to sink up the connection.
m_oConnectionPoint.Advise(this,out m_Cookie);
}
private void button2_Click(object sender, System.EventArgs e)
{
m_oConnectionPoint.Unadvise(m_Cookie);
System.Runtime.InteropServices.Marshal.ReleaseComO bject(exApp);
GC.Collect();
}
[DispId(1560)]
public void SheetBeforeRightClick(object Sh , object Target ,ref bool
Cancel) //Event handler function
{
Cancel = true;
}
private void Form1_Load(object sender, System.EventArgs e)
{
//Create an instance of Excel .
exApp = new Excel.ApplicationClass();
// Show Excel to the user.
exApp.Visible = true;
}
How To Handle PowerPoint Events With Visual C# .NET
http://support.microsoft.com/default...B;EN-US;308825

HOW TO: Establish a COM Event Sink with Return Values in the .NET Framework
by Using Visual Basic .NET (810228)
http://support.microsoft.com/default...B;EN-US;810228

Best regards,

Peter Huang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6
Default Cannot seem to Cancel EXCEL App Right Click Event using C#

Peter,

Many thanks - this works! I have put your code in a simple WinForm app and it works just fine. I am now trying to understand why the technique which I followed based on KB article 830519 does not work. I posted my code on another thread so here is a link to it

http://msdn.microsoft.com/newsgroups...4-68f3724d0e27

Any ideas why your code works but my Q830519 styled solution does not ?

Nick


""Peter Huang"" wrote:

Hi Snark,

There is an known issue in the Office XP PIA which will cause the problem
and the problem has been fixed in the Office 2003 PIA.
Now to workaround the problem, I think we can try to sink the problem
ourselves.

private UCOMIConnectionPoint m_oConnectionPoint;
private int m_Cookie;
private Excel.ApplicationClass exApp;


private void button1_Click(object sender, System.EventArgs e) //sink the
events
{
// QI for IConnectionPointContainer.
UCOMIConnectionPointContainer oConnPointContainer =
(UCOMIConnectionPointContainer)exApp;
// Get the GUID of the EApplication interface.
Guid guid=typeof(Excel.AppEvents).GUID;
// Find the connection point.
oConnPointContainer.FindConnectionPoint(ref guid,out m_oConnectionPoint);
// Call Advise to sink up the connection.
m_oConnectionPoint.Advise(this,out m_Cookie);
}
private void button2_Click(object sender, System.EventArgs e)
{
m_oConnectionPoint.Unadvise(m_Cookie);
System.Runtime.InteropServices.Marshal.ReleaseComO bject(exApp);
GC.Collect();
}
[DispId(1560)]
public void SheetBeforeRightClick(object Sh , object Target ,ref bool
Cancel) //Event handler function
{
Cancel = true;
}
private void Form1_Load(object sender, System.EventArgs e)
{
//Create an instance of Excel .
exApp = new Excel.ApplicationClass();
// Show Excel to the user.
exApp.Visible = true;
}
How To Handle PowerPoint Events With Visual C# .NET
http://support.microsoft.com/default...B;EN-US;308825

HOW TO: Establish a COM Event Sink with Return Values in the .NET Framework
by Using Visual Basic .NET (810228)
http://support.microsoft.com/default...B;EN-US;810228

Best regards,

Peter Huang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.




  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 115
Default Cannot seem to Cancel EXCEL App Right Click Event using C#

Hi Nick,

Now I am researching the issue, and I will get back here and update you
with new information ASAP.

Best regards,

Peter Huang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.

  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 115
Default Cannot seem to Cancel EXCEL App Right Click Event using C#

Hi Nick,

Based on my research, we need to specified the attribute as below.
[ClassInterface(ClassInterfaceType.None)]
public class Excel10EventHelper : IExcelAppEvents10, IDisposable

So that we can guarantee that there is no default interface generate for
Excel10EventHelper class.
You may have a try and let me know the result.

Best regards,

Peter Huang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.

  #8   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6
Default Cannot seem to Cancel EXCEL App Right Click Event using C#

Peter,

What can I say... this solves all my problems. Vary many thanks.

Nick

""Peter Huang"" wrote:

Hi Nick,

Based on my research, we need to specified the attribute as below.
[ClassInterface(ClassInterfaceType.None)]
public class Excel10EventHelper : IExcelAppEvents10, IDisposable

So that we can guarantee that there is no default interface generate for
Excel10EventHelper class.
You may have a try and let me know the result.

Best regards,

Peter Huang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.


  #9   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default Cannot seem to Cancel EXCEL App Right Click Event using C#

I'm new to VB in excel and am trying to remove the right click menu....I saw
your advice below and tried it out however, when I replace the "Cancel" in
"Worksheet_BeforeRightClick(ByVal Target As Range, Cancel As Boolean)" with
"True" it comes up with a compile error...am I being completely thick?

"Nick Biggs" wrote:

Oh but you can! It is done through the Excel application events. Specifically you simply set the "Cancel" parameter to "True" inside the SheetBeforeRightClick event handler. I can do this from VBA in an XLS workbook and also from VB6 via Ole Automation.

My problem is that it does not work from C#. KB Article 830519 has something to say but it does not appear to work for Excel. Check out the post by Chris Peacock titled "Problem implementing connection point sink" in this newsgroup for a further discussion and some dodgy code by my good self!

"AA2e72E" wrote:

I don't believe you can disable the right click on the activesheet. If you set the AllowPropertyToolbox to false, it disables the Property Toolbox on the right click menu. There is no other property that can be set. The list of properties is:

ActiveCell ActivePane ActiveSheet
AllowPropertyToolbox AutoFit BuildNumber
CSVData CSVURL CanUndo
Cells Columns Constants
DataType Dirty DisplayColHeaders
DisplayGridlines DisplayHorizontalScrollBar DisplayPropertyToolbox
DisplayRowHeaders DisplayTitleBar DisplayToolbar
DisplayVerticalScrollBar EnableAutoCalculate EnableEvents
EnableUndo HTMLData HTMLURL
MajorVersion MaxHeight MaxWidth
MinorVersion MoveAfterReturn MoveAfterReturnDirection
Range RevisionNumber RightToLeft
Rows ScreenUpdating Selection
TitleBar Version ViewableRange

I can't see that there is a right click event.The list of events is:

BeforeCommand Calculate CancelEdit
Change Click Command
DblClick EndEdit KeyDown
KeyPress KeyUp MouseDown
MouseOut MouseOver MouseUp
SelectionChange SelectionChanging StartEdit
ViewChange

Like you, I think the OWC PIA is screwed up. Can you help with my post "OWC Web Component Spreadsheet: C#" in this news group?
"Nick Biggs" wrote:

I am trying to use Excel from C# and need to disable the menu that appears when clicking the right mouse button on a cell.

I am trying to do this using the Excel.AppEvents_SheetBeforeRightClickEventHandler from my C# WinForm application.

I have a MessageBox that pops up that proves my event handler actually fires via my delegate but after setting the "Cancel" variable to "true" it has no effect for me. The Excel RMB menu appears when it should not. The Cancel parameter is declared as "ref bool".

I am wondering if there is a problem with the marshalling of this variable in the Office PIA which I am using. I would be happy to send code that demos my problem. Can someone please let me know if they can make it work ?

By the way I have already written some VB6 code that works fine and VBA code in an Excel Workbook that also works just fine as well. Both disable the menu as I require when I set "Cancel" to "True". The problem is that I need to do this from a C# application.

Can anyone shed some light on this at all ?

I am using...

Microsoft Excel 2002 (10.4302.4219) SP-2
Visual Studio 2003 v7.1.3088
Microsoft .NET Framework 1.1 v1.1.4322

I obtained the Office XP Primary Interop Assemblies from the following link

http://www.microsoft.com/downloads/d...displaylang=en


  #10   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default Cannot seem to Cancel EXCEL App Right Click Event using C#

No, you don't replace Cancel with True, you set it to true

Private Sub Worksheet_BeforeRightClick(ByVal Target As Range, Cancel As
Boolean)
Cancel = True
End Sub


--

HTH

RP
(remove nothere from the email address if mailing direct)


"Ironworks1975" wrote in message
...
I'm new to VB in excel and am trying to remove the right click menu....I

saw
your advice below and tried it out however, when I replace the "Cancel" in
"Worksheet_BeforeRightClick(ByVal Target As Range, Cancel As Boolean)"

with
"True" it comes up with a compile error...am I being completely thick?

"Nick Biggs" wrote:

Oh but you can! It is done through the Excel application events.

Specifically you simply set the "Cancel" parameter to "True" inside the
SheetBeforeRightClick event handler. I can do this from VBA in an XLS
workbook and also from VB6 via Ole Automation.

My problem is that it does not work from C#. KB Article 830519 has

something to say but it does not appear to work for Excel. Check out the
post by Chris Peacock titled "Problem implementing connection point sink" in
this newsgroup for a further discussion and some dodgy code by my good self!

"AA2e72E" wrote:

I don't believe you can disable the right click on the activesheet. If

you set the AllowPropertyToolbox to false, it disables the Property Toolbox
on the right click menu. There is no other property that can be set. The
list of properties is:

ActiveCell ActivePane ActiveSheet
AllowPropertyToolbox AutoFit BuildNumber
CSVData CSVURL CanUndo
Cells Columns Constants
DataType Dirty DisplayColHeaders
DisplayGridlines DisplayHorizontalScrollBar

DisplayPropertyToolbox
DisplayRowHeaders DisplayTitleBar DisplayToolbar
DisplayVerticalScrollBar EnableAutoCalculate EnableEvents
EnableUndo HTMLData HTMLURL
MajorVersion MaxHeight MaxWidth
MinorVersion MoveAfterReturn

MoveAfterReturnDirection
Range RevisionNumber RightToLeft
Rows ScreenUpdating Selection
TitleBar Version ViewableRange

I can't see that there is a right click event.The list of events is:

BeforeCommand Calculate CancelEdit
Change Click Command
DblClick EndEdit KeyDown
KeyPress KeyUp MouseDown
MouseOut MouseOver MouseUp
SelectionChange SelectionChanging StartEdit
ViewChange

Like you, I think the OWC PIA is screwed up. Can you help with my post

"OWC Web Component Spreadsheet: C#" in this news group?
"Nick Biggs" wrote:

I am trying to use Excel from C# and need to disable the menu that

appears when clicking the right mouse button on a cell.

I am trying to do this using the

Excel.AppEvents_SheetBeforeRightClickEventHandler from my C# WinForm
application.

I have a MessageBox that pops up that proves my event handler

actually fires via my delegate but after setting the "Cancel" variable to
"true" it has no effect for me. The Excel RMB menu appears when it should
not. The Cancel parameter is declared as "ref bool".

I am wondering if there is a problem with the marshalling of this

variable in the Office PIA which I am using. I would be happy to send code
that demos my problem. Can someone please let me know if they can make it
work ?

By the way I have already written some VB6 code that works fine and

VBA code in an Excel Workbook that also works just fine as well. Both
disable the menu as I require when I set "Cancel" to "True". The problem is
that I need to do this from a C# application.

Can anyone shed some light on this at all ?

I am using...

Microsoft Excel 2002 (10.4302.4219) SP-2
Visual Studio 2003 v7.1.3088
Microsoft .NET Framework 1.1 v1.1.4322

I obtained the Office XP Primary Interop Assemblies from the

following link


http://www.microsoft.com/downloads/d...displaylang=en






  #11   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 16
Default Cannot seem to Cancel EXCEL App Right Click Event using C#



"Nick Biggs" wrote:

And here is the fixed code...

Question is this... should the Excel10EventHelper class that is inheriting from IExcelAppEvents10 also be inheriting the interfaces [DispId] attributes or not ?

Nick


using System;
using System.Runtime.InteropServices;
using Excel=Microsoft.Office.Interop.Excel;

namespace ExcelAppEvents10
{
[InterfaceType(ComInterfaceType.InterfaceIsIDispatc h),
GuidAttribute("00024413-0000-0000-C000-000000000046")]
public interface IExcelAppEvents10
{
[DispId(0x0000061d)] void NewWorkbook(Excel.Workbook Wb);
[DispId(0x00000616)] void SheetSelectionChange(object sh, Excel.Range Target);
[DispId(0x00000617)] void SheetBeforeDoubleClick(object sh, Excel.Range Target, ref bool Cancel);
[DispId(0x00000618)] void SheetBeforeRightClick(object sh, Excel.Range Target, ref bool Cancel);
[DispId(0x00000619)] void SheetActivate(object sh);
[DispId(0x0000061a)] void SheetDeactivate(object sh);
[DispId(0x0000061b)] void SheetCalculate(object sh);
[DispId(0x0000061c)] void SheetChange(object sh, Excel.Range Target);
[DispId(0x0000061f)] void WorkbookOpen(Excel.Workbook Wb);
[DispId(0x00000620)] void WorkbookActivate(Excel.Workbook Wb);
[DispId(0x00000621)] void WorkbookDeactivate(Excel.Workbook Wb);
[DispId(0x00000622)] void WorkbookBeforeClose(Excel.Workbook Wb, ref bool Cancel);
[DispId(0x00000623)] void WorkbookBeforeSave(Excel.Workbook Wb, bool SaveAsUI, ref bool Cancel);
[DispId(0x00000624)] void WorkbookBeforePrint(Excel.Workbook Wb, ref bool Cancel);
[DispId(0x00000625)] void WorkbookNewSheet(Excel.Workbook Wb, object sh);
[DispId(0x00000626)] void WorkbookAddinInstall(Excel.Workbook Wb);
[DispId(0x00000627)] void WorkbookAddinUninstall(Excel.Workbook Wb);
[DispId(0x00000612)] void WindowResize(Excel.Workbook Wb, Excel.Window Wn);
[DispId(0x00000614)] void WindowActivate(Excel.Workbook Wb, Excel.Window Wn);
[DispId(0x00000615)] void WindowDeactivate(Excel.Workbook Wb, Excel.Window Wn);
[DispId(0x0000073e)] void SheetFollowHyperlink(object sh, Excel.Hyperlink Target);
[DispId(0x0000086d)] void SheetPivotTableUpdate(object sh, Excel.PivotTable Target);
[DispId(0x00000870)] void WorkbookPivotTableCloseConnection(Excel.Workbook Wb, Excel.PivotTable Target);
[DispId(0x00000871)] void WorkbookPivotTableOpenConnection(Excel.Workbook Wb, Excel.PivotTable Target);
}

public class Excel10EventHelper : IExcelAppEvents10, IDisposable
{
public Excel10EventHelper()
{
m_oConnectionPoint = null;
m_Cookie = 0;
}

[DispId(0x0000061d)]
public void NewWorkbook(Excel.Workbook Wb)
{System.Diagnostics.Debug.WriteLine("NewWorkbook") ;}

[DispId(0x00000616)]
public void SheetSelectionChange(object sh, Excel.Range Target)
{System.Diagnostics.Debug.WriteLine("SheetSelectio nChange");}

[DispId(0x00000617)]
public void SheetBeforeDoubleClick(object sh, Excel.Range Target, ref bool Cancel)
{System.Diagnostics.Debug.WriteLine("SheetBeforeDo ubleClick");}

[DispId(0x00000618)]
public void SheetBeforeRightClick(object sh, Excel.Range Target, ref bool Cancel)
{
System.Diagnostics.Debug.WriteLine("SheetBeforeRig htClick");
Cancel = true; // Cancel the right click!
}

[DispId(0x00000619)]
public void SheetActivate(object sh)
{System.Diagnostics.Debug.WriteLine("SheetActivate ");}

[DispId(0x0000061a)]
public void SheetDeactivate(object sh)
{System.Diagnostics.Debug.WriteLine("SheetDeactiva te");}

[DispId(0x0000061b)]
public void SheetCalculate(object sh)
{System.Diagnostics.Debug.WriteLine("SheetCalculat e");}

[DispId(0x0000061c)]
public void SheetChange(object sh, Excel.Range Target)
{System.Diagnostics.Debug.WriteLine("SheetChange") ;}

[DispId(0x0000061f)]
public void WorkbookOpen(Excel.Workbook Wb)
{System.Diagnostics.Debug.WriteLine("WorkbookOpen" );}

[DispId(0x00000620)]
public void WorkbookActivate(Excel.Workbook Wb)
{System.Diagnostics.Debug.WriteLine("WorkbookActiv ate");}

[DispId(0x00000621)]
public void WorkbookDeactivate(Excel.Workbook Wb)
{System.Diagnostics.Debug.WriteLine("WorkbookDeact ivate");}

[DispId(0x00000622)]
public void WorkbookBeforeClose(Excel.Workbook Wb, ref bool Cancel)
{System.Diagnostics.Debug.WriteLine("WorkbookBefor eClose");}

[DispId(0x00000623)]
public void WorkbookBeforeSave(Excel.Workbook Wb, bool SaveAsUI, ref bool Cancel)
{System.Diagnostics.Debug.WriteLine("WorkbookBefor eSave");}

[DispId(0x00000624)]
public void WorkbookBeforePrint(Excel.Workbook Wb, ref bool Cancel)
{System.Diagnostics.Debug.WriteLine("WorkbookBefor ePrint");}

[DispId(0x00000625)]
public void WorkbookNewSheet(Excel.Workbook Wb, object sh)
{System.Diagnostics.Debug.WriteLine("WorkbookNewSh eet");}

[DispId(0x00000626)]
public void WorkbookAddinInstall(Excel.Workbook Wb)
{System.Diagnostics.Debug.WriteLine("WorkbookAddin Install");}

[DispId(0x00000627)]
public void WorkbookAddinUninstall(Excel.Workbook Wb)
{System.Diagnostics.Debug.WriteLine("WorkbookAddin Uninstall");}

[DispId(0x00000612)]
public void WindowResize(Excel.Workbook Wb, Excel.Window Wn)
{System.Diagnostics.Debug.WriteLine("WindowResize" );}

[DispId(0x00000614)]
public void WindowActivate(Excel.Workbook Wb, Excel.Window Wn)
{System.Diagnostics.Debug.WriteLine("WindowActivat e");}

[DispId(0x00000615)]
public void WindowDeactivate(Excel.Workbook Wb, Excel.Window Wn)
{System.Diagnostics.Debug.WriteLine("WindowDeactiv ate");}

[DispId(0x0000073e)]
public void SheetFollowHyperlink(object sh, Excel.Hyperlink Target)
{System.Diagnostics.Debug.WriteLine("SheetFollowHy perlink");}

[DispId(0x0000086d)]
public void SheetPivotTableUpdate(object sh, Excel.PivotTable Target)
{System.Diagnostics.Debug.WriteLine("SheetPivotTab leUpdate");}

[DispId(0x00000870)]
public void WorkbookPivotTableCloseConnection(Excel.Workbook Wb, Excel.PivotTable Target)
{System.Diagnostics.Debug.WriteLine("WorkbookPivot TableCloseConnection");}

[DispId(0x00000871)]
public void WorkbookPivotTableOpenConnection(Excel.Workbook Wb, Excel.PivotTable Target)
{System.Diagnostics.Debug.WriteLine("WorkbookPivot TableOpenConnection");}

private UCOMIConnectionPoint m_oConnectionPoint;
private int m_Cookie;
private Excel.ApplicationClass m_xlApp;

public void SetupConnection(Excel.ApplicationClass app)
{
if (m_Cookie != 0) return;

// QI for IConnectionPointContainer.
UCOMIConnectionPointContainer oConnPointContainer = (UCOMIConnectionPointContainer) app;

// GUID of the Excel AppEvents dispinterface.
Guid guid = new Guid("{00024413-0000-0000-C000-000000000046}");
// Guid guid = typeof(Excel.AppEvents).GUID; also works!

// Find the connection point.
oConnPointContainer.FindConnectionPoint(ref guid, out m_oConnectionPoint);

// Call Advise to sink up the connection.
m_oConnectionPoint.Advise(this, out m_Cookie);
}

public void RemoveConnection()
{
if (m_Cookie != 0)
{
m_oConnectionPoint.Unadvise(m_Cookie);
m_oConnectionPoint = null;
m_Cookie = 0;
}
}

public void Dispose(){RemoveConnection();}
}
}

  #12   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 16
Default Cannot seem to Cancel EXCEL App Right Click Event using C#



"AA2e72E" wrote:

I don't believe you can disable the right click on the activesheet. If you set the AllowPropertyToolbox to false, it disables the Property Toolbox on the right click menu. There is no other property that can be set. The list of properties is:

ActiveCell ActivePane ActiveSheet
AllowPropertyToolbox AutoFit BuildNumber
CSVData CSVURL CanUndo
Cells Columns Constants
DataType Dirty DisplayColHeaders
DisplayGridlines DisplayHorizontalScrollBar DisplayPropertyToolbox
DisplayRowHeaders DisplayTitleBar DisplayToolbar
DisplayVerticalScrollBar EnableAutoCalculate EnableEvents
EnableUndo HTMLData HTMLURL
MajorVersion MaxHeight MaxWidth
MinorVersion MoveAfterReturn MoveAfterReturnDirection
Range RevisionNumber RightToLeft
Rows ScreenUpdating Selection
TitleBar Version ViewableRange

I can't see that there is a right click event.The list of events is:

BeforeCommand Calculate CancelEdit
Change Click Command
DblClick EndEdit KeyDown
KeyPress KeyUp MouseDown
MouseOut MouseOver MouseUp
SelectionChange SelectionChanging StartEdit
ViewChange

Like you, I think the OWC PIA is screwed up. Can you help with my post "OWC Web Component Spreadsheet: C#" in this news group?
"Nick Biggs" wrote:

I am trying to use Excel from C# and need to disable the menu that appears when clicking the right mouse button on a cell.

I am trying to do this using the Excel.AppEvents_SheetBeforeRightClickEventHandler from my C# WinForm application.

I have a MessageBox that pops up that proves my event handler actually fires via my delegate but after setting the "Cancel" variable to "true" it has no effect for me. The Excel RMB menu appears when it should not. The Cancel parameter is declared as "ref bool".

I am wondering if there is a problem with the marshalling of this variable in the Office PIA which I am using. I would be happy to send code that demos my problem. Can someone please let me know if they can make it work ?

By the way I have already written some VB6 code that works fine and VBA code in an Excel Workbook that also works just fine as well. Both disable the menu as I require when I set "Cancel" to "True". The problem is that I need to do this from a C# application.

Can anyone shed some light on this at all ?

I am using...

Microsoft Excel 2002 (10.4302.4219) SP-2
Visual Studio 2003 v7.1.3088
Microsoft .NET Framework 1.1 v1.1.4322

I obtained the Office XP Primary Interop Assemblies from the following link

http://www.microsoft.com/downloads/d...displaylang=en


  #13   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 16
Default Cannot seem to Cancel EXCEL App Right Click Event using C#



"Nick Biggs" wrote:

Oh but you can! It is done through the Excel application events. Specifically you simply set the "Cancel" parameter to "True" inside the SheetBeforeRightClick event handler. I can do this from VBA in an XLS workbook and also from VB6 via Ole Automation.

My problem is that it does not work from C#. KB Article 830519 has something to say but it does not appear to work for Excel. Check out the post by Chris Peacock titled "Problem implementing connection point sink" in this newsgroup for a further discussion and some dodgy code by my good self!

"AA2e72E" wrote:

I don't believe you can disable the right click on the activesheet. If you set the AllowPropertyToolbox to false, it disables the Property Toolbox on the right click menu. There is no other property that can be set. The list of properties is:

ActiveCell ActivePane ActiveSheet
AllowPropertyToolbox AutoFit BuildNumber
CSVData CSVURL CanUndo
Cells Columns Constants
DataType Dirty DisplayColHeaders
DisplayGridlines DisplayHorizontalScrollBar DisplayPropertyToolbox
DisplayRowHeaders DisplayTitleBar DisplayToolbar
DisplayVerticalScrollBar EnableAutoCalculate EnableEvents
EnableUndo HTMLData HTMLURL
MajorVersion MaxHeight MaxWidth
MinorVersion MoveAfterReturn MoveAfterReturnDirection
Range RevisionNumber RightToLeft
Rows ScreenUpdating Selection
TitleBar Version ViewableRange

I can't see that there is a right click event.The list of events is:

BeforeCommand Calculate CancelEdit
Change Click Command
DblClick EndEdit KeyDown
KeyPress KeyUp MouseDown
MouseOut MouseOver MouseUp
SelectionChange SelectionChanging StartEdit
ViewChange

Like you, I think the OWC PIA is screwed up. Can you help with my post "OWC Web Component Spreadsheet: C#" in this news group?
"Nick Biggs" wrote:

I am trying to use Excel from C# and need to disable the menu that appears when clicking the right mouse button on a cell.

I am trying to do this using the Excel.AppEvents_SheetBeforeRightClickEventHandler from my C# WinForm application.

I have a MessageBox that pops up that proves my event handler actually fires via my delegate but after setting the "Cancel" variable to "true" it has no effect for me. The Excel RMB menu appears when it should not. The Cancel parameter is declared as "ref bool".

I am wondering if there is a problem with the marshalling of this variable in the Office PIA which I am using. I would be happy to send code that demos my problem. Can someone please let me know if they can make it work ?

By the way I have already written some VB6 code that works fine and VBA code in an Excel Workbook that also works just fine as well. Both disable the menu as I require when I set "Cancel" to "True". The problem is that I need to do this from a C# application.

Can anyone shed some light on this at all ?

I am using...

Microsoft Excel 2002 (10.4302.4219) SP-2
Visual Studio 2003 v7.1.3088
Microsoft .NET Framework 1.1 v1.1.4322

I obtained the Office XP Primary Interop Assemblies from the following link

http://www.microsoft.com/downloads/d...displaylang=en


  #14   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 16
Default Cannot seem to Cancel EXCEL App Right Click Event using C#



""Peter Huang"" wrote:

Hi Snark,

There is an known issue in the Office XP PIA which will cause the problem
and the problem has been fixed in the Office 2003 PIA.
Now to workaround the problem, I think we can try to sink the problem
ourselves.

private UCOMIConnectionPoint m_oConnectionPoint;
private int m_Cookie;
private Excel.ApplicationClass exApp;


private void button1_Click(object sender, System.EventArgs e) //sink the
events
{
// QI for IConnectionPointContainer.
UCOMIConnectionPointContainer oConnPointContainer =
(UCOMIConnectionPointContainer)exApp;
// Get the GUID of the EApplication interface.
Guid guid=typeof(Excel.AppEvents).GUID;
// Find the connection point.
oConnPointContainer.FindConnectionPoint(ref guid,out m_oConnectionPoint);
// Call Advise to sink up the connection.
m_oConnectionPoint.Advise(this,out m_Cookie);
}
private void button2_Click(object sender, System.EventArgs e)
{
m_oConnectionPoint.Unadvise(m_Cookie);
System.Runtime.InteropServices.Marshal.ReleaseComO bject(exApp);
GC.Collect();
}
[DispId(1560)]
public void SheetBeforeRightClick(object Sh , object Target ,ref bool
Cancel) //Event handler function
{
Cancel = true;
}
private void Form1_Load(object sender, System.EventArgs e)
{
//Create an instance of Excel .
exApp = new Excel.ApplicationClass();
// Show Excel to the user.
exApp.Visible = true;
}
How To Handle PowerPoint Events With Visual C# .NET
http://support.microsoft.com/default...B;EN-US;308825

HOW TO: Establish a COM Event Sink with Return Values in the .NET Framework
by Using Visual Basic .NET (810228)
http://support.microsoft.com/default...B;EN-US;810228

Best regards,

Peter Huang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.


  #15   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 16
Default Cannot seem to Cancel EXCEL App Right Click Event using C#



"Nick Biggs" wrote:

I am trying to use Excel from C# and need to disable the menu that appears when clicking the right mouse button on a cell.

I am trying to do this using the Excel.AppEvents_SheetBeforeRightClickEventHandler from my C# WinForm application.

I have a MessageBox that pops up that proves my event handler actually fires via my delegate but after setting the "Cancel" variable to "true" it has no effect for me. The Excel RMB menu appears when it should not. The Cancel parameter is declared as "ref bool".

I am wondering if there is a problem with the marshalling of this variable in the Office PIA which I am using. I would be happy to send code that demos my problem. Can someone please let me know if they can make it work ?

By the way I have already written some VB6 code that works fine and VBA code in an Excel Workbook that also works just fine as well. Both disable the menu as I require when I set "Cancel" to "True". The problem is that I need to do this from a C# application.

Can anyone shed some light on this at all ?

I am using...

Microsoft Excel 2002 (10.4302.4219) SP-2
Visual Studio 2003 v7.1.3088
Microsoft .NET Framework 1.1 v1.1.4322

I obtained the Office XP Primary Interop Assemblies from the following link

http://www.microsoft.com/downloads/d...displaylang=en




  #16   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 16
Default Cannot seem to Cancel EXCEL App Right Click Event using C#



"Nick Biggs" wrote:

Peter,

Many thanks - this works! I have put your code in a simple WinForm app and it works just fine. I am now trying to understand why the technique which I followed based on KB article 830519 does not work. I posted my code on another thread so here is a link to it

http://msdn.microsoft.com/newsgroups...4-68f3724d0e27

Any ideas why your code works but my Q830519 styled solution does not ?

Nick


""Peter Huang"" wrote:

Hi Snark,

There is an known issue in the Office XP PIA which will cause the problem
and the problem has been fixed in the Office 2003 PIA.
Now to workaround the problem, I think we can try to sink the problem
ourselves.

private UCOMIConnectionPoint m_oConnectionPoint;
private int m_Cookie;
private Excel.ApplicationClass exApp;


private void button1_Click(object sender, System.EventArgs e) //sink the
events
{
// QI for IConnectionPointContainer.
UCOMIConnectionPointContainer oConnPointContainer =
(UCOMIConnectionPointContainer)exApp;
// Get the GUID of the EApplication interface.
Guid guid=typeof(Excel.AppEvents).GUID;
// Find the connection point.
oConnPointContainer.FindConnectionPoint(ref guid,out m_oConnectionPoint);
// Call Advise to sink up the connection.
m_oConnectionPoint.Advise(this,out m_Cookie);
}
private void button2_Click(object sender, System.EventArgs e)
{
m_oConnectionPoint.Unadvise(m_Cookie);
System.Runtime.InteropServices.Marshal.ReleaseComO bject(exApp);
GC.Collect();
}
[DispId(1560)]
public void SheetBeforeRightClick(object Sh , object Target ,ref bool
Cancel) //Event handler function
{
Cancel = true;
}
private void Form1_Load(object sender, System.EventArgs e)
{
//Create an instance of Excel .
exApp = new Excel.ApplicationClass();
// Show Excel to the user.
exApp.Visible = true;
}
How To Handle PowerPoint Events With Visual C# .NET
http://support.microsoft.com/default...B;EN-US;308825

HOW TO: Establish a COM Event Sink with Return Values in the .NET Framework
by Using Visual Basic .NET (810228)
http://support.microsoft.com/default...B;EN-US;810228

Best regards,

Peter Huang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.


  #17   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 16
Default Cannot seem to Cancel EXCEL App Right Click Event using C#



""Peter Huang"" wrote:

Hi Nick,

Based on my research, we need to specified the attribute as below.
[ClassInterface(ClassInterfaceType.None)]
public class Excel10EventHelper : IExcelAppEvents10, IDisposable

So that we can guarantee that there is no default interface generate for
Excel10EventHelper class.
You may have a try and let me know the result.

Best regards,

Peter Huang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.


  #18   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 16
Default Cannot seem to Cancel EXCEL App Right Click Event using C#



""Peter Huang"" wrote:

Hi Nick,

Now I am researching the issue, and I will get back here and update you
with new information ASAP.

Best regards,

Peter Huang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.


  #19   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 16
Default Cannot seem to Cancel EXCEL App Right Click Event using C#



"Nick Biggs" wrote:

Peter,

What can I say... this solves all my problems. Vary many thanks.

Nick

""Peter Huang"" wrote:

Hi Nick,

Based on my research, we need to specified the attribute as below.
[ClassInterface(ClassInterfaceType.None)]
public class Excel10EventHelper : IExcelAppEvents10, IDisposable

So that we can guarantee that there is no default interface generate for
Excel10EventHelper class.
You may have a try and let me know the result.

Best regards,

Peter Huang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.


Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Cancel sheet change event NSK Charts and Charting in Excel 1 July 17th 07 08:25 PM
On Click Event?, and how to use Wandering Mage Excel Programming 5 June 7th 04 04:28 PM
Cancel terminate event?? Pop Excel Programming 1 May 19th 04 12:00 PM
Before Right Click event mohsinb[_8_] Excel Programming 10 December 22nd 03 08:47 AM
Click Event Nichevo Excel Programming 2 December 4th 03 04:31 AM


All times are GMT +1. The time now is 10:13 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"