2 Replies - 797 Views - Last Post: 13 January 2014 - 07:19 AM Rate Topic: -----

#1 meeop  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 10-January 14

How do I add pictures into tiles in vb?

Posted 12 January 2014 - 08:53 PM

Hey guys, I'm using visual basic right now, and I'm trying to create a bejeweled/candy crush-like game for a class. My code is as follows:
Public Class frmCandyMash
    Dim NewBoard As Graphics
    Dim KeyBoardOK As Graphics
    Dim rect As Rectangle
    Dim stable As Bitmap
    Dim game As Boolean = True
    Dim mouseX As Integer
    Dim mouseY As Integer
    Dim mouseMapX As Integer
    Dim mouseMapY As Integer
    Dim ResWidth As Integer = 265
    Dim ResHeight As Integer = 290
    Dim TileSize As Integer = 50
    Dim Map(100, 100, 10)
    Dim MapX As Integer = 20
    Dim MapY As Integer = 20
    Dim Tiles(265, 290) As PictureBox
    Dim TileImages As Bitmap


    Private Sub frmCandyMash_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Me.Show()
        Me.Focus()
        NewBoard = Me.CreateGraphics
        stable = New Bitmap(265, 290)
        candyLoop()
    End Sub
    Private Sub candyLoop()
        Do While game = True
            Application.DoEvents()
            DrawGraphics()
        Loop
    End Sub

    Private Sub DrawGraphics()
        For x = 0 To 4
            For Y = 0 To 4
                rect = New Rectangle(x * TileSize, Y * TileSize, TileSize, TileSize)
                NewBoard.FillRectangle(Brushes.Transparent, rect)
                NewBoard.DrawRectangle(Pens.Black, rect)
            Next
        Next

        NewBoard.DrawRectangle(Pens.Orange, mouseX * TileSize, mouseY * TileSize, TileSize, TileSize)

        NewBoard = Graphics.FromImage(stable)
        KeyBoardOK = Me.CreateGraphics
        KeyBoardOK.DrawImage(stable, 0, 0, 265, 290)
        NewBoard.Clear(Color.Transparent)
    End Sub

    Private Sub frmCandyMash_MouseClick(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Me.MouseClick

    End Sub

    Private Sub frmCandyMash_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Me.MouseMove
        mouseX = Math.Floor(e.X / TileSize)
        mouseY = Math.Floor(e.Y / TileSize)

        MapX = MapX + mouseX
        MapY = MapY + mouseY
    End Sub

    Private Sub btnInstructions_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnInstructions.Click
        MessageBox.Show("Click 3 matching candies to earn points. The progress bar will go up when points are gained")
    End Sub

  
End Class


I have all the tiles and stuff, but how can i add pictures into the tiles? I've tried tutorials online, but many of them seem to need pictureboxes...i don't have enough time for adding pictureboxes....

My project is a 5x5 grid, and the user can click on images in the tiles to earn points.

Can someone help me with adding pictures? thanks!

This post has been edited by macosxnerd101: 12 January 2014 - 09:13 PM
Reason for edit:: Please use code tags


Is This A Good Question/Topic? 0
  • +

Replies To: How do I add pictures into tiles in vb?

#2 andrewsw  Icon User is online

  • Fire giant boob nipple gun!
  • member icon

Reputation: 2875
  • View blog
  • Posts: 9,538
  • Joined: 12-December 12

Re: How do I add pictures into tiles in vb?

Posted 13 January 2014 - 07:09 AM

This is VB.NET not VB6. Topic moved.
Was This Post Helpful? 0
  • +
  • -

#3 andrewsw  Icon User is online

  • Fire giant boob nipple gun!
  • member icon

Reputation: 2875
  • View blog
  • Posts: 9,538
  • Joined: 12-December 12

Re: How do I add pictures into tiles in vb?

Posted 13 January 2014 - 07:19 AM

PictureBoxes are designed to contain images. However, it is possible to use a Graphics object to draw an image. One of a number of ways is to use a Rectangle.

Graphics.DrawImage Method (Image, Rectangle)

Private Sub DrawImageRect(ByVal e As PaintEventArgs)

    ' Create image. 
    Dim newImage As Image = Image.FromFile("SampImag.jpg")

    ' Create rectangle for displaying image. 
    Dim destRect As New Rectangle(100, 100, 450, 150)

    ' Draw image to screen.
    e.Graphics.DrawImage(newImage, destRect)
End Sub

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1