-
Oct 31st, 2012, 05:03 AM
#1
Thread Starter
Lively Member
vb.net bank system
Hi,
I'm trying to make a visual bank system for my RPG game, but I have some issues.
as you see on the image if have 9 columns and 4 rows
Code:
Public Const BANK_COLUMNS As Integer = 8
Public Const BANK_ROWS As Integer = 3
when you click on a item area (the pokeball with black background) it should select that item by drawing a rectangle around it.
how will I make a script like this? I can't figure out how I'll make it. I've tried alot of things but I failed. (look my script below)
Code:
Private Sub picBank_MouseDown(sender As Object, e As System.Windows.Forms.MouseEventArgs) Handles picBank.MouseDown
Dim X As Integer = CInt(Math.Floor(e.X / 32))
Dim Y As Integer = CInt(Math.Floor(e.Y / 32))
' Label1.Text = String.Format("{0} - {1}", X, Y)
For column = 0 To BANK_COLUMNS
For row = 0 To BANK_ROWS
'15 + column * 48 / 32
If X > (15 + (column * 48) / 32) Then
Label1.Text = column.ToString
DrawRectangle(New Rectangle(0, 0, 32, 32)
End If
Next
Next
End Sub
-
Oct 31st, 2012, 05:54 AM
#2
Re: vb.net bank system
You don't draw in a MouseDown event handler. You draw in the Paint event handler of the control you want to draw on. If you want to draw around the PictureBox then that means the Paint event of the form, otherwise the Paint event of the PictureBox. As for the actual drawing, use the ControlPaint.DrawSelectionFrame method.
-
Oct 31st, 2012, 08:40 AM
#3
Thread Starter
Lively Member
Re: vb.net bank system
Originally Posted by jmcilhinney
You don't draw in a MouseDown event handler. You draw in the Paint event handler of the control you want to draw on. If you want to draw around the PictureBox then that means the Paint event of the form, otherwise the Paint event of the PictureBox. As for the actual drawing, use the ControlPaint.DrawSelectionFrame method.
No that's not what I ment. that it will draw in this sub doesnt matter. in this sub it needs the location where it should draw the rectangle.
the location is everytime around the black box with the pokeball inside. if you click behind the black box with the pokeball, it should know the location where it should draw the rectangle
-
Oct 31st, 2012, 08:51 AM
#4
Re: vb.net bank system
Your description doesn't really make sense. Presumably you want to draw the selection box just inside or just outside the PictureBox that was clicked, right? If so then you simply handle the Click event of the PictureBoxes and, when one is clicked, assign it to a member variable. In the Paint event handler you're going to draw in you get the value of that variable, i.e. the PictureBox that was "selected" and use its Bounds to decide where to draw.
-
Oct 31st, 2012, 11:19 AM
#5
Thread Starter
Lively Member
Re: vb.net bank system
Originally Posted by jmcilhinney
Your description doesn't really make sense. Presumably you want to draw the selection box just inside or just outside the PictureBox that was clicked, right? If so then you simply handle the Click event of the PictureBoxes and, when one is clicked, assign it to a member variable. In the Paint event handler you're going to draw in you get the value of that variable, i.e. the PictureBox that was "selected" and use its Bounds to decide where to draw.
Yes, but I need the script for that variable because I can't figure out how to get it
-
Oct 31st, 2012, 05:10 PM
#6
Re: vb.net bank system
Well firstly, there is no script because VB.NET is not a scripting language. There's code, but surely you already know how to declare a variable and get and set its value. If what you're saying, without actually saying, is that you don't know how to identify the PictureBox to assign to the variable then we can address that. In an event handler, the 'sender' is always the object that raised the event. That means that, in the Click event handler of your PictureBoxes, he 'sender' is the PictureBox that was clicked. If you need more, please be specific.
-
Oct 31st, 2012, 08:45 PM
#7
Addicted Member
Re: vb.net bank system
Hi, you don't actually say how the graphic you show in the first post is created but if the "pokeballs" are not contained in a PictureBox then it may simplify things if you changed the graphic and used PictureBoxes.
Here is an example of changing the background color to "selected" of one of 10 PictureBoxes. In your case you would be selecting a different image that represented the selected "pokeball"
Code:
Public Class Form1
Private Sub PictureBox1_MouseClick(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) _
Handles PictureBox1.MouseClick, PictureBox2.MouseClick, PictureBox3.MouseClick, PictureBox4.MouseClick, _
PictureBox5.MouseClick, PictureBox6.MouseClick, PictureBox7.MouseClick, PictureBox8.MouseClick, _
PictureBox9.MouseClick, PictureBox10.MouseClick
Dim selected_box As PictureBox = DirectCast(sender, PictureBox)
For Each picbox As Control In Me.Controls
If (TypeOf picbox Is PictureBox) Then
picbox.BackColor = Color.Lime
End If
Next
selected_box.BackColor = Color.Red
End Sub
End Class
-
Nov 1st, 2012, 10:59 AM
#8
Hyperactive Member
Re: vb.net bank system
Perhaps I am oversimplifying, but I think you need to have a collection of all the items in the bank. When the user clicks in the bank, get the mouse coords and go through the bank item collection and check to see if the mouse click falls inside of the coords for the item (using the location of the bank item and the width/height of the item). You can have a method for each bank item to "select" it.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|