Posted by Catur Nugroho | File under :

Autoit Control Get Pos (x) (y) Using C#

Retrieves the position and size of a control relative to its window.
ControlGetPos ( "title", "text", controlID )

Parameters

title The title of the window to access.
text The text of the window to access.
controlID The control to interact with. See Controls.

Return Value

Success: Returns an array containing the size and the control's position relative to its client window:

$array[0] = X position

$array[1] = Y position

$array[2] = Width

$array[3] = Height
Failure: Sets @error to 1.

Remarks

The title/text is referencing the parent window, so be careful with "","" which references the active window which may not be the one containing the controlID control.

Source : Autoit Help Document

Source Code Autoit Control Get Pos (x) (y) In C#


Parameters Required :
Title : [CLASS:Notepad]
Text : ""
Control : Edit1

private void controlGetPosXYButton_Click(object sender, EventArgs e)
        {
            //open notepad program
            autoit.Run("notepad.exe", "", 1);

            //wait notepad opened until 10 seconds
            autoit.WinWait("[CLASS:Notepad]", "", 10);

            //get x position
            int iReturnGetPosX = autoit.ControlGetPosX("[CLASS:Notepad]", "", "Edit1");

            //get y position
            int iReturnGetPosY = autoit.ControlGetPosY("[CLASS:Notepad]", "", "Edit1");

            returnGetPosLabel.Text = "Autoit get control pos (x) : " + iReturnGetPosX.ToString() + "\n";
            returnGetPosLabel.Text += "Autoit get control pos (y) : " + iReturnGetPosY.ToString() + "\n";
        }


Download Full Source Code

0 comments:

Post a Comment