clearing all drawings in PictureBox
clearing all drawings in PictureBox
clearing all drawings in PictureBox
clearing all drawings in PictureBox
clearing all drawings in PictureBox
clearing all drawings in PictureBox clearing all drawings in PictureBox clearing all drawings in PictureBox clearing all drawings in PictureBox clearing all drawings in PictureBox clearing all drawings in PictureBox clearing all drawings in PictureBox clearing all drawings in PictureBox
clearing all drawings in PictureBox clearing all drawings in PictureBox
clearing all drawings in PictureBox
Go Back  Xtreme Visual Basic Talk > > > clearing all drawings in PictureBox


Reply
 
Thread Tools Display Modes
  #1  
Old 04-05-2012, 03:01 AM
george_m george_m is offline
Newcomer
 
Join Date: Mar 2012
Posts: 20
Default clearing all drawings in PictureBox


I've problem with clearing all the drawings I've created in my PictureBox. In fact I've created animation which stops after certain time and remains on the screen. The animation is created/painted with collection of about 25 TextBoxes - input of a user. Now I've added a button which clears all that info in TextBoxes and also should clear PictureBox - PictureBox.Refresh(). The problem is when I add new info in 25 TextBoxes nothing appears in PictureBox and I can't start an animation. Wondering why...
Reply With Quote
  #2  
Old 04-05-2012, 04:50 AM
DrPunk's Avatar
DrPunkclearing all drawings in PictureBox DrPunk is offline
Senior Contributor

* Expert *
 
Join Date: Apr 2003
Location: Never where I want to be
Posts: 1,403
Default

I would maybe be useful to know more about how you're drawing to the picturebox, but the Clear method of the graphics object will do what you require...
Code:
Dim g as graphics = Picturebox1.CreateGraphics
g.Clear(Color.White)
g.Dispose
__________________
There are no computers in heaven!
Reply With Quote
  #3  
Old 04-05-2012, 05:41 AM
george_m george_m is offline
Newcomer
 
Join Date: Mar 2012
Posts: 20
Default

Clear method is not working . For drawing in PictureBox I use a collection of data in DataTable which is added and filled after user defines all info in those 25 TextBoxes. Then I use simple FillPolygon, DrawLine and DrawString. When I reload data I remove all the columns of DataTable, maybe that's not enough.
Reply With Quote
  #4  
Old 04-05-2012, 05:47 AM
AtmaWeapon's Avatar
AtmaWeaponclearing all drawings in PictureBox AtmaWeapon is offline
Fabulous Florist

Forum Leader
* Guru *
 
Join Date: Feb 2004
Location: Austin, TX
Posts: 9,500
Default

Are you drawing by using a CreateGraphics() call (which you shouldn't do), handling the Paint event (which is better, but using a PictureBox is a silly habit), or drawing to a bitmap that is the image of the PictureBox (which is the only sensible reason you'd be using a PictureBox)?
__________________
.NET Resources
My FAQ threads | Tutor's Corner | Code Library
I would bet money 2/3 of .NET questions are already answered in one of these three places.
Reply With Quote
  #5  
Old 04-05-2012, 06:01 AM
george_m george_m is offline
Newcomer
 
Join Date: Mar 2012
Posts: 20
Default

I'm using Paint event in which e.Graphics... After removing all the columns of DataTable I wrote DataTable.Clear() and then DrPunk's answer. In PictureBox stays a picture of an end of a previous animation.
Reply With Quote
  #6  
Old 04-05-2012, 09:21 AM
passel's Avatar
passelclearing all drawings in PictureBox passel is offline
Sinecure Expert

Super Moderator
* Guru *
 
Join Date: Jun 2003
Location: Upstate New York, usa
Posts: 8,024
Default

As AtmaWeapon said, you shouldn't use CreateGraphics.
Normally, if you are doing your drawing in the Paint event of the control, you would "clear" it by causing the Paint event (preferably .Invalidate, but .Refresh if you want), and in the Paint event "don't draw anything".

The control will have "cleared" the drawing surface before handing it to you, so you just leave it alone and it is cleared.
But, what "cleared" means depends on what you have done. If you have something loaded in the .BackgroundImage And/Or .Image properties, then that is what it is cleared to.
If you have nothing in those properties, then it is cleared to the background color.

If you can't start another animation, then perhaps part of your process trying to clear the image is not only not clearing the last frame of animation, but hanging up any further animation you're trying to do.

It really isn't fair to us to have to guess at what way, out of the myriad of ways to update an area of the screen in .Net, that you are doing your drawing.
Surely, you could have shown the key components of what your paint event is doing, whether you mess with the .Image property at all, whether you're using another backbuffer implentation, etc.
__________________
There Is An Island Of Opportunity In The Middle of Every Difficulty.
Miss That, Though, And You're Pretty Much Doomed.
Reply With Quote
  #7  
Old 04-05-2012, 10:59 AM
AtmaWeapon's Avatar
AtmaWeaponclearing all drawings in PictureBox AtmaWeapon is offline
Fabulous Florist

Forum Leader
* Guru *
 
Join Date: Feb 2004
Location: Austin, TX
Posts: 9,500
Default

Yeah honestly I can't make a stab at an answer without seeing some code. "I tried it and it didn't work" doesn't satisfy me; you probably put the code in the wrong place. I can't operate blind.
__________________
.NET Resources
My FAQ threads | Tutor's Corner | Code Library
I would bet money 2/3 of .NET questions are already answered in one of these three places.
Reply With Quote
  #8  
Old 04-05-2012, 11:31 AM
george_m george_m is offline
Newcomer
 
Join Date: Mar 2012
Posts: 20
Default

