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:
[CgsAddInMacro]
public void Add()
{
string controlAssembly = @"C:\VSTS\ScratchProjects\CoreDrawPoC\CoreDrawPoC\bin\Debug\CoreDrawPoC.dll";
var mySlider = app.FrameWork.CommandBars["Standard"].Controls.AddCustomControl("CoreDrawPoC.MySlider", controlAssembly);
mySlider.Caption = "Border Sizing Slider Caption";
mySlider.ToolTipText = "Border Sizing Slider Tooltip";
var myButton = app.FrameWork.CommandBars["Standard"].Controls.AddCustomControl("CoreDrawPoC.ButtonSample", controlAssembly);
myButton.Caption = "Rectanlge Selector";
mySlider.ToolTipText = "Rectanlge Selector Tooltip";
}
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:
<UserControl x:Class="CoreDrawPoC.MySlider"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:CoreDrawPoC"
mc:Ignorable="d" >
<Slider x:Name="mySlider" Width="100" Minimum=".5" Maximum="10" TickFrequency=".5" IsSnapToTickEnabled="True" ValueChanged="mySlider_ValueChanged"/>
</UserControl>
Code behind is:
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
namespace CoreDrawPoC
{
/// <summary>
/// Interaction logic for UserControl1.xaml
/// </summary>
public partial class MySlider : UserControl
{
Corel.Interop.VGCore.Application appDraw = null;
public MySlider()
{
InitializeComponent();
}
public MySlider(object app)
{
InitializeComponent();
appDraw = (Corel.Interop.VGCore.Application)app;
}
private void mySlider_ValueChanged(object sender, RoutedPropertyChangedEventArgs<double> e)
{
if (appDraw != null && appDraw.ActiveDocument != null && appDraw.ActiveShape != null)
{
double width = appDraw.ConvertUnits((double)e.NewValue, Corel.Interop.VGCore.cdrUnit.cdrPoint, Corel.Interop.VGCore.cdrUnit.cdrInch);
appDraw.ActiveSelectionRange.SetOutlineProperties(width);
}
}
}
}
Then create the button:
<UserControl x:Class="CoreDrawPoC.ButtonSample"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:CoreDrawPoC"
mc:Ignorable="d">
<Button x:Name="buttonSample" Click="buttonSample_Click" Width="24" Height="24" >
<Button.Template>
<ControlTemplate>
<Image Source="C:\CorelIcons\Two.bmp"/>
</ControlTemplate>
</Button.Template>
</Button>
</UserControl>
Code behind:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
namespace CoreDrawPoC
{
/// <summary>
/// Interaction logic for ButtonSample.xaml
/// </summary>
public partial class ButtonSample : UserControl
{
Corel.Interop.VGCore.Application appDraw = null;
public ButtonSample()
{
InitializeComponent();
}
public ButtonSample(object app)
{
InitializeComponent();
appDraw = (Corel.Interop.VGCore.Application)app;
}
private void buttonSample_Click(object sender, RoutedEventArgs e)
{
SelectOfType("rectangle");
}
private void SelectOfType(string strType)
{
string strQuery = null;
Corel.Interop.VGCore.ShapeRange srGroup = default(Corel.Interop.VGCore.ShapeRange);
Corel.Interop.VGCore.ShapeRange srTopOnly = default(Corel.Interop.VGCore.ShapeRange);
strQuery = "@type='" + strType + "'";
srGroup = appDraw.ActivePage.Shapes.FindShapes("", 0, true, strQuery);
srTopOnly = appDraw.ActivePage.Shapes.FindShapes("", 0, false, strQuery);
srTopOnly.CreateSelection();
appDraw.ActivePage.Shapes.FindShapes("", 0, false, strQuery).CreateSelection();
//if (srTopOnly.Count == srGroup.Count)
//{
// lblWarning.Visibility = System.Windows.Visibility.Hidden;
//}
//else
//{
// lblWarning.Visibility = System.Windows.Visibility.Visible;
//}
}
}
}
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: