|
code
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
contents of picturebox contents get wiped out ...Dear All,
I am using Picture1.Print and Picture1.PaintPicture commands to add texts and images to Picture1 control at run time. But when a message box pops up over the picture1 or if I drag a form over the picture1 control, the texts and images in the picturebox (which are behind the message box or the form) will disappear. How can I prevent this problem? Thanks very much for your comments in advance. DORI "DORI" <D***@discussions.microsoft.com> wrote There are basically two methods to show graphics on a form.> Dear All, > I am using Picture1.Print and Picture1.PaintPicture commands to add texts > and images to Picture1 control at run time. But when a message box pops up > over the picture1 or if I drag a form over the picture1 control, the texts > and images in the picturebox (which are behind the message box or the form) > will disappear. How can I prevent this problem? > Thanks very much for your comments in advance. First, using the Paint event of the form and constituent controls, you draw whatever graphics are required each time the Paint event fires. Second, you set AutoRedraw to True for the form and constituent controls so that you only need to draw the graphics once and let Window repaint the form (or control) as needed. When you have AutoRedraw off, your graphics commands are sent directly to the form or control's screen image. When you have AutoRedraw on, the graphic commands are sent to an off-screen buffer which must then be copied (Refresh) to the on-screen image. The simple solution is to set AutoRedraw, see if that will fix it for you.... LFS "Larry Serflaten" <serfla***@usinternet.com> wrote in message It should be noted that setting Autoredraw is quite inefficient in terms of news:OTfEO58LIHA.2208@TK2MSFTNGP06.phx.gbl... > When you have AutoRedraw off, your graphics commands are sent directly > to the form or control's screen image. When you have AutoRedraw on, the > graphic commands are sent to an off-screen buffer which must then be > copied (Refresh) to the on-screen image. > > The simple solution is to set AutoRedraw, see if that will fix it for > you.... memory usage. If possible you should avoid its use, although in the OP's case it sounds like it might be appropriate. Michael > It should be noted that setting Autoredraw is quite inefficient in terms of Thanks for your comments. How would it affect the efficiency?> memory usage. Hi Michael, DORI Show quote "Michael C" wrote: > "Larry Serflaten" <serfla***@usinternet.com> wrote in message > news:OTfEO58LIHA.2208@TK2MSFTNGP06.phx.gbl... > > When you have AutoRedraw off, your graphics commands are sent directly > > to the form or control's screen image. When you have AutoRedraw on, the > > graphic commands are sent to an off-screen buffer which must then be > > copied (Refresh) to the on-screen image. > > > > The simple solution is to set AutoRedraw, see if that will fix it for > > you.... > > It should be noted that setting Autoredraw is quite inefficient in terms of > memory usage. If possible you should avoid its use, although in the OP's > case it sounds like it might be appropriate. > > Michael > > > "DORI" <D***@discussions.microsoft.com> wrote in message With Autoredraw on, VB uses an off screen bitmap to store an image of your news:1F0C47B5-6963-4128-8838-C09906234F5E@microsoft.com... >> It should be noted that setting Autoredraw is quite inefficient in terms of >> memory usage. > Hi Michael, > Thanks for your comments. How would it affect the efficiency? > DORI > picturebox, and uses the bitmap to redraw the picturebox when needed. If you had an elaborate graphic that you had drawn yourself, such as a pie chart with labels, it would be more efficent for you to simply redraw the graphic elements in the picturebox paint event, rather than make VB store a complete bitmap of the chart. It also makes sense to paint it yourself if the content is changing frequently. However, if you are using images within the picturebox, it doesn't make much difference whether you store them for repainting, or VB does it, especially if you are not changing the content frequently. Autoredraw is also often used to produce smoother graphic changes, since the buffering of the image will reduce flicker. Even .Net, Michael's favorite platform, uses double buffering on many forms to reduce flicker when image content is changing rapidly. Unless you are seeing really large amounts of memory being used for big image files, or are trying to achieve optimum speed in graphical updating, such as in a game, I would not worry about it, and use Autoredraw whenever you find you need it. Hi Steve,
Thanks for providing such a detailed information. I have a much better undertanding of what AutoRedraw does. My images are not very large and I have not noticed any negative impact on using AutoRedraw, so I am going to use it. Thanks again, DORI Show quote "Steve Gerrard" wrote: > > "DORI" <D***@discussions.microsoft.com> wrote in message > news:1F0C47B5-6963-4128-8838-C09906234F5E@microsoft.com... > >> It should be noted that setting Autoredraw is quite inefficient in terms of > >> memory usage. > > Hi Michael, > > Thanks for your comments. How would it affect the efficiency? > > DORI > > > > With Autoredraw on, VB uses an off screen bitmap to store an image of your > picturebox, and uses the bitmap to redraw the picturebox when needed. > > If you had an elaborate graphic that you had drawn yourself, such as a pie chart > with labels, it would be more efficent for you to simply redraw the graphic > elements in the picturebox paint event, rather than make VB store a complete > bitmap of the chart. It also makes sense to paint it yourself if the content is > changing frequently. > > However, if you are using images within the picturebox, it doesn't make much > difference whether you store them for repainting, or VB does it, especially if > you are not changing the content frequently. > > Autoredraw is also often used to produce smoother graphic changes, since the > buffering of the image will reduce flicker. Even .Net, Michael's favorite > platform, uses double buffering on many forms to reduce flicker when image > content is changing rapidly. > > Unless you are seeing really large amounts of memory being used for big image > files, or are trying to achieve optimum speed in graphical updating, such as in > a game, I would not worry about it, and use Autoredraw whenever you find you > need it. > > > "DORI" <D***@discussions.microsoft.com> wrote in message No, you won't notice any negative impact. The little extra memory used will news:0980EAB1-E100-4A7A-B9A6-445A93631AD2@microsoft.com... > My images are not very large and I have not noticed > any negative impact on using AutoRedraw, so I am > going to use it. Thanks again, be no problem at all. Autoredraw is fine. It is well thought out and well implemented and it does the job admirably. It does use a little extra memory of course, but then the various alternative methods use a little extra time. It's horses for courses. Autoredraw updates your Picture Box rapidly from a screen compatible memory bitmap and it redraws only those parts of the Picture Box that have become "dirty", so it is very time efficient. It is an extremely useful tool, and so simple to use. Mike
Show quote
"Steve Gerrard" <mynameh***@comcast.net> wrote in message That's not necessarily true. It's quite possible to create non buffered news:0uqdnUaK4u_h6tfanZ2dnUVZ_jSdnZ2d@comcast.com... > With Autoredraw on, VB uses an off screen bitmap to store an image of your > picturebox, and uses the bitmap to redraw the picturebox when needed. > > If you had an elaborate graphic that you had drawn yourself, such as a pie > chart with labels, it would be more efficent for you to simply redraw the > graphic elements in the picturebox paint event, rather than make VB store > a complete bitmap of the chart. It also makes sense to paint it yourself > if the content is changing frequently. > > However, if you are using images within the picturebox, it doesn't make > much difference whether you store them for repainting, or VB does it, > especially if you are not changing the content frequently. > > Autoredraw is also often used to produce smoother graphic changes, since > the buffering of the image will reduce flicker. graphics that are as smooth as buffered graphics if done properly. The reason non-buffered graphics look jumpy (eg acrobat reader) is because the programmers did it wrong. > Even .Net, Michael's favorite platform, uses double buffering on many That's true, it has quite good double buffering features which I have used > forms to reduce flicker when image content is changing rapidly. when all else failed. Michael "DORI" <D***@discussions.microsoft.com> wrote in message PicBox Autoredraw uses a backbuffer the same pixel size as the Picture Box news:1F0C47B5-6963-4128-8838-C09906234F5E@microsoft.com... > How would it affect the efficiency [memory usage]? at whatever colour depth your system is currently using, so that for example an Autoredraw 400 x 300 pixel Picture Box on a standard full colour system would use a bit less than half a meg more memory than a non Autoredraw Picture Box of the same size. Half a meg is almost nothing these days, especially when you compare it to the massive amount of memory gobbled up by most of the Microsoft stuff running in the background and especially by any dotnet stuff that might be installed and running. I wouldn't worry about half a meg, especially as it can save wasting quite a lot of processor time if the image in the box is complex and if it takes a long time to draw, unless you subclass the box and get your code to draw only into the "dirty rectangle", which in any case can take quite some time for a complex drawing. Personally I'd go for the straightforward Autoredraw solution and I wouldn't worry about the half a meg. Mike Hi Mike,
Thank you very much for the info re the AutoRedraw. DORI Show quote "Mike Williams" wrote: > "DORI" <D***@discussions.microsoft.com> wrote in message > news:1F0C47B5-6963-4128-8838-C09906234F5E@microsoft.com... > > > How would it affect the efficiency [memory usage]? > > PicBox Autoredraw uses a backbuffer the same pixel size as the Picture Box > at whatever colour depth your system is currently using, so that for example > an Autoredraw 400 x 300 pixel Picture Box on a standard full colour system > would use a bit less than half a meg more memory than a non Autoredraw > Picture Box of the same size. Half a meg is almost nothing these days, > especially when you compare it to the massive amount of memory gobbled up by > most of the Microsoft stuff running in the background and especially by any > dotnet stuff that might be installed and running. I wouldn't worry about > half a meg, especially as it can save wasting quite a lot of processor time > if the image in the box is complex and if it takes a long time to draw, > unless you subclass the box and get your code to draw only into the "dirty > rectangle", which in any case can take quite some time for a complex > drawing. Personally I'd go for the straightforward Autoredraw solution and I > wouldn't worry about the half a meg. > > Mike > > > "DORI" <D***@discussions.microsoft.com> wrote in message Bitmaps use a lot of memory and the bigger your picturebox gets the more news:1F0C47B5-6963-4128-8838-C09906234F5E@microsoft.com... > Hi Michael, > Thanks for your comments. How would it affect the efficiency? > DORI memory it uses. If your form is resizable then your picturebox could use 5MB at 1280x1024. If you then have a lot of programs using it those 5mbs add up. You'll get away with it in your program only because every other programmer did it properly and didn't use autoredraw. It really depends on what your doing and it is definately appropriate to use it in certain situations. It is worth pointing out that advising people to simply turn on autoredraw and forgot it is not the best advice. It's always good to understand what's going on. If everyone thinks we've got plenty of memory in machines these days so can do what we like then we end up with machines needing 10GB of ram just to boot. Michael Hi Michael,
Thanks for answering my question. DORI Show quote "Michael C" wrote: > "DORI" <D***@discussions.microsoft.com> wrote in message > news:1F0C47B5-6963-4128-8838-C09906234F5E@microsoft.com... > > Hi Michael, > > Thanks for your comments. How would it affect the efficiency? > > DORI > > Bitmaps use a lot of memory and the bigger your picturebox gets the more > memory it uses. If your form is resizable then your picturebox could use 5MB > at 1280x1024. If you then have a lot of programs using it those 5mbs add up. > You'll get away with it in your program only because every other programmer > did it properly and didn't use autoredraw. It really depends on what your > doing and it is definately appropriate to use it in certain situations. It > is worth pointing out that advising people to simply turn on autoredraw and > forgot it is not the best advice. It's always good to understand what's > going on. If everyone thinks we've got plenty of memory in machines these > days so can do what we like then we end up with machines needing 10GB of ram > just to boot. > > Michael > > >
Show quote
"Michael C" <mike@nospam.com> wrote in message I've had poor luck when not using Autoredraw, however. Perhaps I'm using thenews:%23KyGiI%23LIHA.748@TK2MSFTNGP04.phx.gbl... > "Larry Serflaten" <serfla***@usinternet.com> wrote in message > news:OTfEO58LIHA.2208@TK2MSFTNGP06.phx.gbl... > > When you have AutoRedraw off, your graphics commands are sent directly > > to the form or control's screen image. When you have AutoRedraw on, the > > graphic commands are sent to an off-screen buffer which must then be > > copied (Refresh) to the on-screen image. > > > > The simple solution is to set AutoRedraw, see if that will fix it for > > you.... > > It should be noted that setting Autoredraw is quite inefficient in terms of > memory usage. If possible you should avoid its use, although in the OP's > case it sounds like it might be appropriate. > wrong methods. I use hidden PictureBoxes for printing or copying to a visible one, and without Autoredraw, don't seem to get the desired image, if anything. Likewise, for visible PictureBoxes, drawing on them using PaintPicture and line/text commands, Autoredraw seems to be necessary. What other methods should I be using to eliminate this? -- Regards, Rick Raisley
Show quote
"Rick Raisley" <heavymetal-A-T-bellsouth-D-O-T-net> wrote If you are using a hidden picturebox as a build buffer or whatever, you> > > When you have AutoRedraw off, your graphics commands are sent directly > > > to the form or control's screen image. When you have AutoRedraw on, the > > > graphic commands are sent to an off-screen buffer which must then be > > > copied (Refresh) to the on-screen image. > > I've had poor luck when not using Autoredraw, however. Perhaps I'm using the > wrong methods. I use hidden PictureBoxes for printing or copying to a > visible one, and without Autoredraw, don't seem to get the desired image, if > anything. Likewise, for visible PictureBoxes, drawing on them using > PaintPicture and line/text commands, Autoredraw seems to be necessary. > > What other methods should I be using to eliminate this? will have to have its AutoRedraw turned on. A hidden control won't have the on screen image to draw to.... If you are only using a few drawing commands to show what needs to be shown, you could put those commands in the Paint event of the control (or form) you are drawing on, and not use AutoRedraw. Its a 'one or the other' type of trade off. When AutoRedraw is True, the Paint event of that control (or form) is not called, as it would be when AutoRedraw is False. Generally, doing your drawing in the Paint event is the better option. But in some instances, (compound or complex graphics) the draw once and forget nature of using AutoRedraw is fairly convenient. LFS "Larry Serflaten" <serfla***@usinternet.com> wrote in message The buffering action of the Autoredraw facility is more than merely news:%23LFgkpGMIHA.3852@TK2MSFTNGP06.phx.gbl... > Generally, doing your drawing in the Paint event is the better > option. But in some instances, (compound or complex graphics) > the draw once and forget nature of using AutoRedraw is fairly > convenient. "convenient". Buffering, and double buffering, has been the mainstay of all games programs for the last twenty or more years, and still is, because of the massive advantages it offers in those and other similar circumstances. Hardware frame buffering, where you merely "swap a pointer" is of course the preferred option today (and has been for many years now) but software buffering is still immensely useful. And if "professional" application programmers turn up their noses at "games programming" then they have an awful lot to learn ;-) Mike "Mike Williams" <mi***@whiskyandCoke.com> wrote in message No one is turning up their noses at the idea. It's just you should only use news:OkZZQuHMIHA.1204@TK2MSFTNGP03.phx.gbl... > The buffering action of the Autoredraw facility is more than merely > "convenient". Buffering, and double buffering, has been the mainstay of > all games programs for the last twenty or more years, and still is, > because of the massive advantages it offers in those and other similar > circumstances. Hardware frame buffering, where you merely "swap a pointer" > is of course the preferred option today (and has been for many years now) > but software buffering is still immensely useful. And if "professional" > application programmers turn up their noses at "games programming" then > they have an awful lot to learn ;-) it where appropriate. Every time this question comes up the answer is always "blindly turn on autoredraw and forgot it". This is really bad advice and other options should be looked at first. Michael Hi Larry,
Thanks for the explanation. I set the AutoRedraw to True and it solved the problem. Thanks again for taking time to provide a solution and explanation. DORI Show quote "Larry Serflaten" wrote: > > "DORI" <D***@discussions.microsoft.com> wrote > > Dear All, > > I am using Picture1.Print and Picture1.PaintPicture commands to add texts > > and images to Picture1 control at run time. But when a message box pops up > > over the picture1 or if I drag a form over the picture1 control, the texts > > and images in the picturebox (which are behind the message box or the form) > > will disappear. How can I prevent this problem? > > Thanks very much for your comments in advance. > > There are basically two methods to show graphics on a form. > > First, using the Paint event of the form and constituent controls, you draw > whatever graphics are required each time the Paint event fires. > > Second, you set AutoRedraw to True for the form and constituent controls > so that you only need to draw the graphics once and let Window repaint > the form (or control) as needed. > > When you have AutoRedraw off, your graphics commands are sent directly > to the form or control's screen image. When you have AutoRedraw on, the > graphic commands are sent to an off-screen buffer which must then be > copied (Refresh) to the on-screen image. > > The simple solution is to set AutoRedraw, see if that will fix it for you.... > > LFS > > > |
|||||||||||||||||||||||