|
-
Mar 16th, 2004, 07:25 PM
#1
Thread Starter
Hyperactive Member
Redraw images when lost focus
He everyone!
I'm using this function to draw images on my pictureBox
VB Code:
Dim gr As Graphics = pctBox.CreateGraphics
gr.DrawImage(New Bitmap("c:\pion.gif"), iX, iY)
As you know when you minimize your application all those things you drew on it are gone so I searched for the GotFocus or something and found/created this:
VB Code:
Public Sub frmMain_Activated(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Activated
Dim iLoop, iX, iY As Integer
For iLoop = 0 To 29
iX = Coordinate2Pixel(pioPion(iLoop).GetCoordinateX())
iY = Coordinate2Pixel(pioPion(iLoop).GetCoordinateY())
Dim gr As Graphics = pctBox.CreateGraphics
gr.DrawImage(New Bitmap("c:\pion.gif"), iX, iY)
Next
End Sub
To draw them back whenever my app lost focus... Now does this work when I popup an messagebox... but not when I minimize & maximize my application anyone with good ideas?!
Thnx in advance,
Bloged
-
Mar 16th, 2004, 07:56 PM
#2
Re: Redraw images when lost focus
Originally posted by Bloged
He everyone!
I'm using this function to draw images on my pictureBox
VB Code:
Dim gr As Graphics = pctBox.CreateGraphics
gr.DrawImage(New Bitmap("c:\pion.gif"), iX, iY)
As you know when you minimize your application all those things you drew on it are gone so I searched for the GotFocus or something and found/created this:
VB Code:
Public Sub frmMain_Activated(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Activated
Dim iLoop, iX, iY As Integer
For iLoop = 0 To 29
iX = Coordinate2Pixel(pioPion(iLoop).GetCoordinateX())
iY = Coordinate2Pixel(pioPion(iLoop).GetCoordinateY())
Dim gr As Graphics = pctBox.CreateGraphics
gr.DrawImage(New Bitmap("c:\pion.gif"), iX, iY)
Next
End Sub
To draw them back whenever my app lost focus... Now does this work when I popup an messagebox... but not when I minimize & maximize my application anyone with good ideas?!
Thnx in advance,
Bloged
two answers: you can make the image to stay forever if you draw it on the picturebox's image.
instead of
Dim gr As Graphics = pctBox.CreateGraphics
you could use
Dim gr As Graphics = Graphics.FromImage(pctBox.Image)
This way the actual image contained within the picturebox will be modified. You will only have to draw the grahpics ONCE and wont need to call your code again.
other way: if for some other reason you need to use the method that you are using right now (Grahpics.CreateGrahpics), you should put your code in the Paint event of your picturebox. The paint even is fired everytime the control is to be redrawn. Put this code in the Paint event of pctBox:
e.Graphics.DrawImage(New Bitmap("c:\pion.gif"), iX, iY)
notice the e.Graphics.... in the paint event a graphics object is provided already so you dont need to make your own graphics object.
rate my posts if they help ya!
Extract thumbnail without reading the whole image file: (C# - VB)
Apply texture to bitmaps: (C# - VB)
Extended console library: (VB)
Save JPEG with a certain quality (image compression): (C# - VB )
VB.NET to C# conversion tips!!
-
Mar 17th, 2004, 05:33 AM
#3
Thread Starter
Hyperactive Member
Thanks MrPolite
Will try it as soon as I'm home!
Edit:
Tried it here with an simple test... But it won't work it looks like it redraws them but then 'removes' them directly after... (Same thing happend when using frmMain_Activated).
Any ideas
Grtz,
Bloged
Last edited by Bloged; Mar 17th, 2004 at 06:10 AM.
-
Mar 17th, 2004, 10:42 AM
#4
hmm post the code you have in the paint event. You're not clearing or refreshing the form or anything ?
rate my posts if they help ya!
Extract thumbnail without reading the whole image file: (C# - VB)
Apply texture to bitmaps: (C# - VB)
Extended console library: (VB)
Save JPEG with a certain quality (image compression): (C# - VB )
VB.NET to C# conversion tips!!
-
Mar 18th, 2004, 07:00 AM
#5
Thread Starter
Hyperactive Member
Sorry for the delay but here is the code I'm using:
VB Code:
'If map is (redraw) draw the pions back on it
Private Sub pctMap_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles pctMap.Paint
'If game is started
If booStarted = True Then
Map.DrawAllPions(pioPion, pctMap)
End If
End Sub
and the DrawAllPions function:
VB Code:
'(Re)draws all the pions on the map
Public Shared Function DrawAllPions(ByRef pioPion() As Pion, ByVal pctBox As PictureBox)
Dim iLoop, iX, iY As Integer
For iLoop = 0 To 29
iX = Coordinate2Pixel(pioPion(iLoop).GetCoordinateX())
iY = Coordinate2Pixel(pioPion(iLoop).GetCoordinateY())
Dim gr As Graphics = pctBox.CreateGraphics
gr.DrawImage(New Bitmap("c:\pion.gif"), iX, iY)
Next
End Function
Grtz,
Bloged
-
Mar 18th, 2004, 03:12 PM
#6
Thread Starter
Hyperactive Member
*bump*
Anyone?
Grtz,
Bloged
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|