Two-layered image control

  • Thread starter Thread starter Massimo
  • Start date Start date
M

Massimo

Hi to all.

I need to create a custom control which does the following:


- It should contain a first, fixed image.
- It should manage a second image, which will change programmatically.
- It should display the second image on top of the first one, updating it in
response to user events; the second image will of course have a transparent
background.
- The second image should be accessible outside the control, and wil be used
for printing on some paper forms which are, as you probably guessed, the
same as the first image; this is the reason for having two separate images.


I'm trying to develop this, but I'm quite confused about the various
System.Drawing classes and which Windows Forms control is the best to use as
my control's base class. I don't thoroughly understand the process of
painting a control, and the relationships between an Image, a Drawing object
and the control.

My initial guess was to use a PictureBox, set its BackGroundImage property
to the fixed image and use the Image property for my drawing... but I don't
know how to do manual drawing this way.

Is this a good approach, or there is a better one?

Also, I know very little about printing with Windows Forms. What do I need
for printing? An Image? A Graphics object? What else?

Can someone please help?


Thanks


Massimo
 
Use the PrintDocument class to print from Windows Forms.

If you use the Image property for your drawing, create a variable with a
data type of one of the Image subclasses (like Bitmap). Then, pass that
variable to the static method Graphics.FromImage() to get an instance of
the Graphics class.

Use the Graphics class's draw methods which will write their output to
the Image variable.
 
Use the PrintDocument class to print from Windows Forms.

If you use the Image property for your drawing, create a variable with a
data type of one of the Image subclasses (like Bitmap). Then, pass that
variable to the static method Graphics.FromImage() to get an instance of
the Graphics class.

Use the Graphics class's draw methods which will write their output to the
Image variable.

Ok, thanks for your help.

Do you think creating this control from a PictureBox base class and using
the BackGroundImage and Image properties can be a good strategy? Maybe it's
better to derive directly from Control (or UserControl, what's the
difference anyway?) and directly draw on the control's surface?


Massimo
 
Yes I think that is a good strategy. The difference between the Control
class and UserControl class is that the UserControl class is used to
create composite controls.

Yes, that's true. I tried starting a project with that, and it gets the
whole infrastructure for adding internal controls.
I would try subclassing the PictureBox first and if that does not work
out, subclass the Control class instead.

Ok, I'l give it a try.

Thanks.


Massimo
 
Back
Top