last day (15 days later) » 

8:18 PM
-1
Q: Can't Catch ArgumentException

Green FireI am building a game in vb.net. I need to update my screen (PictureBox), From several threads. My Update Function : Private Delegate Sub NonInput() Public Sub UpdateMyScreen() If BarScreen.InvokeRequired() Then BarScreen.Invoke(New NonInput(AddressOf UpdateMyScreen)) ...

 
Regardless of the error. Debug the Paint event, find and fix the error that lives there.
 
There are no Paint event, When I refresh a picturebox it draws to screen the image of the picturebox. I mean that if I change the image of the picturebox I will not see it until I refresh the control.
 
What? show some more code then.
 
@OneFineDay what do you mean by showing more code, I have 4000 lines of code !
 
come think about it-what code as anything to do with this?
If you change an image in a picturebox you don't have to call refresh. It has always updated as soon as I assigned a new image.
 
8:18 PM
Well I an not changeing the image I am drawing on it (I draw dirctly on the image), so to see the update I need to refresh
 
How are you drawing on it if not using the paint event? That is what Refresh is for - firing the paint event.
Show the GDI+ code then. This error usually means one of the graphics methods is not working as expected. You may need to use a diff overload for that method.
 
OK look, I have a bitmap named background, now my picturebox always shows the background image. I created a graphics from the bitmap and I use it to draw things to the bitmap, now when I draw things like that it will not update in the picturebox until I refresh it.
 
When you paint something in anything other than the paint event it does not persist. You must draw then make an image of that and then reassign that image.
 
8:35 PM
No ....
Wait just a sec
 
I can't wait all day...
 
sorry :( it hard to Explain yourself I am Writing
Ok this is some of my code -
__Private BarScreen As PictureBox
__Private TempScreen As Bitmap
__Private g As Graphics
I initializes it like this -
__TempScreen = New Bitmap(BarScreen.Size.Width, BarScreen.Size.Height)
__BarScreen.Image = TempScreen
__ g = Graphics.FromImage(TempScreen)
Now when I draw the picture like -
__g.Clear(Color.White)
__g.FillRectangle(Color.Blue, 25, 0, 20, 20)
I need to do BarScreen.Refresh to see the changes in the image.
 
g.Clear could be the offender - try commenting that out. Where are you drawing this?
g.FillRectangle(Color.Blue, New Rectangle(25, 0, 20, 20) ) also works better in GDI+
You should also be using a different Graphics object - Using g As Graphics = BarScreen.CreateGraphics
 
8:51 PM
I tryed to do without the g.Clear (the same problem).
And the drawing code is always running on a another thread, it is not so good idea to do New Rectangle(25, 0, 20, 20) because this code runs all the time and it is slow to create Each time new rectangle.
 
Using blocks dispose of the Graphics object. Look at the last line of above post too.
How is FillRectangle(Color.Blue, 25, 0, 20, 20) in your example diff than what I did?
It is not slow. I have painted over 300 lines of code every 100 ms and slow was not a problem.
 
Now if I use Using g As Graphics = BarScreen.CreateGraphics, I can see the drawing in progress, I mean that if I need to draw a lot of things I will see how each thing will be drawen, and in my one it will draw all in one time to screen.
and 100ms is very very long time.
100ms = 10fps
 
You are leaving off a lot of info and being quite vague. I don't think I can help.
 
But is any case why I can't catch the error ?
Anyway thanks for your time
 

last day (15 days later) »