views:

85

answers:

3

Hi,

I am doing some image sampling. What my question is, is there a 'crosshair' tool in visual studio? I want to have several instances on a single form, be able to move them around and then sample those points, obviously returning the color of the pixel at the center of the crosshair, is there already a tool that will do this, before I go and write one?

Thanks, R.

+1  A: 

I know of no crosshair, but the following procedure can be used twice to draw a crosshair. To remove it, simply draw it again as it uses XOR to make the procedure reversible.

ControlPaint.DrawReversibleLine().

Paul Ruane
How is this relevant to the question?
Alastair Pitts
Sorry, thought it was obvious. I have updated the answer to clarify how it is useful.
Paul Ruane
+1  A: 

You could just change the cursor:

    private void btnSample_Click(object sender, EventArgs e) {
        this.Cursor = Cursors.Cross;
    }
    protected override void OnMouseDown(MouseEventArgs e) {
        if (this.Cursor == Cursors.Cross) {
            this.Cursor = Cursors.Default;
            // etc...
        }
    }
Hans Passant
I thought he wanted to leave multple "sample marks" in the shape of a crosshair on the image. But I may be wrong.
Charlie boy
No, Charlie you are right, I don't simple want to change the pointer, I was wondering if there was a tool that I could use to mark a point on an image, which is itself loaded into a form.
flavour404
Well sure, implement the Paint event to draw it. Moving it is however very expensive, you have to keep redrawing the image as the mouse moves. You are not stuck with Cursors.Cross, VS has a cursor editing tool to make your own.
Hans Passant
Yes but as interpit the question, he doesn't want to move all the markers at every mouse move. Just paint out the markers on click, then be able to move each marker (that, however is another question). In short, no there is no such tool.
Charlie boy
A: 

I would change the cursor to Cursor.cross. Then just paint indicators at the mousedown-points with GDI on the PictureBox's Graphic, sample the colors from those locations and then clear the PictureBox's Graphic when the operation is done.

Charlie boy