OberonPlace.com Forums  

Go Back   OberonPlace.com Forums > Blogs > shelbym

Rating: 17 votes, 5.00 average.

Custom .NET Controls in CorelDRAW X6

Posted 25-03-2012 at 22:24 by shelbym
Updated 26-03-2012 at 11:42 by shelbym
Tags .net, vba, wpf

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.
Name:  NewProject.PNG
Views: 38592
Size:  97.7 KB

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\Assemblies
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:
Name:  XAML.PNG
Views: 35997
Size:  13.2 KB
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:
Name:  CSharp.PNG
Views: 36083
Size:  26.0 KB
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
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.
Name:  Slider.png
Views: 35292
Size:  23.1 KB

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
Posted in VBA
Views 104424 Comments 4
« Prev     Main     Next »
Total Comments 4

Comments

  1. Old Comment

    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 12:37 by Steven E
  2. Old Comment
    shelbym's Avatar

    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

    -Shelby
    Posted 22-10-2012 at 00:32 by shelbym shelbym is offline
  3. Old Comment
    olympiatr's Avatar

    links

    links broken (
    Posted 26-02-2014 at 02:06 by olympiatr olympiatr is offline
  4. Old Comment
    shelbym's Avatar

    Links

    I have correct all broken links. Everything should be working now.
    Posted 27-03-2014 at 23:56 by shelbym shelbym is offline
 
Total Trackbacks 0

Trackbacks


All times are GMT -5. The time now is 21:24.


Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2023, Jelsoft Enterprises Ltd.
Copyright © 2011, Oberonplace.com