i am using the following code

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace GIS_assignment
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();

        }
        private void Form1_Load(object sender, EventArgs e)
        {

        }
          private void pictureBox1_Click(object sender, EventArgs e)
        {
            //this.PointToClient(Cursor.Position);
            int x = Cursor.Position.X , y = Cursor.Position.Y;
            label1.Text = x.ToString();
            label2.Text = y.ToString();
        }
    }
}

but the problem is that is taking screen coordinates not the picturebox.But i want coordinates of picturebox not the screen,
please help.
thank you

If you handle the MouseClick event, e.Location will give you the location within the pictureBox:

    private void pictureBox1_MouseClick(object sender, MouseEventArgs e)
    {
        int x = e.Location.X , y = e.Location.Y;
        label1.Text = x.ToString();
        label2.Text = y.ToString();

    }

Edited 3 Years Ago by tinstaafl

Try this:

private void pictureBox1_Click(object sender, EventArgs e)
        {
            Point PictPoint = new Point();
            PictPoint = PointToClient(Cursor.Position);

            label1.Text = PictPoint.X.ToString();
            label2.Text = PictPoint.Y.ToString();
        }

If the upper left corner of your picture has to be 0,0, substract the picture location also.

This question has already been answered. Start a new discussion instead.