i have cards the i cand drag and drop and whatnot but when i drag and drop them they change order
okay so all i would like to know is what should i use (string, array, controls) to figure out what order the cards are in
![]()
i have cards the i cand drag and drop and whatnot but when i drag and drop them they change order
okay so all i would like to know is what should i use (string, array, controls) to figure out what order the cards are in
![]()
Last edited by rockyamyx; Nov 30th, 2010 at 07:23 AM. Reason: wasnt resolved
numerically? left to right? by suit?
help us help you.
If my post helped, rate it!
Shameless blog plug: www.stateofidleness.com
My Projects:
Phoenix Fetch (For University of Phoenix Online students)
Lookout (Keylogger/PC Nanny)
PathManipulate Class (Filepath formatting)
Scraper - Class for HTML/WebBrowser Document scraping
Tutorials:
Keystroke Capturing Tutorial
Detecting completely loaded page using VB.Net WebBrowser including all frames
Sending Email in VB.Net
Autofill HP Service Manager (HPSM) in VB.Net
Ping Network Device
My latest project(s): QuickScrape | Source Matters
updated 05.15.2011
lol sorry bout that ..just from left to right ^^
im just making a game that ive missed since i cant seem to find grandia III in stores
the game is called arranged dice
Last edited by rockyamyx; Nov 29th, 2010 at 02:00 AM.
so the next question is, what type of objects are the individual cards? (pictureboxes, Images, labels overlaying an image, etc.) Are you storing the cards numeric equivalent for each card already, or are you needing to somehow convert the Image to a numeric value and THEN sort? (might be tough)
If my post helped, rate it!
Shameless blog plug: www.stateofidleness.com
My Projects:
Phoenix Fetch (For University of Phoenix Online students)
Lookout (Keylogger/PC Nanny)
PathManipulate Class (Filepath formatting)
Scraper - Class for HTML/WebBrowser Document scraping
Tutorials:
Keystroke Capturing Tutorial
Detecting completely loaded page using VB.Net WebBrowser including all frames
Sending Email in VB.Net
Autofill HP Service Manager (HPSM) in VB.Net
Ping Network Device
My latest project(s): QuickScrape | Source Matters
updated 05.15.2011
to extend my drag drop swap example:
vb Code:
Imports System.Runtime.InteropServices Public Class Form1 Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load PictureBox1.AllowDrop = True PictureBox2.AllowDrop = True PictureBox3.AllowDrop = True PictureBox4.AllowDrop = True PictureBox5.AllowDrop = True PictureBox6.AllowDrop = True PictureBox7.AllowDrop = True PictureBox8.AllowDrop = True PictureBox9.AllowDrop = True PictureBox1.Tag = 3 PictureBox2.Tag = 4 PictureBox3.Tag = 5 PictureBox4.Tag = 6 PictureBox5.Tag = 7 PictureBox6.Tag = 8 PictureBox7.Tag = 9 PictureBox8.Tag = 10 PictureBox9.Tag = 11 cardOrder = (From pb In Me.Controls.OfType(Of PictureBox)() _ Order By pb.Left _ Select CInt(pb.Tag)).ToArray End Sub 'integer array that holds value of cards from left (element 0) to right (element 8) Dim cardOrder() As Integer Private Sub PictureBoxes_DragDrop(ByVal sender As Object, ByVal e As System.Windows.Forms.DragEventArgs) Handles PictureBox1.DragDrop, PictureBox2.DragDrop, PictureBox3.DragDrop, PictureBox4.DragDrop, PictureBox5.DragDrop, PictureBox6.DragDrop, PictureBox7.DragDrop, PictureBox8.DragDrop, PictureBox9.DragDrop Dim target As PictureBox = DirectCast(sender, PictureBox) If e.Data.GetDataPresent(DataFormats.Bitmap) Then Dim sourceCardTag As Integer = CInt(source.Tag) source.Image = target.Image source.Tag = target.Tag target.Image = DirectCast(e.Data.GetData(DataFormats.Bitmap), Bitmap) target.Tag = sourceCardTag cardOrder = (From pb In Me.Controls.OfType(Of PictureBox)() _ Order By pb.Left _ Select CInt(pb.Tag)).ToArray End If End Sub Private Sub PictureBoxes_DragOver(ByVal sender As Object, ByVal e As System.Windows.Forms.DragEventArgs) Handles PictureBox1.DragOver, PictureBox2.DragOver, PictureBox3.DragOver, PictureBox4.DragOver, PictureBox5.DragOver, PictureBox6.DragOver, PictureBox7.DragOver, PictureBox8.DragOver, PictureBox9.DragOver 'make sure drag drop data can be used If e.Data.GetDataPresent(DataFormats.Bitmap) And e.AllowedEffect = DragDropEffects.Move Then e.Effect = DragDropEffects.Move Else e.Effect = DragDropEffects.None End If End Sub Dim source As PictureBox Dim image As Bitmap Private Sub PictureBox2_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles PictureBox1.MouseDown, PictureBox2.MouseDown, PictureBox3.MouseDown, PictureBox4.MouseDown, PictureBox5.MouseDown, PictureBox6.MouseDown, PictureBox7.MouseDown, PictureBox8.MouseDown, PictureBox9.MouseDown source = DirectCast(sender, PictureBox) image = DirectCast(source.Image.Clone, Bitmap) source.DoDragDrop(image, DragDropEffects.Move) End Sub Public Sub PictureBoxes_giveFeedback(ByVal sender As Object, ByVal e As System.Windows.Forms.GiveFeedbackEventArgs) Handles PictureBox1.GiveFeedback, PictureBox2.GiveFeedback, PictureBox3.GiveFeedback, PictureBox4.GiveFeedback, PictureBox5.GiveFeedback, PictureBox6.GiveFeedback, PictureBox7.GiveFeedback, PictureBox8.GiveFeedback, PictureBox9.GiveFeedback e.UseDefaultCursors = False Dim EffectCursor As New Cursor(New IO.MemoryStream(My.Resources.Move)) Dim img As New Bitmap(15 + image.Width, 26 + image.Height) Dim gr As Graphics = Graphics.FromImage(img) gr.FillRectangle(Brushes.Magenta, img.GetBounds(Drawing.GraphicsUnit.Pixel)) EffectCursor.Draw(gr, New Rectangle(0, 0, _ EffectCursor.Size.Width, EffectCursor.Size.Height)) gr.DrawImage(image, 15, 26, image.Width, image.Height) img.MakeTransparent(Color.Magenta) Cursor.Current = CreateCursor(img) End Sub #Region " CreateIconIndirect" Private Structure IconInfo Public fIcon As Boolean Public xHotspot As Int32 Public yHotspot As Int32 Public hbmMask As IntPtr Public hbmColor As IntPtr End Structure <DllImport("user32.dll", EntryPoint:="CreateIconIndirect")> _ Private Shared Function CreateIconIndirect(ByVal iconInfo As IntPtr) As IntPtr End Function <DllImport("user32.dll", CharSet:=CharSet.Auto)> _ Public Shared Function DestroyIcon(ByVal handle As IntPtr) As Boolean End Function <DllImport("gdi32.dll")> _ Public Shared Function DeleteObject(ByVal hObject As IntPtr) As Boolean End Function ''' <summary> ''' CreateCursor ''' </summary> ''' <param name="bmp"></param> ''' <returns>custom Cursor</returns> ''' <remarks>creates a custom cursor from a bitmap</remarks> Public Function CreateCursor(ByVal bmp As Bitmap) As Cursor 'Setup the Cursors IconInfo Dim tmp As New IconInfo tmp.xHotspot = 0 tmp.yHotspot = 0 tmp.fIcon = False tmp.hbmMask = bmp.GetHbitmap() tmp.hbmColor = bmp.GetHbitmap() 'Create the Pointer for the Cursor Icon Dim pnt As IntPtr = Marshal.AllocHGlobal(Marshal.SizeOf(tmp)) Marshal.StructureToPtr(tmp, pnt, True) Dim curPtr As IntPtr = CreateIconIndirect(pnt) 'Clean Up DestroyIcon(pnt) DeleteObject(tmp.hbmMask) DeleteObject(tmp.hbmColor) Return New Cursor(curPtr) End Function #End Region End Class
![]()
![]()
if this helps, rate me
![]()
![]()
irregular regions | numericTextbox | keycodes | removing control properties | hotkeys | rtf printing | Extended RichTextBox | iconWorks | readonly listbox | sort listview | screen capture | relational listForms | countDown timer | animated notifyIcon form | dynamic crystal report | move / resize runtime controls | reOrderable DnD listview / listbox | self closing message box | searchable list(of class) | cursor from bitmap | (VB2008+) Textbox - GetFirstVisibleLineIndex / GetLastVisibleLineIndex | vb2008 extensions | Paint lite.Net | calculator | inline calculator | export listview to word table | imperial~metric converter | export DGV to word ~ excel | globalInputHook | dropDown Calendar control | International Time + Currency | GDI+ gauge | quizControl | extended dgv
My Web Site....
Maths Revision V1.0
Play Connect4 against your PC (java Applet)
ohh they are in pictureboxes... with an image preset in them.. i hae them so i can drag and drop thx to paul. and by looking at pauls code i would say i would use Tag to tell what the numeric value of the card is.. am i right??
![]()
![]()
if this helps, rate me
![]()
![]()
irregular regions | numericTextbox | keycodes | removing control properties | hotkeys | rtf printing | Extended RichTextBox | iconWorks | readonly listbox | sort listview | screen capture | relational listForms | countDown timer | animated notifyIcon form | dynamic crystal report | move / resize runtime controls | reOrderable DnD listview / listbox | self closing message box | searchable list(of class) | cursor from bitmap | (VB2008+) Textbox - GetFirstVisibleLineIndex / GetLastVisibleLineIndex | vb2008 extensions | Paint lite.Net | calculator | inline calculator | export listview to word table | imperial~metric converter | export DGV to word ~ excel | globalInputHook | dropDown Calendar control | International Time + Currency | GDI+ gauge | quizControl | extended dgv
My Web Site....
Maths Revision V1.0
Play Connect4 against your PC (java Applet)
but the thing is .. i dont understand how tagging the "pictureboxes" work
i mean if picutebox1 has 3 in it and i switch the 5 with the 3 then wouldnt that me 5 =3??
how would i call to check what order they are in??
if you read my code in post #5 you'll see that it puts the value of the card in it's picturebox tag at form_load, then switches the values when you drag drop.
the array cardOrder holds the value of your cards from left to right + is refilled every time you move a card...
![]()
![]()
if this helps, rate me
![]()
![]()
irregular regions | numericTextbox | keycodes | removing control properties | hotkeys | rtf printing | Extended RichTextBox | iconWorks | readonly listbox | sort listview | screen capture | relational listForms | countDown timer | animated notifyIcon form | dynamic crystal report | move / resize runtime controls | reOrderable DnD listview / listbox | self closing message box | searchable list(of class) | cursor from bitmap | (VB2008+) Textbox - GetFirstVisibleLineIndex / GetLastVisibleLineIndex | vb2008 extensions | Paint lite.Net | calculator | inline calculator | export listview to word table | imperial~metric converter | export DGV to word ~ excel | globalInputHook | dropDown Calendar control | International Time + Currency | GDI+ gauge | quizControl | extended dgv
My Web Site....
Maths Revision V1.0
Play Connect4 against your PC (java Applet)
one more question..
in my game the player rolls the dice .. the sum of both dice, lets say 7.. then that card moves up... how would i check to see if at least three cards in a row have been rolled??
i mean i guess i could add (correct me if im wrong) a boolean on the card to determine if the card was used and then check the tag.array, but ive looked all over msdn and don't really have a good concept on how tags work, there example just shows you using a tag to open a new form
Move away from pictureboxes and this will produce more logical results. A picturebox is an element of a User Interface. It should only display a card, nothing more. A good design separates the inner logic from user interface (thus making it possible to change/modify the user interface and/or inner logic separately, without affecting each other).
If you'd made your cards as a class or a set of classes separated from the elements of the user interface you could design it to fit your needs perfectly.
As for the .tag property - it can hold any value of any type. This value does not affect its appearance and is only used by the program. So there's no concept about 'how tags work'. They don't. More specificly they work as you want them to work in your program.
#define true ((rand() % 2)? true: false) // Debug THAT!
Rate the posts that helped you!
Evaluating Expressions | Simple POP3 Protocol Realization | Timers explained | Delegates explained | A secure login to your app sample | Numeric Textbox | Printer.Print (or I miss VB6 printing in .Net) | Shuffling any IEnumerable | Marshalling structures to byte arrays and back | Invoking a method by its name | Plugins architecture WITHOUT references | Permuter that permutes everything | Encrypt/Decrypt your stuff | Snake Game | Enumerating all Network Adapters in the system | How to make a web request
well i pretty much striped my program to figureout what i am going to do..
so heres the bare minimum
VB.NET Code:
Imports System.Runtime.InteropServices Public Class ArrangeDiceForm Dim lucky_3_1_str As String = "Lucky 3-Card Bonus" Dim lucky_3_2_str As String = "Lucky 3-Card Bonus" Dim lucky_4_1_str As String = "Lucky 4-Card Bonus" Dim lucky_4_2_str As String = "Lucky 4-Card Bonus" Dim lucky_5_1_str As String = "Lucky 5-Card Bonus" Dim lucky_5_2_str As String = "Lucky 5-Card Bonus" Dim lucky3 As Boolean = False Dim lucky11 As Boolean = False Dim lucky_3_1_bool As Boolean = False Dim lucky_3_2_bool As Boolean = False Dim lucky_4_1_bool As Boolean = False Dim lucky_4_2_bool As Boolean = False Dim lucky_5_1_bool As Boolean = False Dim lucky_5_2_bool As Boolean = False Dim pinzoro_int As Integer = 0 Dim turn As Integer = 0 Dim random As Random = New Random() Dim cardOrder() As Integer 'Called at Form1_Load '##########END DIMS########' '######ArrangeDice LOAD###### Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load PictureBox1.AllowDrop = True PictureBox2.AllowDrop = True PictureBox3.AllowDrop = True PictureBox4.AllowDrop = True PictureBox5.AllowDrop = True PictureBox6.AllowDrop = True PictureBox7.AllowDrop = True PictureBox8.AllowDrop = True PictureBox9.AllowDrop = True PictureBox1.Tag = 3 PictureBox2.Tag = 4 PictureBox3.Tag = 5 PictureBox4.Tag = 6 PictureBox5.Tag = 7 PictureBox6.Tag = 8 PictureBox7.Tag = 9 PictureBox8.Tag = 10 PictureBox9.Tag = 11 cardOrder = (From pb In Me.Controls.OfType(Of PictureBox)() _ Order By pb.Left _ Select CInt(pb.Tag)).ToArray End Sub '######ARRANGE DICE LOAD END'####### '##########CARD SWAP########' #Region "Card Swap" Private Sub PictureBoxes_DragDrop(ByVal sender As Object, ByVal e As System.Windows.Forms.DragEventArgs) Handles PictureBox2.DragDrop, PictureBox3.DragDrop, PictureBox4.DragDrop, PictureBox5.DragDrop, PictureBox6.DragDrop, PictureBox7.DragDrop, PictureBox8.DragDrop, PictureBox1.DragDrop, PictureBox9.DragDrop Dim target As PictureBox = DirectCast(sender, PictureBox) If e.Data.GetDataPresent(DataFormats.Bitmap) Then Dim sourceCardTag As Integer = CInt(source.Tag) source.Image = target.Image target.Image = DirectCast(e.Data.GetData(DataFormats.Bitmap), Bitmap) target.Tag = sourceCardTag cardOrder = (From pb In Me.Controls.OfType(Of PictureBox)() _ Order By pb.Left _ Select CInt(pb.Tag)).ToArray End If End Sub Private Sub PictureBoxes_DragOver(ByVal sender As Object, ByVal e As System.Windows.Forms.DragEventArgs) Handles PictureBox2.DragOver, PictureBox3.DragOver, PictureBox4.DragOver, PictureBox5.DragOver, PictureBox6.DragOver, PictureBox7.DragOver, PictureBox8.DragOver, PictureBox1.DragDrop, PictureBox9.DragOver, PictureBox1.DragOver 'make sure drag drop data can be used If e.Data.GetDataPresent(DataFormats.Bitmap) And e.AllowedEffect = DragDropEffects.Move Then e.Effect = DragDropEffects.Move Else e.Effect = DragDropEffects.None End If End Sub Dim source As PictureBox Dim image As Bitmap Private Sub card_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles PictureBox2.MouseDown, PictureBox3.MouseDown, PictureBox4.MouseDown, PictureBox5.MouseDown, PictureBox6.MouseDown, PictureBox7.MouseDown, PictureBox8.MouseDown, PictureBox9.MouseDown, PictureBox1.MouseDown source = DirectCast(sender, PictureBox) image = DirectCast(source.Image.Clone, Bitmap) source.DoDragDrop(image, DragDropEffects.Move) End Sub Public Sub PictureBoxes_giveFeedback(ByVal sender As Object, ByVal e As System.Windows.Forms.GiveFeedbackEventArgs) Handles PictureBox2.GiveFeedback, PictureBox3.GiveFeedback, PictureBox4.GiveFeedback, PictureBox5.GiveFeedback, PictureBox6.GiveFeedback, PictureBox7.GiveFeedback, PictureBox8.GiveFeedback, PictureBox1.GiveFeedback, PictureBox9.GiveFeedback e.UseDefaultCursors = False Dim EffectCursor As New Cursor(New IO.MemoryStream(My.Resources.Move)) Dim img As New Bitmap(15 + image.Width, 26 + image.Height) Dim gr As Graphics = Graphics.FromImage(img) gr.FillRectangle(Brushes.Magenta, img.GetBounds(Drawing.GraphicsUnit.Pixel)) EffectCursor.Draw(gr, New Rectangle(50, 50, _ EffectCursor.Size.Width, EffectCursor.Size.Height)) gr.DrawImage(image, 15, 26, image.Width, image.Height) img.MakeTransparent(Color.Magenta) Cursor.Current = CreateCursor(img) End Sub #Region " CreateIconIndirect" Private Structure IconInfo Public fIcon As Boolean Public xHotspot As Int32 Public yHotspot As Int32 Public hbmMask As IntPtr Public hbmColor As IntPtr End Structure <DllImport("user32.dll", EntryPoint:="CreateIconIndirect")> _ Private Shared Function CreateIconIndirect(ByVal iconInfo As IntPtr) As IntPtr End Function <DllImport("user32.dll", CharSet:=CharSet.Auto)> _ Public Shared Function DestroyIcon(ByVal handle As IntPtr) As Boolean End Function <DllImport("gdi32.dll")> _ Public Shared Function DeleteObject(ByVal hObject As IntPtr) As Boolean End Function '''<summary> ''' CreateCursor ''' </summary> ''' <param name="bmp"></param> ''' <returns>custom Cursor</returns> '''<remarks>creates a custom cursor from a bitmap</remarks> Public Function CreateCursor(ByVal bmp As Bitmap) As Cursor 'Setup the Cursors IconInfo Dim tmp As New IconInfo tmp.xHotspot = 50 tmp.yHotspot = 50 tmp.fIcon = False tmp.hbmMask = bmp.GetHbitmap() tmp.hbmColor = bmp.GetHbitmap() 'Create the Pointer for the Cursor Icon Dim pnt As IntPtr = Marshal.AllocHGlobal(Marshal.SizeOf(tmp)) Marshal.StructureToPtr(tmp, pnt, True) Dim curPtr As IntPtr = CreateIconIndirect(pnt) 'Clean Up DestroyIcon(pnt) DeleteObject(tmp.hbmMask) DeleteObject(tmp.hbmColor) Return New Cursor(curPtr) End Function #End Region #End Region Private Sub Label11_MouseEnter(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Label9.MouseEnter, Label8.MouseEnter, Label7.MouseEnter, Label6.MouseEnter, Label5.MouseEnter, Label4.MouseEnter, Label3.MouseEnter, Label11.MouseEnter, Label10.MouseEnter Label3.Text = PictureBox1.Tag Label4.Text = PictureBox2.Tag Label5.Text = PictureBox3.Tag Label6.Text = PictureBox4.Tag Label7.Text = PictureBox5.Tag Label8.Text = PictureBox6.Tag Label9.Text = PictureBox7.Tag Label10.Text = PictureBox8.Tag Label11.Text = PictureBox9.Tag End Sub End Class
this is the part of the tags i dont get..
the labels on there over top the cards are the tag number.. if i switch them around(drag drop the tags are suppose to change with them
before switch
After switch
![]()
why use MouseEnter?
put this after the cardOrder = ... lines:
vb Code:
dim lbls() as label = {Label3, Label4, Label5, Label6, Label7, Label8, Label9, Label10, Label11} for x as integer = 0 to lbls.getupperbound(0) lbls(x).text = cardOrder(x).tostring next
![]()
![]()
if this helps, rate me
![]()
![]()
irregular regions | numericTextbox | keycodes | removing control properties | hotkeys | rtf printing | Extended RichTextBox | iconWorks | readonly listbox | sort listview | screen capture | relational listForms | countDown timer | animated notifyIcon form | dynamic crystal report | move / resize runtime controls | reOrderable DnD listview / listbox | self closing message box | searchable list(of class) | cursor from bitmap | (VB2008+) Textbox - GetFirstVisibleLineIndex / GetLastVisibleLineIndex | vb2008 extensions | Paint lite.Net | calculator | inline calculator | export listview to word table | imperial~metric converter | export DGV to word ~ excel | globalInputHook | dropDown Calendar control | International Time + Currency | GDI+ gauge | quizControl | extended dgv
My Web Site....
Maths Revision V1.0
Play Connect4 against your PC (java Applet)
no no.. i just used those to tell if the swap code was working
ok. my mistake.
it's simple...each picturebox has a card image + a tag property which contains the value of the card image
![]()
![]()
if this helps, rate me
![]()
![]()
irregular regions | numericTextbox | keycodes | removing control properties | hotkeys | rtf printing | Extended RichTextBox | iconWorks | readonly listbox | sort listview | screen capture | relational listForms | countDown timer | animated notifyIcon form | dynamic crystal report | move / resize runtime controls | reOrderable DnD listview / listbox | self closing message box | searchable list(of class) | cursor from bitmap | (VB2008+) Textbox - GetFirstVisibleLineIndex / GetLastVisibleLineIndex | vb2008 extensions | Paint lite.Net | calculator | inline calculator | export listview to word table | imperial~metric converter | export DGV to word ~ excel | globalInputHook | dropDown Calendar control | International Time + Currency | GDI+ gauge | quizControl | extended dgv
My Web Site....
Maths Revision V1.0
Play Connect4 against your PC (java Applet)
right.. i have up til when i roll the dice and whatever the sum of the two dice .. that card is activated like 4 and 3 make seven ... i dont know how to, or what method i could use to see
maybe
on roll button click event
VB.NET Code:
if picturebox9.tag = rollsum then 'do somthing' else if picturebox8.tag = rollsum then 'do somthing' else if picturebox7.tag = rollsum then 'do somthing' else if picturebox6.tag = rollsum then 'do somthing' else if picturebox5.tag = rollsum then 'do somthing' else if picturebox4.tag = rollsum then 'do somthing' else if picturebox3.tag = rollsum then 'do somthing' end if
would that work??.. or cause problems down the road?
hello, I know. it is an old post, but I tried to modify the .paul code's without success. I need, instead of swapping cards, insert the card moved between 2 cards. I tried several ways without success, could someone help me? thank!
I think there should change this part:
Dim sourceCardTag As Integer = CInt(source.Tag)
source.Image = target.Image
source.Tag = target.Tag
target.Image = DirectCast(e.Data.GetData(DataFormats.Bitmap), Bitmap)
target.Tag = sourceCardTag