New question:
OK, I ran into another problem. I want it be so that if I click the picture box with the person in it, you can move him by clicking on another tile. How do I do this (I tried (got from Dustin_H's sample code) :
Private Sub PicBox_On_Click(ByVal sender As Object, ByVal e As EventArgs) If PicBox(x, y).Image = Tiles.picPerson.Image Then 'BlaBlaBla End If End Sub |
but it didn't work)
In other words: How can you tell VB to do something to the picture box the user clicked
------------------------------
Another question:
I am trying to let the user change all the Grass (frmTiles.picGrass.Picture) tiles to Dirt (frmTiles.picDirt.Picture) tiles, how do I do this
And using Dustin_H's sample code (see page 3 of this topic), how do I tell vb where to put the grid of picture boxes (its always in the top left corner of the form)
------------------------------
Another question:
(See post#39)

Another Question
Dennis Vys
You can any picture box event you want to the class. In any event you get data on the particular picture box from the sender argument, which is an object or the object in question.
Events are easy. :) !
The Netron Project
How about asking specific questions
lizzy64
the individual above is right.... It may be slow.....
But believe it or not... I wrote something like this.
I'd like to think I'm getting better. However, this is the first .Net piece of code I ever wote and I don't have a clue how I did this. Yes I set some of the way's I do things in there. But goodness, I'm going to have to stare at this for a while...
Public Class Form1
Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Dim row As Integer
Dim column As Integer
For row = 0 To 24
For column = 0 To 24
addnewpicturebox(column, row, 20, 20)
Next
Next
addnewpicturebox(0, 0, 20, 20)
addnewpicturebox(10, 0, 20, 20)
End Sub
Private Sub addnewpicturebox(ByVal x As Integer, ByVal y As Integer, Optional ByVal Xbase As Integer = 0, Optional ByVal Ybase As Integer = 0)
Const cCellHeight As Integer = 10
Const cCellWidth As Integer = 10
Dim a As New ColumnEditor
Dim b As New System.Windows.Forms.picturebox
b = a.Getpicturebox
b.Enabled = True
b.BackColor = Color.White
Me.Controls.Add(b)
b.Left = (x * cCellWidth) + Xbase
b.Top = (y * cCellHeight) + Ybase
End Sub
End Class
Public Class ColumnEditor
Protected Const cCellHeight As Integer = 10
Protected Const cCellWidth As Integer = 10
Friend withevents tb As New System.Windows.Forms.picturebox
Public Function Getpicturebox() As System.Windows.Forms.PictureBox
Dim CellID As New DataDefinitions.CellDescriptor
tb.Visible = True
tb.Enabled = True
tb.Height = cCellHeight
tb.Width = cCellWidth
tb.BorderStyle = BorderStyle.None
'CellID.ColumnNumber()
'CellID.RowNumber()
Getpicturebox = tb
End Function
Private
Sub tb_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles tb.Click "Hello", MsgBoxStyle.DefaultButton1, "Click Event") End SubPublic Sub New()
End Sub
Public Class DataDefinitions
Public Structure CellDescriptor
Public RowNumber As Integer
Public ColumnNumber As Integer
Public Selected As Boolean
Public character As Char
End Structure
End Class
End Class
Jeremy Maynor
sang
jamesg1
If you look at the current code it is now declared as friend withevents.
The picture boxes produced by class column editor now has events.
Additionally, you now have a click event as an example. Its been added to the code.
Play with this in the debugger to learn by setting a break point in this routine, running the program and clicking on a random picture box. Also pay special attention to the arguments of the click event. Sender will be an object representation of the picture box that you clicked. "e" will have additional information.
Remember this is just one event of many, all accessible in the upper right hand window, when you select the Tb object in the columneditor class in the upper left window on the IDE.
merrylep
APMaio
LuckyCarl
Please see my post on 10/26.
pbriggs
u_r_twisted
How I am making a RPG game with a grid.
nikoo
I do think you want to keep those controls in an array, so you can access them. You can declare an array as a member of your form class:
Private m_PictureControls(24, 24) As MyPictureBox
In the AddNewPictureBox, you can do
m_PictureControls(x, y) = newPictureBox
After that, you could access the control in the array. You can use code like
AddHandler newPictureBox.Click, AddressOf xxx
to handle events as well.
You see why I use MyPictureBox here You can create your own class which inherits from the PictureBox to add your own properties and functions. For example, you can add row, column information into it:
Public Class MyPictureBox
Inherits PictureBox
Public Column As Integer ' you might want to use Property, I just want to provide a simple sample...
Public Row As Integer
...
End Class
In this way, when you handle the events, you know where it comes from easily, right You can also overrides functions in the PictureBox to handle events.
Frankly, I don't exactly know whether the performance of a form with so many controls will meet the requirement of a game. I personally will think to build one control which paints all of those pictures, of course, you need handle Mouse events and calculate where it is. It could be a little bit complex when you start to do it, but would give you the right performance for a game.
Thanks
Lifeng Lu MS
A Casa do Java
Big Andy 78