Custom .NET Dockers in CorelDRAW X6
Posted 01-04-2012 at 23:38 by shelbym
Introduction
In the previous blog post we showed an example of a custom WPF control that was hosted in the UI of CorelDRAW. In this post we are going to take a Custom Web Docker that Hendrik had provided as an example and rewrite it as a Custom WPF .NET Docker. If you have never made a custom docker his article is a wonderful place to start. You may find it here: Custom add-ons and dockers in CorelDRAW
WPF User Control Library
Once again I will be using Visual Studio Professional. I will be posting all code samples this time in VB.NET as they were downloaded the most often in the last blog post. I will however include a C# version of the source code for those that prefer it.
To begin Open Visual Studio and Start a New Project | Visual Basic | Windows | WPF User Control Library. I named my project SM_Selection_VB, but feel free to name it whatever you like. Rename the UserControl1.xaml to Docker.xaml, double click on the Docker.xaml.vb and rename the public class UserControl1 to Docker. In the Solution Explorer right click your project name, in my case SM_Selection_VB and select add reference. If you have done the previous example the CorelDRAW interop assemblies will be listed in the Recent tab, if not the 64-bit location is:
XAML
Since we are creating a docker we will use the DesignHeight and DesignWidth, I have found that DesignWidth is best set to 225, and the height can be whatever fits your content best, in this case I went with a DesignHeight of 500.
Replace the Grid, with a StackPanel and then we can drag our needed labels, textboxes, and buttons from the Toolbox to our XAML, if you prefer you could of course type all the XAML by hand. I like to rename all the controls so they are easily identified. When you are done, you should have something that looks like the XAML below:
Now that we are done with the XAML we need to code it up, this time we shall use Visual Basic. Again, keeping the code very basic, we have a Sub for each button that we created and our Sub for the SelectionChange event, you will only need WithEvents if you are listening for these types of events. All the selection of our shapes is done with a little CQL, which makes it very simple. When you are done, your code will look something like this:
Save your work, and Build the solution to generate the .dll, I move the .dll to my Addons folder, but it can be placed anywhere you wish. Just remember where you put it because you will need to reference it in your VBA code.
Add Custom Docker
Adding the docker is very similar to adding or WPF Custom Control; expect that we will need a unique GUID to identify the docker by. You can generate a GUID from the tool included with Visual Studio, Create GUID, or if you prefer use an online tool such as: http://www.guidgenerator.com/ the important thing to remember is that you need to generate a new GUID for each new Custom .NET Docker you create.
The following VBA code, creates the docker in the UI, and makes an entry for our Docker in the Windows | Dockers menu.
The newly create docker should look similar to this:
Congratulations you have just created your very first Custom WPF .NET Docker for CorelDRAW X6. As always if you have question feel free to ask them in the forums.
Coming up Next…
Adding a Custom Docker or Control via XSLT instead of VBA
Full Visual Studio 2010 Source Code
If you would like to look at the full source code, I am providing both C# and VB.NET examples.
SM_Selection_CSharp.zip
SM_Selection_VB.zip
In the previous blog post we showed an example of a custom WPF control that was hosted in the UI of CorelDRAW. In this post we are going to take a Custom Web Docker that Hendrik had provided as an example and rewrite it as a Custom WPF .NET Docker. If you have never made a custom docker his article is a wonderful place to start. You may find it here: Custom add-ons and dockers in CorelDRAW
WPF User Control Library
Once again I will be using Visual Studio Professional. I will be posting all code samples this time in VB.NET as they were downloaded the most often in the last blog post. I will however include a C# version of the source code for those that prefer it.
To begin Open Visual Studio and Start a New Project | Visual Basic | Windows | WPF User Control Library. I named my project SM_Selection_VB, but feel free to name it whatever you like. Rename the UserControl1.xaml to Docker.xaml, double click on the Docker.xaml.vb and rename the public class UserControl1 to Docker. In the Solution Explorer right click your project name, in my case SM_Selection_VB and select add reference. If you have done the previous example the CorelDRAW interop assemblies will be listed in the Recent tab, if not the 64-bit location is:
C:\Program Files\Corel\CorelDRAW Graphics Suite X6\Programs64\AssembliesYou need to add a reference to both the Corel.Interop.CorelDRAW.dll and Corel.Interop.VGCore.dll. That should be it for setup we are all ready to get started coding.
XAML
Since we are creating a docker we will use the DesignHeight and DesignWidth, I have found that DesignWidth is best set to 225, and the height can be whatever fits your content best, in this case I went with a DesignHeight of 500.
Replace the Grid, with a StackPanel and then we can drag our needed labels, textboxes, and buttons from the Toolbox to our XAML, if you prefer you could of course type all the XAML by hand. I like to rename all the controls so they are easily identified. When you are done, you should have something that looks like the XAML below:
Visual Basic
Now that we are done with the XAML we need to code it up, this time we shall use Visual Basic. Again, keeping the code very basic, we have a Sub for each button that we created and our Sub for the SelectionChange event, you will only need WithEvents if you are listening for these types of events. All the selection of our shapes is done with a little CQL, which makes it very simple. When you are done, your code will look something like this:
Note: I did not post the full code due to space, if you want to see all the code please download the source files.
Save your work, and Build the solution to generate the .dll, I move the .dll to my Addons folder, but it can be placed anywhere you wish. Just remember where you put it because you will need to reference it in your VBA code.
Add Custom Docker
Adding the docker is very similar to adding or WPF Custom Control; expect that we will need a unique GUID to identify the docker by. You can generate a GUID from the tool included with Visual Studio, Create GUID, or if you prefer use an online tool such as: http://www.guidgenerator.com/ the important thing to remember is that you need to generate a new GUID for each new Custom .NET Docker you create.
The following VBA code, creates the docker in the UI, and makes an entry for our Docker in the Windows | Dockers menu.
Code:
Sub addSelectionVB() Dim dockerAssembly As String dockerAssembly = "C:\Program Files\Corel\CorelDRAW Graphics Suite X6\Programs64\Addons\SM_Selection\SM_Selection_VB.dll" Call FrameWork.AddDocker("6139b731-672f-4131-88e4-3a30833b349d", "SM_Selection_VB.Docker", dockerAssembly) Call FrameWork.CommandBars("Dockers").Controls.AddToggleButton("6139b731-672f-4131-88e4-3a30833b349d", 0, False) End Sub
Conclusion
Congratulations you have just created your very first Custom WPF .NET Docker for CorelDRAW X6. As always if you have question feel free to ask them in the forums.
Coming up Next…
Adding a Custom Docker or Control via XSLT instead of VBA
Full Visual Studio 2010 Source Code
If you would like to look at the full source code, I am providing both C# and VB.NET examples.
SM_Selection_CSharp.zip
SM_Selection_VB.zip
Total Comments 3
Comments
-
Thanks!
This is awesome, quite a bit easier to do than in X5 once you get the hang of it.
Thanks, Shelby! I totally stole your example code and then modified it with very pleasant resultsPosted 15-05-2012 at 05:31 by Joe -
great post!
I was totally with you up until the point that you reference the vb code that adds the docker.
What do I do with that code?Posted 15-05-2014 at 15:42 by Keefster -
VBA Code
You need to run this code via VBA. (Alt-F11), I suggest making your own GMS file and add the code there, then run it. Keeps things nice and neat. :-)Posted 22-05-2014 at 11:48 by shelbym
Total Trackbacks 0