EEPerson

Is there any way to determine the color of a particular pixel on a System.Windows.Forms.Controls object

I am using a third party activex control to plot graphs. I am trying to make it so I can select points on the graph by clicking on them. However, the activex control has no implementation for this and gives me no methods that allow me to determine the location of the points on the graph.

The only way I can think of to get this to work is to determine if the color of the pixel in the spot I click matches the color that the activex control uses to draw the data points.

Thanks


Re: Windows Forms General Control Pixels

nobugz

It's possible but how would it be useful All you'd know is that a point was clicked, not which point.





Re: Windows Forms General Control Pixels

EEPerson

The graphing control lets me retrieve the coordinates of where I click but it is in terms of the graph coordinates. I know the coordinates of each point on the graph because I added them. Therefore I can simply go through all of the points and and see which one is closest to where I clicked. However, the graphing control doesn't give me a way to know if a point was actually clicked on.




Re: Windows Forms General Control Pixels

nobugz

Can't you just do a "shortest distance" calculation from the mouse coordinates and the list of points That also makes it a lot easier for the user to click without having to hunt a pixel.





Re: Windows Forms General Control Pixels

EEPerson

The problem is I don't know how the graph is scaled. I don't know how close the points appear on the screen. I don't know the distance in pixels from where I clicked.

Say that I know that the place I clicked on the graph is 5 graph units from a particular data point. Depending on the how the graph is scaled that click could be 5 pixels from where that data point appears on the screen or it could be 1000. If it is 5 pixels then the user will think they clicked on the that data point. If it is 1000 then the user will be confused as to why that data point was selected.




Re: Windows Forms General Control Pixels

nobugz

That was my original point. How would knowing the color of the pixel under the cursor help you find out what point was clicked All you know that the user clicked one of the points, which particular one is left to be determined. Sorry if this sounds argumentative, I just trying to come up with a realistic algorithm.





Re: Windows Forms General Control Pixels

EEPerson

I guesss I should have been clearer in my second post. I know your just trying to make sure I'm not wasting my energy on a pointless solution.

I can find the distance from where I clicked to to any given data point in graph units not pixels. I can use that to tell which data point my click was closest to.

I just need pixel color to determine if any point, as it is displayed on the screen, was clicked on.

psuedocode:

Click_Event
{
get pixel color;
if(pixel color matches that of a data point)
{
calculate graph distance from click to all of the data points;

set point clicked on to data point with shortest graph distance;
}
}