OK to be more exact what is happening: I've created DataGridView with DataTable which is filled with data after some calculations (6 columns of numbers to be exact). Under PictureBox_Paint event I'm drawing animation every Timer_Tick event with PictureBox.Refresh() method. In Paint event I'm using a row of data of DataTable like DataGridView.Item("Name_of_row", i.Value) to draw every step of animation. Everything works fine for the first run. Then I've created Button event where I want to clear all the data and prepare application to be ready for a new calculation and animation. Under this event I wrote:

Code:
TextBox.Clear() 'All TextBoxes are cleared
DataTable.Clear()
DataTable.Columns.Remove(Name) 'All columns of DataTable are removed
PictureBox.Refresh()
Calculations work fine after clearing on a second run and also a new proper DataTable is added but the animation isn't working.
Reply With Quote
  #9  
Old 04-05-2012, 01:41 PM
passel's Avatar
passelclearing all drawings in PictureBox passel is offline
Sinecure Expert

Super Moderator
* Guru *
 
Join Date: Jun 2003
Location: Upstate New York, usa
Posts: 8,024
Default

Yes, the animation isn't working, and amazingly enough, the animation code is the code you haven't illustrated.

PictureBox.Refresh will cause the Paint event to occur, but we have no idea what you are doing in the Paint event.

"Under PictureBox_Paint event I'm drawing animation"

Ok, how are you "drawing animation"
Drawing paths, filling polys, using a bitmap, DrawImage, Transformations, ....
Indexing into rows of a table?
Have you put a breakpoint in the Paint Event and stepped through to verify you are indexing and getting the values you expect when it doesn't work?

Sorry to inform you, but code can be wrong more ways then there are lines of code in the code.
If we could solve your code problems without seeing the code, I probably wouldn't need to be behind this desk right now.
__________________
There Is An Island Of Opportunity In The Middle of Every Difficulty.
Miss That, Though, And You're Pretty Much Doomed.
Reply With Quote
  #10  
Old 04-05-2012, 03:00 PM
george_m george_m is offline
Newcomer
 
Join Date: Mar 2012
Posts: 20
Default

The animation code part is quite long so I'm describing generally what' s happening. Just about animation part then: in Timer_Tick event I've Integer i declared like i=i+1, the same i is used in PictureBox Paint event like DataGridView.Item("Name_of_row", i.Value) which is a certain row of a DataTable column. For drawing I'm using only FillPolygon, DrawLine, DrawString like e.Graphics.FillPolygon...
Reply With Quote
  #11  
Old 04-05-2012, 04:44 PM
passel's Avatar
passelclearing all drawings in PictureBox passel is offline
Sinecure Expert

Super Moderator
* Guru *
 
Join Date: Jun 2003
Location: Upstate New York, usa
Posts: 8,024
Default

Ok, so when it is not working, then put a breakpoint in the paint event code and verify that you are populating your drawing instructions correctly.
Perhaps when you cleared the table, then whatever reference you're using to access the table is not longer valid, so you are not getting good data.
Perhaps you have an exception handler that is trapping an exception silently, and so nothing is being done.

You will need to learn to use the Debugging capabilities of the IDE as well as the programming capabilities if you want to have any success at finding the problem.
We can not help solve the problem without code to look at.

If you want more from us, then you will probably need to create a small project that replicates the problem.
You may not need all the capabilities.
If you can create a test application that will process a few items from a table and draw them, and then when reset, fails to draw them, then you will have a small project that you could post and someone could look at.

Sometimes, just the act of creating a small test case to illustrate the problem leads to finding out what the problem was, so it might not be a waste of time if you could try to create a new, small, not as capable project, to use for debugging.
__________________
There Is An Island Of Opportunity In The Middle of Every Difficulty.
Miss That, Though, And You're Pretty Much Doomed.
Reply With Quote
  #12  
Old 04-08-2012, 08:34 AM
Gruff's Avatar
Gruffclearing all drawings in PictureBox Gruff is offline
Bald Mountain Survivor

Retired Moderator
* Expert *
 
Join Date: Aug 2003
Location: Oregon, USA - deceased
Posts: 6,440
Default

The Paint event fires not just when you tell it to, but also whenever Windows decides it needs to be triggered. Any drawing code inside the event runs at that time.

If you do not want the code to run (i.e show a blank canvas) you need some logic to handle that situation.

It sounds like You are relying on logic far up stream of the paint event. You could instead place it directly inside the paint event.

Code:
Public Class Form1 Dim Draw_Animation As Boolean = False Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click Draw_Animation = True PictureBox1.Invalidate() timer1.enabled = True End Sub Private Sub Button2_Click(sender As System.Object, e As System.EventArgs) Handles Button2.Click Draw_Animation = False timer1.enabled = False PictureBox1.Invalidate() End Sub Private Sub PictureBox1_Paint(sender As Object, e As System.Windows.Forms.PaintEventArgs) Handles PictureBox1.Paint If Draw_Animation Then ',,, End If 'otherwise Picturebox is cleared. End Sub End Class

In any case I also suggest you make use of your debug tools to see why your getting the behavior you describe.
__________________
Burn the land and boil the sea
You can't take the sky from me


~T

Last edited by Gruff; 04-08-2012 at 08:45 AM.
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
clearing all drawings in PictureBox
clearing all drawings in PictureBox
clearing all drawings in PictureBox clearing all drawings in PictureBox
clearing all drawings in PictureBox
clearing all drawings in PictureBox
clearing all drawings in PictureBox clearing all drawings in PictureBox clearing all drawings in PictureBox clearing all drawings in PictureBox clearing all drawings in PictureBox clearing all drawings in PictureBox clearing all drawings in PictureBox
clearing all drawings in PictureBox
clearing all drawings in PictureBox
 
clearing all drawings in PictureBox
clearing all drawings in PictureBox
 
-->