0

我正在尝试使用 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;
        }
    }
4

1 回答 1

0

当需要实例化以供使用时,您正尝试静态访问绘图控件。这是一个应该有所帮助的演练。

于 2009-01-20T17:50:51.250 回答