Shape Change event not working.

E

Eric

I need to capture the events for 1. deleting a shape, 2. changing the shape
text, 3. moving a shape and 4. connecting/disconnecting a "line" shape to a
shape's connection point.


My first two events (1 and 2) are being captured. The others (3 and 4) are
not. I thought Mod Shape or Mod Cell would take care of this. Am I doing
this correctly?

**********************************
************SOURCE *************
**********************************
case (short) Visio.VisEventCodes.visEvtDel + (short)
Visio.VisEventCodes.visEvtShape:

System.Windows.Forms.MessageBox.Show("del shape");

break;

case (short) Visio.VisEventCodes.visEvtCodeShapeExitTextEdit:

System.Windows.Forms.MessageBox.Show("TextEdit");

break;

case (short) Visio.VisEventCodes.visEvtMod + (short)
Visio.VisEventCodes.visEvtCell:

System.Windows.Forms.MessageBox.Show("mod cell");

break;

case (short) Visio.VisEventCodes.visEvtMod + (short)
Visio.VisEventCodes.visEvtShape:

System.Windows.Forms.MessageBox.Show("mod shape");

break;

case (unchecked((short) Visio.VisEventCodes.visEvtAdd) + (short)
Visio.VisEventCodes.visEvtConnect):

System.Windows.Forms.MessageBox.Show("add conx");

break;

case (short) Visio.VisEventCodes.visEvtDel + (short)
Visio.VisEventCodes.visEvtConnect:

System.Windows.Forms.MessageBox.Show("del conx");

break;

default:

System.Windows.Forms.MessageBox.Show(eventCode.ToString());

break;

**********************************
**********END SOURCE ***********
**********************************

Thanks,

Eric
 
M

Markus Breugst

Hi Eric,

I use the following event codes:
1. Cell changes (for example when shapes are moved):
(short) VisEventCodes.visEvtMod + (short) VisEventCodes.visEvtFormula
2. Adding a connection to a shape
(short) -32768 + (short) VisEventCodes.visEvtConnect
3. Removing a connection from a shape
(short) VisEventCodes.visEvtDel + (short) VisEventCodes.visEvtConnect

Concerning event code 1: This event is fired if any cell value is changed.
If you only want to listen to specific cells (like PinX and PinY), you
should set a filter for this event. I'm sure you will find a description of
event filters at the MSDN library.

Best regards,
Markus
 
E

Eric

Thanks for the help, Markus.

Although my "Shape Delete" is being caught by my handler (via Visio Document
AddAdvise) your suggested events are not being caught.

Here is an example of how I implemented "1"

VisDocument = (Visio.Document) axDrawingControl1.Document;.
Visio.EventList eventListDoc = VisDocument.EventList;

resultEvent = eventListDoc.AddAdvise(
((short) Visio.VisEventCodes.visEvtMod + (short)
Visio.VisEventCodes.visEvtFormula),
(Visio.IVisEventProc) eventSinkHandler,
"",
"" );

FYI, My eventSinkHandler includes the following object :
object Visio.IVisEventProc.VisEventProc(
short eventCode,
object source,
int eventID,
int eventSeqNum,
object subject,
object moreInfo)

Any idea on why the event is not being caught?

Thanks again,
Eric
 
M

Markus Breugst

Well, the only differences I see are that
- I am using the whole Visio application instead of the drawing control and
- I am adding the event handlers to the Visio Application object instead of
the Document

But these things should not be a problem, since also a Visio document should
fire a FormulaChanged event of the contained shapes.

And right now I checked with the Visio EventMonitor that the FormulaChanged
event is definitely fired when a shape is moved. So, somehow it gets lost in
your application.

Are you sure that your VisEventProc is not entered? Perhaps it only returns
before your test output? Have you modified the case statement according to
the new event type? Currently I don't have any other ideas. If I get one,
I'll tell you.

Best regards,
Markus
 
E

Eric

There's an exception in the code that wasn't propogating to a MessageBox.

Here's the culprit:
case ((short) -32768 + (short) Visio.VisEventCodes.visEvtConnect):
object conx = (Visio.Connect) subject;
System.Windows.Forms.MessageBox.Show("add conx");
break;

For object conx = (Visio.Connect) subject; I am receiving an Invalid Cast
exception.

I'll research/test for a solution.

Eric
 
E

Eric

I'm having trouble casting the subject. I tried using AddAdvise on the
shape itself, I'm getting a COM Exception error when I try that.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top