I am in the process of creating a plugin (or addin) for CorelDraw X6 using VSTA (Visual Studio for Applications) because I like C# and .NET library. I would like to have a button in CorelDraw toolbar, so when a user clicks this button some action happens, for example, a form is showed. For that I use predefined solution VSTAGlobal, that is there for me when I start CorelDraw. Unfortunately, there is NO official documentation (WTF!!!!!) for VSTA in CorelDraw, instead we have VBA (Visual Basic for Applications) documentation and CorelDraw Object Model. I googled a lot and found a few links: some forum post and YouTube video tutorial. The problem is, both guys there create their CustomControl (a buton for example) and simply build it as *.dll and then use VBA script to add the CustomControl to CorelDraw toolbar like this
Sub addLineWidthControl()
Call FrameWork.CommandBars("Standard").Controls. '
AddCustomControl("MyNameSpace.MyCustomControlClass", '
"MyCustomControlAssembly.dll")
End Sub
So, my question is: is there any way to do this using only VSTA?
Additional info:
For example, in the default solution VSTAGlobal there is a Main class with [CgsAddInModule] attribute:
[CgsAddInModule]
public partial class Main
{
private Corel.Interop.VGCore.Application app;
// some other code here...
}
This class has a constructor (note, default and provided by CorelDraw):
[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?
}
Maybe this is the place where I should add something like this:
app.FrameWork.CommandBars["Standard"]
.Controls.AddCustomControl("MyCustomControlClass");
I did some experiments with this last line of code. I obtained that the Count of Controls is increasing, but still MyCustomControl does not show up in the toolbar.
There is a way to use only C# (I tested this in Corel X8 but it should work in any version that has VSTA). It is a 2 part process though. First you will need to open Macro Manager in Corel and edit the VSTAGlobal solution. For example, if you want to add a button and a slider, add this method:
Once you add this code, you will need to add a .dll for a solution to the folder listed above. Open Visual Studio 2015 and create a new project (mine was named CoreDrawPoC). It needs to be a WPF User Control Library project. Create 2 .xaml files with. First will be the slider:
Code behind is:
Then create the button:
Code behind:
}
Once that is done, you will want to compile the code. Also, you will want to create the image C:\CorelIcons\Two.bmp. It is just a 24x24 bitmap that looks however you want it to look. Then compile the project. You will need to this will CorelDraw closed.
Once it compiles successfully, you will want to go and run your VSTA macro to add the button and slider. This macro will only need to be run 1 time! After than, it will connect directly to the code in your dll. If you change anything in the dll and update it while Corel is closed, it changes it. This includes the images.
Finally, I learned how to do this from 2 blog posts and I only changed it to add a button to the Standard command bar and to use purely C#. Those posts are: