ALIGNING OBJECTS TO WINDOW OR TO SCREEN

Hello,

Object-to-object or page-to-page alignment is a standard option. I need a method / VBA code to align the object to the screen or window. Is it possible?
I have an idea to use Desktop object but I don't know how.

 

Greetings!

  • Not sure what you mean by screen or window? Do you mean align to page center (Keystroke p)?

  • I dont know if works in X5

    [CgsAddInMacro]
    public void AlignByScreen()
    {
     
        double leftX = 0;
        double bottomY = 0;
        corelApp.ActiveWindow.ScreenToDocument(corelApp.ActiveWindow.Left, corelApp.ActiveWindow.Top + corelApp.ActiveWindow.Height, out leftX, out bottomY);
        corelApp.ActiveShape.BottomY = bottomY;
        corelApp.ActiveShape.LeftX = leftX;
    }

    Converted ti VBA by ChatGPT, 

    Dim leftX As Double
    Dim bottomY As Double

    ' Convert screen coordinates to document coordinates
    ActiveWindow.ScreenToDocument ActiveWindow.Left, ActiveWindow.Top + ActiveWindow.Height, leftX, bottomY

    ' Set the BottomY and LeftX properties of the active shape
    ActiveShape.BottomY = bottomY
    ActiveShape.LeftX = leftX

    This is interesting for doing things like this