Any good tutorials on this?

Adagio

Well-known member
Joined
Dec 12, 2005
Messages
162
Programming Experience
Beginner
I have spent a lot of time trying to find a good tutorial on GDI+, but so far no luck :(

I can find lots of tutorials telling me how to load an image and show it, that's not the problem, my problem is I have no idea how to do this based on what I do later in the program. Right now I'm just trying to get a simple hover effect (mouse off the image, show image1, mouse over image, show image2)

My coding 'seems' correct, as if I start the program with the mouse over the image, image2 is shown, else image1 is shown. This is how it should be. Though when I move the mouse out of (or into) the image nothing happens, though by using breakpoints I'm 100% sure that the draw() method is run
 
Could you post a code snippet so we could take a look?

As for GDI+ tutorials, my advice ( and this is how i did it ) Buy a good book, play around with it loads! and
if you get stuck, post the question on this forum.
 
Do you have any book recommendations?

Here's some code:

My class that handles graphics objects:

Public Sub drawHover()
Bitmap loadedPictureHover = Bitmap.FromFile(Application.StartupPath + IMAGE_PATH + picture + "Selected.jpg")
DrawGraphics.DrawImage(loadedPictureHover, location)
End Sub

Public Sub draw()
Bitmap loadedPicture = Bitmap.FromFile(Application.StartupPath + IMAGE_PATH + picture + ".jpg")
DrawGraphics.DrawImage(loadedPicture, location)
End Sub

Sub New(ByVal pic As String, ByVal pnt As Point)
picture = pic
location = pnt
End Sub



This looks very simple. As mentioned in first post, the drawHover() is called whenever a mouse hovers over an image, and the draw() is when not
 
DrawGraphics is located in another class (GameEngine class, which has all the objects of the graphics objects, etc)

Friend Shared DrawGraphics As Graphics
 
What are you trying to draw this image onto? i.e a control?, a graphics object you have created?
Also
The OnMouseHoverEvent i assume is where you are calling this sub, then is the acutal painting being done in the paint event?
 
I have a form with an Image, which I use to draw on. I have an MouseMove Event for this picture, which then calls the draw method

The mousemove looks like this:

Private Sub imgGameField_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles imgGameField.MouseMove
Dim i As Integer

For i = 0 To 3
If hoverButton(game.shpAnswer(i), e) Then
game.shpAnswer(i).drawHover()
Else
game.shpAnswer(i).draw()
End If
Next
End Sub

Private Function hoverButton(ByVal shpButton As Shapes, ByVal e As System.Windows.Forms.MouseEventArgs) As Boolean
If e.Location.X > shpButton.location.X And e.Location.X < shpButton.location.X + shpButton.width And e.Location.Y > shpButton.location.Y And e.Location.Y < shpButton.location.Y + shpButton.width Then
Return True
Else
Return False
End If
End Function
 
Back
Top