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();

    }

thank you tinstaafle,i worked perfectly:)

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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.