Visio에서 현재 선택한 셰이프의 PinX 및 PinY 값을 키보드 시퀀스에서 설정하려고합니다. [Ctrl] + [G]. 이 작업의 목적은 프로그래밍 방식으로 현재 선택된 도형의 핀 좌표를 기반으로 Visio 드로잉에 도형을 놓는 것입니다. 나는 이것을하기 위해 C#과 Microsoft.Office.Interop.Visio API를 사용하고있다. .NET 4.0 (mscorlib.dll은 버전 4.0.30319.1)을 사용하고 있습니다.현재 선택한 셰이프의 PinX, PinY ShapeSheet 셀 값을 읽습니다. Visio, C# COM Interop
은 지금까지 나는이 코드를 가지고 :이 코드는 COMException이 발생
Application myApp; // the reference to the Visio Application instance, which is passed into this class via constructor
Shape currShape; // a global variable for this class
//... down to the method in question
void app_KeyUp(int KeyCode, int KeyButtonState, ref bool CancelDefault)
{
currShape = myApp.ActiveWindow.Selection[0];
String xCoord = currShape.get_Cells("PinX").Formula;
String yCoord = currShape.get_Cells("PinY").Formula;
//handle keyboard events here
//...
}
을; 조사한 결과, myApp.ActiveWindow.Selection에 요소 [0] (단 하나의 모양 만 선택된 경우 유일한 요소)가 있어도 실제로 해당 요소를 currShape에 저장할 수는 없습니다. 왜 그런지 모르겠습니다. 이상하게도 COMException은 프로그램을 중지시키지 않습니다. 프로그램은 currShape에 할당하려 할 때 메소드에서 빠져 나오지만 실행은 계속됩니다.
다른 방법으로 현재 모양을 얻으려고했습니다. 이것은 이전과는 달리,이 예외가 실행을 중단했기 때문에 이번에는 그것을 볼 수 있었던 것을 제외하고는 동일한 COMException을 발생 시켰습니다.
이 코드 : 나는 "잘못된 선택 식별자가"무엇을 의미하는지 단서가없고, 인터넷 검색은 Visual Basic 및입니다 this 주제를 산출
System.Runtime.InteropServices.COMException was unhandled
Message="\n\nInvalid selection identifier."
Source="Microsoft Visio"
ErrorCode=-2032465753
StackTrace:
at Microsoft.Office.Interop.Visio.SelectionClass.get_Item(Int32 Index)
at WindowsFormsApplication4.Handler.test() in C:\Users\pvs5x\Documents\Visual Studio 2008\Projects\ACCESS(1)\Handler.cs:line 91
at WindowsFormsApplication4.Form3.changeColorToolStripMenuItem_Click(Object sender, EventArgs e) in C:\Users\pvs5x\Documents\Visual Studio 2008\Projects\ACCESS(1)\OpenSafetyCase.cs:line 355
at System.Windows.Forms.ToolStripItem.RaiseEvent(Object key, EventArgs e)
at System.Windows.Forms.ToolStripMenuItem.OnClick(EventArgs e)
at System.Windows.Forms.ToolStripItem.HandleClick(EventArgs e)
at System.Windows.Forms.ToolStripItem.HandleMouseUp(MouseEventArgs e)
at System.Windows.Forms.ToolStripItem.FireEventInteractive(EventArgs e, ToolStripItemEventType met)
at System.Windows.Forms.ToolStripItem.FireEvent(EventArgs e, ToolStripItemEventType met)
at System.Windows.Forms.ToolStrip.OnMouseUp(MouseEventArgs mea)
at System.Windows.Forms.ToolStripDropDown.OnMouseUp(MouseEventArgs mea)
at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.ScrollableControl.WndProc(Message& m)
at System.Windows.Forms.ToolStrip.WndProc(Message& m)
at System.Windows.Forms.ToolStripDropDown.WndProc(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
at System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
at System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(Int32 dwComponentID, Int32 reason, Int32 pvLoopData)
at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
at System.Windows.Forms.Application.Run(Form mainForm)
at WindowsFormsApplication4.Program.Main() in C:\Users\pvs5x\Documents\Visual Studio 2008\Projects\ACCESS(1)\Program.cs:line 20
at System.AppDomain._nExecuteAssembly(Assembly assembly, String[] args)
at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart()
InnerException:
:
public void test()
{
currShape = myApp.ActiveWindow.Selection[0];
String x = currShape.Shapes[1].get_Cells("PinX").Formula;
currShape.Shapes[1].get_Cells("PinX").FormulaForce = "5";
}
이 예외를 발생 C#이 아닙니다.
두 가지 질문은 다음과 같습니다.
(1) 여기서 무엇이 잘못됩니까?
(2) 이러한 종류의 조작을 위해 현재 선택된 모양에 액세스하는 올바른 방법은 무엇입니까?
도움 주셔서 감사합니다.
어떤 이유로 든 더 게시 된 답변을 볼 수 없습니다. –