Click here to Skip to main content
15,670,415 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi All,

First timer questions so my apologies if they are a bit vague or in the wrong area.

I am writing a program that interfaces to some real world electronics and would like to represent the items graphically via PictureBox. Drawing the items is no problem, however I would like the Item to change colour for a change of state. eg if a Valve is off/on it may be red/green and the corresponding pipe may change colour also.

My problem is that once the item is drawn there appears no way to change it other than redawing the object. Can the object be 'tagged' in some way to contain some attributes that could then be changed?

I have thought of interfacing to something like MS Visio but would prefer to be able to package the whole solution in one package. I am using Visual Basic 2010.


The simple answer is "no".

The image in a PictureBox is in essence a Bitmap - which means it is just a sequence of individual pixels which have no relation to each other. You can't tag them to say "these are together, change them all to green" because the image does not contain any information which relates pixels to each other.

If you are using Winforms, then I would suggest that instead of a PictureBox, you use a Panel and handle it's Paint event. You can then get each object (such as a valve) to draw itself when it changes state.
Share this answer
Ok. Thank-you for the reply. I sort of expected this to be the case. I will look down another avenue now.

Share this answer

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900