In my C# winforms application I need to draw blocks. These blocks are so called process blocks. All the blocks together are a process. There are different kinds of process blocks. At this moment I have three kinds of process blocks: A, B, C. When I draw a process block it looks like this:
A
B
B
C
A
Every block has it’s own backgroundcolor. And every block has it’s own properties. For example: process block A and B both has the same properties (ID and description). The difference is the background color of the block.
I already have created a user control. This user control is a process block. I already have a picturebox where I add the user control (process blocks) to the controls collection. This works fine. The point is that I don’t know how to link a process block of type A, B, C to the user control. I also have a propertygrid. When a processblock is clicked I want to display it’s property values.
I don’t know exactly how to implement this. I hope you can point me at the right direction.
I would see the UserControl that you’ve created as a ‘visualizer’ of a
ProcessBlockinstance.So, what I would do -given the information you’ve given-, is create an abstract class (or interface, it depends) ‘
ProcessBlock‘, which has some abstract methods likeGetDrawingColor.For every concrete
ProcessBlock, you create a new class which inherits from the abstract class (or interface).So, then you could have ‘ProcessBlockA’, ‘ProcessBlockB’, and ‘ProcessBlockC’ which inherit from the ProcessBlock base class.
In each concrete subclass, you override the the
GetDrawingColormethod, so that it returns theColorthat you want to have.Then , you pass an instance of a ProcessBlock to the UserControl, and the UserControls calls the
GetDrawingColormethod, and it uses the result in order to paint it’s background.For instance: