|
dev
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Two-layered image controlI 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. -- Show quoteHide quoteBryan Phillips MCSD, MCDBA, MCSE Blog: http://bphillips76.spaces.live.com Web Site: http://www.composablesystems.net "Massimo" <bar***@mclink.it> wrote in message news:uufkgPTgHHA.392@TK2MSFTNGP06.phx.gbl: > 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 "Bryan Phillips" <bphillips@nospam.spamcop.net.spammenot> ha scritto nel Ok, thanks for your help.messaggio news:uJYxj4UgHHA.4156@TK2MSFTNGP02.phx.gbl... > 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. 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. I would try subclassing the PictureBox first and if that does not work out, subclass the Control class instead. -- Show quoteHide quoteBryan Phillips MCSD, MCDBA, MCSE Blog: http://bphillips76.spaces.live.com Web Site: http://www.composablesystems.net "Massimo" <bar***@mclink.it> wrote in message news:eUY4aTVgHHA.4708@TK2MSFTNGP04.phx.gbl: > "Bryan Phillips" <bphillips@nospam.spamcop.net.spammenot> ha scritto nel > messaggio news:uJYxj4UgHHA.4156@TK2MSFTNGP02.phx.gbl... > > > 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 "Bryan Phillips" <bphillips@nospam.spamcop.net.spammenot> ha scritto nel Yes, that's true. I tried starting a project with that, and it gets the messaggio news:ua2EXPcgHHA.3412@TK2MSFTNGP02.phx.gbl... > 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. whole infrastructure for adding internal controls. > I would try subclassing the PictureBox first and if that does not work Ok, I'l give it a try.> out, subclass the Control class instead. Thanks. Massimo
Other interesting topics
Databind a nullable date to a masked textbox
This code compiles/runs but breaks designer... Adding an event handler to a dynamically populated control Datagridview help ClickOnce Deployment in a Plug-in architecture context Generated Program.cs uses special way of disposing native resource Login window vs Main window Newbie question: how to set focus to a usercontrol How to read Default Values from App.Config for User Settings? print the current time on the screen |
|||||||||||||||||||||||