tags:

views:

619

answers:

2

I am dabbling in a little drawing automation with Visio 2003. However, I am having a problem taking what MSDN says and incorporating it into my code. I am probably making a very newbie mistake. However, after days of searching the internet I have yet to implement a solution.

I am trying to simply open a stencil from a tbClick. The MSDN site tells me to use DrawingControl.Src to open the stencil. However, when I apply DrawingControl to the code and compile I get this error: An object reference is required for the nonstatic field, method, or property 'VisOcx.IDrawingCopntrol.Src.get'(CS0120). Below is a snippet of code that shows the namespace resources and the function I am trying to implement.

I am open to any and all suggestions about the code as well.

//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;
  }
A: 

You are trying to access the drawing control statically, when it needs to be instantiated for use. Here's a walkthrough that should help.

cmsjr
I have reviewed the website and downloaded their code, thank you for this link. Is the solution then to make the function static? The application on the website you pointed me to has this type of function but their function was static.
tejas_grande
I apologize cmsjr, that previous statement is not true. I am currently trying to make their code work. Thanks again, I will post soon with a result.
tejas_grande
A: 

I think I am much closer to making this code work. I am now getting the error, "No overload for 'Qed2_elevation_stencil_tbClick' matches delegate 'System.EventHandler' (CSO123). Below is the updated code. Thank you in advance for anyone who is willing to help.

// 
// 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;
        }
 }
tejas_grande