Custom .NET Controls in CorelDRAW X6
Introduction
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:
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:
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:
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.
SM_LineWidth_CSharp.zip
SM_LineWidth_VB.zip
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:
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
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:
Code:
Sub addLineWidthControl() Dim controlAssembly As String controlAssembly = "C:\Program Files\Corel\CorelDRAW Graphics Suite X6\Programs64\Addons\SM_LineWidth\SM_LineWidth_CSharp.dll" ' Add custom slider control Call FrameWork.CommandBars("Standard").Controls.AddCustomControl("SM_LineWidth_CSharp.MySlider", controlAssembly) End Sub
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.
SM_LineWidth_CSharp.zip
SM_LineWidth_VB.zip
Total Comments 4
Comments
-
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:
Custom add-ons and dockers in CorelDRAW
-ShelbyPosted 22-10-2012 at 00:32 by shelbym -
Posted 26-02-2014 at 02:06 by olympiatr -
Posted 27-03-2014 at 23:56 by shelbym
Total Trackbacks 0