Windows Develop Bookmark and Share   
 index > Windows Forms General > Control Pixels
 

Control Pixels

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
EEPerson  Monday, September 24, 2007 11:58 PM
It's possible but how would it be useful? All you'd know is that a point was clicked, not which point.
nobugz  Tuesday, September 25, 2007 1:23 AM
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.
EEPerson  Tuesday, September 25, 2007 5:04 PM
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.
nobugz  Tuesday, September 25, 2007 5:11 PM
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.
EEPerson  Tuesday, September 25, 2007 5:32 PM
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.
nobugz  Tuesday, September 25, 2007 5:47 PM
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;
}
}
EEPerson  Tuesday, September 25, 2007 5:59 PM

You can use google to search for other answers

Custom Search

More Threads

• ListView capacity?
• Help stored in database, not file - how can HelpProvider be leveraged?
• Drag and Drop with Tree component
• KeyHandling...
• Add Pictures to Excel from dyanmically retrieve Byte[] image
• Windows XP Home and Windows Professional
• how to customise file open/save dialog box
• How to hide controls using a loop
• Any situations where the NotifyIcon.ShowBalloonTip(...) WONT actually show the balloon?
• the background colore is black , why