title: Create a custom control in Corel Draw X6 using only VSTA
body: <p>I am in the process of creating a plugin (or addin) for <strong>CorelDraw X6</strong> using <strong>VSTA (Visual Studio for Applications)</strong> because I like <strong>C#</strong> and <strong>.NET library</strong>. I would like to have a button in <strong>CorelDraw</strong> toolbar, so when a user clicks this button some action happens, for example, a form is showed. For that I use predefined solution <em>VSTAGlobal</em>, that is there for me when I start <strong>CorelDraw</strong>. Unfortunately, there is <strong>NO</strong>  <strong>official documentation</strong> (WTF!!!!!) for <strong>VSTA</strong> in <strong>CorelDraw</strong>, instead we have <strong>VBA (Visual Basic for Applications)</strong> documentation and <strong>CorelDraw Object Model</strong>. I googled a lot and found a few links: <a href="http://forum.oberonplace.com/blog.php?bt=39072" rel="nofollow" title="some post from forum">some forum post</a> and <a href="http://www.youtube.com/playlist?list=PLifjrLV9azlypQ3IW3W6X017UIl_-0K8p&amp;feature=c4-feed-u" rel="nofollow" title="YuoTube video tutorial">YouTube video tutorial</a>. The problem is, both guys there create their <em>CustomControl</em> (a buton for example) and simply build it as *.dll and then use <strong>VBA</strong> script to add the <em>CustomControl</em> to <strong>CorelDraw</strong> toolbar like this</p>
  
  <pre><code>Sub addLineWidthControl()
      Call FrameWork.CommandBars("Standard").Controls. '
           AddCustomControl("MyNameSpace.MyCustomControlClass", '
                            "MyCustomControlAssembly.dll")
  End Sub
  </code></pre>
  
  <p>So, my question is: <strong>is there any way to do this using only VSTA</strong>?</p>
  
  <p><strong><em>Additional info</em></strong>:</p>
  
  <p>For example, in the default solution <em>VSTAGlobal</em> there is a <em>Main</em> class with [CgsAddInModule] attribute:</p>
  
  <pre><code>[CgsAddInModule]
  public partial class Main
  {
      private Corel.Interop.VGCore.Application app;
  
      // some other code here...
  }
  </code></pre>
  
  <p>This class has a constructor (note, default and provided by <strong>CorelDraw</strong>):</p>
  
  <pre><code>[CgsAddInConstructor]
  public Main(object _app)
  // this constructor probably gets an instance
  // of CorelDraw application object.
  {
      app = _app as Corel.Interop.VGCore.Application;
      // will it work if I add some code here?
  }
  </code></pre>
  
  <p>Maybe this is the place where I should add something like this:</p>
  
  <pre><code>app.FrameWork.CommandBars["Standard"]
      .Controls.AddCustomControl("MyCustomControlClass");
  </code></pre>
  
  <p>I did some experiments with this last line of code. I obtained that the <em>Count</em> of <em>Controls</em> is increasing, but still <em>MyCustomControl</em> does not show up in the toolbar.</p>