我正在尝试使用Visio 2003进行一次小型绘图自动化。但是,我在使用MSDN所说的内容并将其合并到我的代码中时遇到了问题。我可能犯了一个非常新手的错误。但是,经过几天的互联网搜索,我还没有实施解决方案。
我试图简单地从tbClick打开模板。 MSDN站点告诉我使用DrawingControl.Src打开模板。但是,当我将DrawingControl应用于代码并编译时,我收到此错误:非静态字段,方法或属性“VisOcx.IDrawingCopntrol.Src.get”(CS0120)需要对象引用。下面是一段代码,显示了命名空间资源和我试图实现的功能。
我对所有关于代码的建议持开放态度。
//namespace
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Windows.Forms;
using System.Diagnostics;
using System.Runtime.Serialization;
using System.Runtime.InteropServices;
using Visio1 = Microsoft.Office.Interop.Visio;
using Visio2 = VisOcx;
//function
void Qed2_elevation_stencil_tbClick(object sender, EventArgs e)
{
try
{
Visio2.DrawingControl.Src = "C:\\Drawing.vsd";
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
return;
}
我认为我更接近于使这个代码工作。我现在收到错误,“Qed2_elevation_stencil_tbClick'没有超载匹配委托'System.EventHandler'(CSO123)。下面是更新的代码。提前感谢任何愿意提供帮助的人。
//
// qed2_elevation_stencil_tb
//
this.qed2_elevation_stencil_tb.ToolTipText = "QED2 Front Elevation";
this.qed2_elevation_stencil_tb.Click += new
system.EventHandler(this.Qed2_elevation_stencil_tbClick);
using System;
using System.Configuration;
using System.Collections.Generic;
using System.Collections;
using System.Data;
using System.Drawing;
using System.Windows.Forms;
using System.Diagnostics;
using System.Runtime.Serialization;
using System.Runtime.InteropServices;
using System.IO;
using Visio1 = Microsoft.Office.Interop.Visio;
using Visio2 = VisOcx;
using Visio3 = AxMicrosoft.Office.Interop.VisOcx;
public partial class MainForm : Form
{
public MainForm()
{
//
// The InitializeComponent() call is required for Windows Forms designer support.
//
InitializeComponent();
//
// TODO: Add constructor code after the InitializeComponent() call.
//
}
private Visio1.Application VisApp = null;
private Visio1.Page VisPage = null;
private Visio1.Document VisDocument = null;
private Visio1.Documents VisDocuments = null;
private Visio1.Window VisWindow = null;
private Visio1.Document VisStencil = null;
private void Qed2_elevation_stencil_tbClick(ref Visio1.Documents visDocuments)
{
string stencilPath = System.IO.Path.Combine(@"C:\\Documents and Settings\\MGPF50\\My Documents\\Visio Stencils", @"Front Elevation Stencil.vss");
try
{
VisStencil = visDocuments.OpenEx(stencilPath,
(short)Visio1.VisOpenSaveArgs.visOpenRO
+ (short)Visio1.VisOpenSaveArgs.visOpenHidden
+ (short)Visio1.VisOpenSaveArgs.visOpenMinimized
+ (short)Visio1.VisOpenSaveArgs.visOpenNoWorkspace);
}
catch (COMException exp)
{
MessageBox.Show("Error Loading Stencil: " + stencilPath + exp.Message);
throw exp;
}
}