Question Why are my images not appearing?

colossus1958

Member
Joined
Sep 7, 2008
Messages
10
Programming Experience
Beginner
I am only a beginner at VB.NET. I am having a problem displaying images on a form. This is the code I am working with:

VB.NET:
Public Class NewSol
    Private m_GO As Graphics = Me.CreateGraphics
    Private Sub ExitToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ExitToolStripMenuItem.Click
        Application.Exit()
    End Sub

    Private Sub AboutNewSolToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles AboutNewSolToolStripMenuItem.Click
        AboutBox1.Show()
    End Sub
    Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
        SLabel4.Text = Now.ToLongTimeString
    End Sub
    Private Sub DealToolStripMenuItem_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles DealToolStripMenuItem.Click
        m_GO.DrawImage(My.Resources.card1, 351, 83)
        m_GO.DrawImage(My.Resources.card2, 282, 83)
        m_GO.DrawImage(My.Resources.card3, 277, 83)
        m_GO.DrawImage(My.Resources.card4, 272, 83)
        m_GO.DrawImage(My.Resources.card5, 267, 83)
        m_GO.DrawImage(My.Resources.card6, 262, 83)
        m_GO.DrawImage(My.Resources.card7, 257, 83)
        m_GO.DrawImage(My.Resources.card8, 188, 83)
    End Sub

What's happening is that along about the 7th image, only half the image appears and the last one is gone altogether. Anyone have any ideas?
 
You can't use CreateGraphics for drawing, you must use the Paint event, the correct Graphics instance is provided through e.Graphics.
 
You can use the Click event to force a repaint by calling Invalidate/Update or Refresh which causes the Paint event to happen and paint invalidated areas.
 
Back
Top