How to perform ctrl+a, ctrl+x, ctrl+n and ctrl+v sequentially?

Hello all,

I have created custom docker for x7(many many thanks to bonus630) for my company which basically brings spesific image or file related to its product code from database. After all operation is done what i would like to do is perform ctrl+a, ctrl+x, ctrl+n and ctrl+v sequentially within the code. What i tried at first was this.

1
2
3
4
5
6
7
public void selectCutNewPaste()
{
    corelApp.Application.FrameWork.Automation.InvokeItem("a604992c-e7a6-4a72-85c1-4fcf0ec8ff77"); //ctrl+a
    corelApp.Application.FrameWork.Automation.InvokeItem("0eb6f64d-af52-4f2d-aaa1-cb64429b0f3e"); //ctrl+x
    corelApp.Application.FrameWork.Automation.InvokeItem("fa65d0c1-879b-4ef5-9465-af09e00e91ab"); //ctrl+n
    corelApp.Application.FrameWork.Automation.InvokeItem("89088287-2340-4179-b719-017c956ba65d"); //ctrl+v
}

The problem is that code works if i assign every operation to different button and wait for those operation to be completed (i.e when i invoke ctrl+a it takes some time to select all objects in the document) What i prefer is do that four operation with one button. 

Thanks in advance.

Parents
No Data
Reply
  • I would like to suggest that before developing in C# ir is good to know/learn some VBA...

    You can use InvokeItem Automation also from VBA. But the main idea of what you try is to find a workable solution. Nothing not working in VBA will not work in your docker and this it is very easy to check. On the other hand, VBA works faster.

    The docker is necessary only if you want to hide your code, or to impress your boss. 

    But nevermind, a code sample to try in VBA, doing what you want, on the mechanism you suggested, will be the next:

    1
    2
    3
    4
    5
    Dim shR As ShapeRange
        Set shR = ActivePage.Shapes.All
        shR.CreateSelection
        shR.Copy
        ActiveDocument.Pages.First.ActiveLayer.Paste
    

    Line 3 can be omitted. I just tried to respect your scenario... But using Copy + Paste in Corel, it may produce crashes in case of big size shapes to be copied using this method (by code). I do not use it (anymore). I would suggest you to use native Corel Duplicate function:

    1
    2
    3
    4
    Dim shR As ShapeRange, sDupl As ShapeRange
        Set shR = ActivePage.Shapes.All
        Set sDupl = shR.Duplicate
           sDupl.MoveToLayer ActiveDocument.Pages.First.ActiveLayer
    

    Both code samples copies all shapes from the active page to the active layer of the first page. Of course, you can use both of them in C# translating this code, which is extremely easy:

    1
    2
    3
    4
    5
    6
    Dim shR As ShapeRange, sDupl As ShapeRange, CorelApp As Application
      Set CorelApp = Application
        Set shR = CorelApp.ActivePage.Shapes.All
        Set sDupl = shR.Duplicate
           sDupl.MoveToLayer CorelApp.ActiveDocument.Pages.First.ActiveLayer
           CorelApp.ActiveDocument.Pages.First.Activate
    

     You just forged about the first declaration lines, declare the variables as C# requests and finish the line with ; character.

    The method using duplicate takes much less time than the first one and consumes less resources...

Children
No Data