c# - Create a custom control in Corel Draw X6 using only VSTA -
i in process of creating plugin (or addin) coreldraw x6 using vsta (visual studio applications) because c# , .net library. have button in coreldraw toolbar, when user clicks button action happens, example, form showed. use predefined solution vstaglobal, there me when start coreldraw. unfortunately, there no official documentation (wtf!!!!!) vsta in coreldraw, instead have vba (visual basic applications) documentation , coreldraw object model. googled lot , found few links: some forum post , youtube video tutorial. problem is, both guys there create customcontrol (a buton example) , build *.dll , use vba script add customcontrol coreldraw toolbar this
sub addlinewidthcontrol() call framework.commandbars("standard").controls. ' addcustomcontrol("mynamespace.mycustomcontrolclass", ' "mycustomcontrolassembly.dll") end sub
so, question is: is there way using vsta?
additional info:
for example, in default solution vstaglobal there main class [cgsaddinmodule] attribute:
[cgsaddinmodule] public partial class main { private corel.interop.vgcore.application app; // other code here... }
this class has constructor (note, default , provided coreldraw):
[cgsaddinconstructor] public main(object _app) // constructor gets instance // of coreldraw application object. { app = _app corel.interop.vgcore.application; // work if add code here? }
maybe place should add this:
app.framework.commandbars["standard"] .controls.addcustomcontrol("mycustomcontrolclass");
i did experiments last line of code. obtained count of controls increasing, still mycustomcontrol not show in toolbar.
there way use c# (i tested in corel x8 should work in version has vsta). 2 part process though. first need open macro manager in corel , edit vstaglobal solution. example, if want add button , slider, add 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 add code, need add .dll solution folder listed above. open visual studio 2015 , create new project (mine named coredrawpoc). needs wpf user control library project. create 2 .xaml files with. first 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 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 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 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 done, want compile code. also, want create image c:\corelicons\two.bmp. 24x24 bitmap looks want look. compile project. need coreldraw closed.
once compiles successfully, want go , run vsta macro add button , slider. macro need run 1 time! after than, connect directly code in dll. if change in dll , update while corel closed, changes it. includes images.
finally, learned how 2 blog posts , changed add button standard command bar , use purely c#. posts are:
Comments
Post a Comment