Windows Develop Bookmark and Share   
 index > Windows Forms General > Locate x and y co-ordinates of a control
 

Locate x and y co-ordinates of a control

I want to find a x and y co-ordinates of a control in different exe.

Here is what I am trying to do?

1) Find a window is running or not (custom app 1) I think I can use Process.GetProcessbyName method to do this

2) List all the controls in the form -- I am not sure how to do this

3) List x and y co-ordinates of the control -- I am not sure how to do this.

Please help

jijo12343  Thursday, August 23, 2007 12:33 PM

Here is a quick example for using Remoting to talk between 2 application:

1. Create a new project - "RemoteApplication".

1b. Add a refference to System.Runtime.Remoting

2. Double click on the form and add the following code:

private void Form1_Load(object sender, EventArgs e)

{

TcpServerChannel channel = new TcpServerChannel(8085);

ChannelServices.RegisterChannel(channel, false);

ObjRef SiteReference = RemotingServices.Marshal(this, "RemoteForm");

}

3. Change the Form.Text property to "This is the remote form".

4. Run the application (if the windows firewall ask something - click 'allow'\'don't block',etc.).

The form should appear.

5. Create a new project "ApplicationTalker".

6. Double click on the form and add the following code:

private void Form1_Load(object sender, EventArgs e)

{

if (ConnectToRemote())

this.Text = "I got '" + _remoteForm.Text + "' from the other app!";

}

private Form _remoteForm;

privatebool ConnectToRemote()

{

string Url = "tcp://localhost";

int Port = 8085;

string Name = "RemoteForm";

Url += ":" + Port + "/" + Name;

if (_remoteForm == null)

{

try

{

_remoteForm = (Form)Activator.GetObject(typeof(Form), Url);

}

catch (Exception ex)

{

System.Windows.Forms.MessageBox.Show(ex.Message);

return false;

}

}

return true;

}

7. Run the application - you should see the form text changed to "I got - 'This is the remote form' from the other app!".

8. This is it! by using the form, you can search for controls in it, get their properties, etc.

Eli Gazit  Thursday, August 23, 2007 1:09 PM

If you just want topass information from one application to the other once, use some file to save the relevant data.

If you want to 'talk' between the 2 apps, you might consider checking Remoting- this is a nice way to talk between 2 apps.

Eli Gazit  Thursday, August 23, 2007 12:43 PM

Here is a quick example for using Remoting to talk between 2 application:

1. Create a new project - "RemoteApplication".

1b. Add a refference to System.Runtime.Remoting

2. Double click on the form and add the following code:

private void Form1_Load(object sender, EventArgs e)

{

TcpServerChannel channel = new TcpServerChannel(8085);

ChannelServices.RegisterChannel(channel, false);

ObjRef SiteReference = RemotingServices.Marshal(this, "RemoteForm");

}

3. Change the Form.Text property to "This is the remote form".

4. Run the application (if the windows firewall ask something - click 'allow'\'don't block',etc.).

The form should appear.

5. Create a new project "ApplicationTalker".

6. Double click on the form and add the following code:

private void Form1_Load(object sender, EventArgs e)

{

if (ConnectToRemote())

this.Text = "I got '" + _remoteForm.Text + "' from the other app!";

}

private Form _remoteForm;

privatebool ConnectToRemote()

{

string Url = "tcp://localhost";

int Port = 8085;

string Name = "RemoteForm";

Url += ":" + Port + "/" + Name;

if (_remoteForm == null)

{

try

{

_remoteForm = (Form)Activator.GetObject(typeof(Form), Url);

}

catch (Exception ex)

{

System.Windows.Forms.MessageBox.Show(ex.Message);

return false;

}

}

return true;

}

7. Run the application - you should see the form text changed to "I got - 'This is the remote form' from the other app!".

8. This is it! by using the form, you can search for controls in it, get their properties, etc.

Eli Gazit  Thursday, August 23, 2007 1:09 PM

You can use google to search for other answers

Custom Search

More Threads

• TabControl Flicker Issue
• How does dataGridView know form loaded ?
• how to link particular words in TextBox
• how to share memory variable within two forms?
• System.NullReferenceException: Object reference not set to an instance of an object.
• where to put initialization code in Winforms app.
• selcting tabs on forms using radio buttons
• Fill a rectangle without drawing border?
• Slow re-draw of screen with background bitmap
• Open/ Save/ Print?