Custom .NET Controls in CorelDRAW X6

With CorelDRAW X6 you can now create custom .NET controls that can be hosted in either a custom docker or the UI itself, including toolbars and menus. I will be doing a few posts on exactly how this is done. For this post we will build our own slider control that will change the line width of the selected shapes.

WPF User Control Library

I will be using Visual Studio 2010 Professional to create the custom control. Start a new project, Visual C#, WPF User Control Library.

Rename the UserControl1.xaml to MySlider.xaml and Refactor | Rename the UserControl1 class to MySlider. Next we need to add references to the CorelDRAW interop assemblies. For the 64-bit version they are located:

You 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

Click on MySlider.xaml to show the XAML. Remove the width and height, as well as the grid and then add a slider control from the toolbox. In the properties docker rename slider1 to mySlider, set the Mininum to .5, Maximum to 10, TickFrequency of .5, and check IsSnapToTickEnabled. Click the Events tab and double click the ValueChanged to generate the event in code. Your XAML should look similar to this:

CSharp

Going to keep the code pretty simple, we just need to link our control to CorelDRAW and then add the code for when the slider value changes. SetOutlineProperties wants its value in inches, so we will take the value of the slider and convert it to inches with the ConvertUnits function. When you are done your code should look similar to 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 Control

To add the custom control to the UI I am going to use VBA. My VBA code looks like this:

Run the VBA code, and the new slider should be added to the end of the standard toolbar. Draw a couple of shapes, select them and drag the slider to see what happens. If we have done things correctly the outlines of the shapes to change as you move the slider.

Conclusion

We created our very first WPF custom control for CorelDRAW X6, how very cool is that. If you have questions please post to the forum, this opens up so many new opportunities for coders, I cannot wait to see what awesome things you come up with.

Coming up Next…

Custom .NET Docker Example

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.

Comments

Two questions

1. Can I do this in X5, using the built in VSTA editor and not Visual Studio 2010, which I don't have ?

2. If I can and change the VBA to install the slider into the "standard" bar with my names and location IE: (X86) is this a GMS file that I just run from the VBA editor once or is it then a "macro" that I need to have run automatically when CorelDraw starts? (put it in the Global file?)

Just saw your new blog entry, I'll dig through it to see if I find some of my answers there. Thanks
Steve E.

Posted 21-10-2012 at 13:37 by Steven E

X5 Dockers

Steven,

No this is new to X6, you will not be able to do this for X5. However, if you want to create a custom docker that would work X4 - X6 you can use the older way here: