DotNetNewsgroup.com  
web access to complete list of Microsoft.NET newsgroups
   home   |   control panel login   |   archive  |  
 
  carried group
academic
adonet
aspnet
aspnet.announcements
aspnet.buildingcontrols
aspnet.caching
aspnet.datagridcontrol
aspnet.mobile
aspnet.security
aspnet.webcontrols
aspnet.webservices
assignment_manager
datatools
dotnet.distributed_apps
dotnet.general
dotnet.myservices
dotnet.nternationalization
dotnet.scripting
dotnet.security
dotnet.vjsharp
dotnet.vsa
dotnet.xml
dotnetfaqs
framework
framework.clr
framework.compactframework
framework.component_services
framework.controls
framework.databinding
framework.drawing
framework.enhancements
framework.interop
framework.odbcnet
framework.performance
framework.remoting
framework.sdk
framework.setup
framework.webservices
framework.windowsforms
framework.wmi
frwk.windowsforms.designtime
lang.csharp
lang.jscript
lang.vb
lang.vb.controls
lang.vb.data
lang.vb.upgrade
lang.vc
lang.vc.libraries
  
 
start date: Tue, 31 Jul 2007 05:42:35 -0700,    posted on: microsoft.public.dotnet.framework.drawing        back       

Thread Index
  1    nvx
          2    nvx
          3    Bob Powell [MVP]


How to clear the content of a PictureBox which has a BG colour set to white? (.NET 2.0)   
Hello,
how can I permanently clear the content of a PictureBox which has a
background colour set to white? I have tried to do it the same way as
I do the painting (create a Bitmap, clear it with white colour and
draw it onto a Graphics on the PictureBox), but it does not work as I
expect it would.

The PictureBox is on a TabPage of a TabControl. After I try to clear
the content of the PictureBox, it becomes white, but if I switch to
another TabPage and return back, the previous image is there again.
The same thing happens when I click a menu item. It rolls down, covers
the PictureBox partially, and after it rolls up, the part of the
PictureBox that was covered contains the previous content. What do I
do wrong?

Sample code supposed to permanently clear the contents of a
PictureBox:

Bitmap bm = new Bitmap(pictureBox.Width, pictureBox.Height);
Graphics g = Graphics.FromImage(bm);
g.Clear(System.Drawing.Color.White);
Graphics pbg = pictureBox.CreateGraphics();
pbg.DrawImageUnscaled(bm, new Point(0, 0));
g.Dispose();


Thanks for any help...

Best regards
nvx
Date:Tue, 31 Jul 2007 05:42:35 -0700   Author:  

Re: How to clear the content of a PictureBox which has a BG colour set to white? (.NET 2.0)   
SOLVED... There was one wrong declaration in the code.

nvx
Date:Tue, 31 Jul 2007 06:27:08 -0700   Author:  

Re: How to clear the content of a PictureBox which has a BG colour set to white? (.NET 2.0)   
A picture box displays images. You don't need to draw the image onto it, you 
just set the Picturebox's Image property to the image.

Bitmap bm=new Bitmap(...);
this.pictureBox1.Image=bm;

To clear the image from the picture box just simply set the Image parameter 
to null.


-- 
-- 
Bob Powell [MVP]
Visual C#, System.Drawing

Ramuseco Limited .NET consulting
http://www.ramuseco.com

Find great Windows Forms articles in Windows Forms Tips and Tricks
http://www.bobpowell.net/tipstricks.htm

Answer those GDI+ questions with the GDI+ FAQ
http://www.bobpowell.net/faqmain.htm

All new articles provide code in C# and VB.NET.
Subscribe to the RSS feeds provided and never miss a new article.


"nvx"  wrote in message 
news:1185885755.126623.52880@22g2000hsm.googlegroups.com...

> Hello,
> how can I permanently clear the content of a PictureBox which has a
> background colour set to white? I have tried to do it the same way as
> I do the painting (create a Bitmap, clear it with white colour and
> draw it onto a Graphics on the PictureBox), but it does not work as I
> expect it would.
>
> The PictureBox is on a TabPage of a TabControl. After I try to clear
> the content of the PictureBox, it becomes white, but if I switch to
> another TabPage and return back, the previous image is there again.
> The same thing happens when I click a menu item. It rolls down, covers
> the PictureBox partially, and after it rolls up, the part of the
> PictureBox that was covered contains the previous content. What do I
> do wrong?
>
> Sample code supposed to permanently clear the contents of a
> PictureBox:
>
> Bitmap bm = new Bitmap(pictureBox.Width, pictureBox.Height);
> Graphics g = Graphics.FromImage(bm);
> g.Clear(System.Drawing.Color.White);
> Graphics pbg = pictureBox.CreateGraphics();
> pbg.DrawImageUnscaled(bm, new Point(0, 0));
> g.Dispose();
>
>
> Thanks for any help...
>
> Best regards
> nvx
> 
Date:Tue, 31 Jul 2007 16:00:20 +0200   Author:  

Google
 
Web dotnetnewsgroup.com


COPYRIGHT ?2005, EUROFRONT WORLDWIDE LTD., ALL RIGHT RESERVE  |   Contact us