Moon Dim Viewer As DrawingGraphics Dim Moon As DrawingImage Dim

Document Sample
Moon Dim Viewer As DrawingGraphics Dim Moon As DrawingImage Dim Powered By Docstoc
					                                  Moon

Dim Viewer As Drawing.Graphics
    Dim Moon As Drawing.Image
    Dim MoonX As Integer, MoonY As Integer

    Private Function AppPath() As String
        Dim A As String
        'Executing file location and name
        A = Reflection.Assembly.GetExecutingAssembly.Location
        'strip off file name
        A = Mid(A, 1, InStrRev(A, "\"))
        Return (A)
    End Function

    Private Sub frmMoon_Load(ByVal sender As Object, ByVal e As
System.EventArgs) Handles MyBase.Load
        'set up graphics info
        Viewer = picViewer.CreateGraphics
        Moon = Drawing.Image.FromFile(AppPath() + "themoon.bmp")
        MoonX = 0 : MoonY = 0
        picViewer_Paint(Nothing, Nothing)
        Me.Focus()
    End Sub

    Private Sub frmMoon_Closing(ByVal sender As Object, ByVal e As
System.ComponentModel.CancelEventArgs) Handles MyBase.Closing
        Viewer.Dispose()
        Moon.Dispose()
    End Sub

    Private Sub frmMoon_KeyDown(ByVal sender As Object, ByVal e As
System.Windows.Forms.KeyEventArgs) Handles MyBase.KeyDown
        Dim Delta As Integer
        'hold down shift for faster movement
        If e.Shift Then
            Delta = 5
        Else
            Delta = 1
        End If
        'set values for x and y (check limits)
        Select Case e.KeyCode
            Case Keys.Left
                MoonX -= Delta
            Case Keys.Right
                MoonX += Delta
            Case Keys.Up
                MoonY -= Delta
            Case Keys.Down
                MoonY += Delta
            Case Else
                Exit Sub
        End Select
        If MoonX < 0 Then
            MoonX = 0
        ElseIf MoonX > Moon.Width - picViewer.ClientRectangle.Width
Then
            MoonX = Moon.Width - picViewer.ClientRectangle.Width
        End If
        If MoonY < 0 Then
            MoonY = 0
        ElseIf MoonY > Moon.Height - picViewer.ClientRectangle.Height
Then
            MoonY = Moon.Height - picViewer.ClientRectangle.Height
        End If
        'draw moon in viewer
        picViewer_Paint(Nothing, Nothing)
        Me.Focus()
    End Sub

    Private Sub picViewer_Paint(ByVal sender As Object, ByVal e As
System.Windows.Forms.PaintEventArgs) Handles picViewer.Paint
        Dim ViewRect As Drawing.Rectangle
        Dim MoonRect As Drawing.Rectangle
        ViewRect = New Rectangle(0, 0, picViewer.ClientRectangle.Width,
picViewer.ClientRectangle.Height)
        MoonRect = New Rectangle(MoonX, MoonY,
picViewer.ClientRectangle.Width, picViewer.ClientRectangle.Height)
        Viewer.DrawImage(Moon, ViewRect, MoonRect,
Drawing.GraphicsUnit.Pixel)
    End Sub
End Class

				
DOCUMENT INFO
Shared By:
Categories:
Stats:
views:87
posted:3/7/2010
language:English
pages:2
Description: Moon Dim Viewer As DrawingGraphics Dim Moon As DrawingImage Dim