Skip to main content

Specifying the X and Y coordinates in Windows Form

  • July 12, 2019
  • 2 replies
  • 0 views

Alexander Castro

I am trying to specify the X and Y coordinates on my form and though I realize I can do this on the form’s property’s window, I would like to be able to do this in the program. I have the following code when the form loads:

       method-id Form1_Load final private.

       procedure division using by value sender as object e as type System.EventArgs.

 

         set self::Location::X to '690'.

         set self::Location::Y to '255'.

 

       end method.

 

This does not appear to work and I do not know why. The X and Y coordinates get reverted to some kind of default value. And this happens even if I specify the coordinates in the property’s window.  

2 replies

Chris Glazier
Forum|alt.badge.img+2

I am trying to specify the X and Y coordinates on my form and though I realize I can do this on the form’s property’s window, I would like to be able to do this in the program. I have the following code when the form loads:

       method-id Form1_Load final private.

       procedure division using by value sender as object e as type System.EventArgs.

 

         set self::Location::X to '690'.

         set self::Location::Y to '255'.

 

       end method.

 

This does not appear to work and I do not know why. The X and Y coordinates get reverted to some kind of default value. And this happens even if I specify the coordinates in the property’s window.  

You also need to change the FormStartPosition property to manual or else it will use the WindowsDefaultPosition which is what you are experiencing.

        set self::StartPosition to type FormStartPosition::Manual 

Please see the article here:

 

 


Alexander Castro
  • Author
  • Participating Frequently
  • July 13, 2019

You also need to change the FormStartPosition property to manual or else it will use the WindowsDefaultPosition which is what you are experiencing.

        set self::StartPosition to type FormStartPosition::Manual 

Please see the article here:

 

 

Thank you, that worked! However, it does not work when I put the code in the form load method. I had to put it in the method-id NEW:

method-id NEW.
procedure division.


invoke self::InitializeComponent
set self::Location::X to 690.
set self::Location::Y to 255.
set self::StartPosition to type FormStartPosition::Manual

goback.
end method.

 

And thank you for the resource! I often first resort to the Microsoft knowledge base for questions regarding Windows forms. Unfortunately, I never find in their knowledge base the syntax for managed COBOL and hence why I post the question on this forum. Thanks again!