Results 1 to 19 of 19

Thread: what do i use to....

  1. #1
    Member rockyamyx's Avatar
    Join Date
    Nov 10
    Posts
    57

    Question what do i use to....

    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

  2. #2

  3. #3
    Member rockyamyx's Avatar
    Join Date
    Nov 10
    Posts
    57

    Re: what do i use to....

    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.

  4. #4
    Frenzied Member stateofidleness's Avatar
    Join Date
    Jan 09
    Posts
    1,780

    Re: what do i use to....

    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)

  5. #5
    vb Coda .paul.'s Avatar
    Join Date
    May 07
    Location
    Chelmsford UK
    Posts
    16,471

    Re: what do i use to....

    to extend my drag drop swap example:

    vb Code:
    1. Imports System.Runtime.InteropServices
    2.  
    3. Public Class Form1
    4.  
    5.     Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    6.         PictureBox1.AllowDrop = True
    7.         PictureBox2.AllowDrop = True
    8.         PictureBox3.AllowDrop = True
    9.         PictureBox4.AllowDrop = True
    10.         PictureBox5.AllowDrop = True
    11.         PictureBox6.AllowDrop = True
    12.         PictureBox7.AllowDrop = True
    13.         PictureBox8.AllowDrop = True
    14.         PictureBox9.AllowDrop = True
    15.         PictureBox1.Tag = 3
    16.         PictureBox2.Tag = 4
    17.         PictureBox3.Tag = 5
    18.         PictureBox4.Tag = 6
    19.         PictureBox5.Tag = 7
    20.         PictureBox6.Tag = 8
    21.         PictureBox7.Tag = 9
    22.         PictureBox8.Tag = 10
    23.         PictureBox9.Tag = 11
    24.         cardOrder = (From pb In Me.Controls.OfType(Of PictureBox)() _
    25.                     Order By pb.Left _
    26.                     Select CInt(pb.Tag)).ToArray
    27.     End Sub
    28.  
    29.     'integer array that holds value of cards from left (element 0) to right (element 8)
    30.     Dim cardOrder() As Integer
    31.  
    32.     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
    33.         Dim target As PictureBox = DirectCast(sender, PictureBox)
    34.         If e.Data.GetDataPresent(DataFormats.Bitmap) Then
    35.             Dim sourceCardTag As Integer = CInt(source.Tag)
    36.             source.Image = target.Image
    37.             source.Tag = target.Tag
    38.             target.Image = DirectCast(e.Data.GetData(DataFormats.Bitmap), Bitmap)
    39.             target.Tag = sourceCardTag
    40.             cardOrder = (From pb In Me.Controls.OfType(Of PictureBox)() _
    41.                     Order By pb.Left _
    42.                     Select CInt(pb.Tag)).ToArray
    43.         End If
    44.     End Sub
    45.  
    46.     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
    47.         'make sure drag drop data can be used
    48.         If e.Data.GetDataPresent(DataFormats.Bitmap) And e.AllowedEffect = DragDropEffects.Move Then
    49.             e.Effect = DragDropEffects.Move
    50.         Else
    51.             e.Effect = DragDropEffects.None
    52.         End If
    53.     End Sub
    54.  
    55.     Dim source As PictureBox
    56.     Dim image As Bitmap
    57.  
    58.     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
    59.         source = DirectCast(sender, PictureBox)
    60.         image = DirectCast(source.Image.Clone, Bitmap)
    61.         source.DoDragDrop(image, DragDropEffects.Move)
    62.     End Sub
    63.  
    64.     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
    65.         e.UseDefaultCursors = False
    66.         Dim EffectCursor As New Cursor(New IO.MemoryStream(My.Resources.Move))
    67.         Dim img As New Bitmap(15 + image.Width, 26 + image.Height)
    68.         Dim gr As Graphics = Graphics.FromImage(img)
    69.         gr.FillRectangle(Brushes.Magenta, img.GetBounds(Drawing.GraphicsUnit.Pixel))
    70.         EffectCursor.Draw(gr, New Rectangle(0, 0, _
    71.             EffectCursor.Size.Width, EffectCursor.Size.Height))
    72.         gr.DrawImage(image, 15, 26, image.Width, image.Height)
    73.         img.MakeTransparent(Color.Magenta)
    74.         Cursor.Current = CreateCursor(img)
    75.     End Sub
    76.  
    77. #Region "   CreateIconIndirect"
    78.  
    79.     Private Structure IconInfo
    80.         Public fIcon As Boolean
    81.         Public xHotspot As Int32
    82.         Public yHotspot As Int32
    83.         Public hbmMask As IntPtr
    84.         Public hbmColor As IntPtr
    85.     End Structure
    86.  
    87.     <DllImport("user32.dll", EntryPoint:="CreateIconIndirect")> _
    88.     Private Shared Function CreateIconIndirect(ByVal iconInfo As IntPtr) As IntPtr
    89.     End Function
    90.  
    91.     <DllImport("user32.dll", CharSet:=CharSet.Auto)> _
    92.     Public Shared Function DestroyIcon(ByVal handle As IntPtr) As Boolean
    93.     End Function
    94.  
    95.     <DllImport("gdi32.dll")> _
    96.     Public Shared Function DeleteObject(ByVal hObject As IntPtr) As Boolean
    97.     End Function
    98.  
    99.     ''' <summary>
    100.     ''' CreateCursor
    101.     ''' </summary>
    102.     ''' <param name="bmp"></param>
    103.     ''' <returns>custom Cursor</returns>
    104.     ''' <remarks>creates a custom cursor from a bitmap</remarks>
    105.     Public Function CreateCursor(ByVal bmp As Bitmap) As Cursor
    106.         'Setup the Cursors IconInfo
    107.         Dim tmp As New IconInfo
    108.         tmp.xHotspot = 0
    109.         tmp.yHotspot = 0
    110.         tmp.fIcon = False
    111.         tmp.hbmMask = bmp.GetHbitmap()
    112.         tmp.hbmColor = bmp.GetHbitmap()
    113.  
    114.         'Create the Pointer for the Cursor Icon
    115.         Dim pnt As IntPtr = Marshal.AllocHGlobal(Marshal.SizeOf(tmp))
    116.         Marshal.StructureToPtr(tmp, pnt, True)
    117.         Dim curPtr As IntPtr = CreateIconIndirect(pnt)
    118.  
    119.         'Clean Up
    120.         DestroyIcon(pnt)
    121.         DeleteObject(tmp.hbmMask)
    122.         DeleteObject(tmp.hbmColor)
    123.  
    124.         Return New Cursor(curPtr)
    125.     End Function
    126.  
    127. #End Region
    128.  
    129. End Class

  6. #6
    Member rockyamyx's Avatar
    Join Date
    Nov 10
    Posts
    57

    Re: what do i use to....

    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??

  7. #7
    vb Coda .paul.'s Avatar
    Join Date
    May 07
    Location
    Chelmsford UK
    Posts
    16,471

    Re: what do i use to....

    Quote Originally Posted by rockyamyx View Post
    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??
    yes. use the picturebox's tag property

  8. #8
    Member rockyamyx's Avatar
    Join Date
    Nov 10
    Posts
    57

    Re: what do i use to....

    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??

  9. #9

  10. #10
    Member rockyamyx's Avatar
    Join Date
    Nov 10
    Posts
    57

    Re: what do i use to....

    ahhh now i see thank you

  11. #11
    Member rockyamyx's Avatar
    Join Date
    Nov 10
    Posts
    57

    Re: what do i use to....

    Quote Originally Posted by .paul. View Post
    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...

    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

  12. #12
    PowerPoster cicatrix's Avatar
    Join Date
    Dec 09
    Location
    Moscow, Russia
    Posts
    3,588

    Re: what do i use to....

    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.

  13. #13
    Member rockyamyx's Avatar
    Join Date
    Nov 10
    Posts
    57

    Re: what do i use to....

    well i pretty much striped my program to figureout what i am going to do..

    so heres the bare minimum



    VB.NET Code:
    1. Imports System.Runtime.InteropServices
    2.  
    3.  
    4. Public Class ArrangeDiceForm
    5.     Dim lucky_3_1_str As String = "Lucky 3-Card Bonus"
    6.         Dim lucky_3_2_str As String = "Lucky 3-Card Bonus"
    7.         Dim lucky_4_1_str As String = "Lucky 4-Card Bonus"
    8.         Dim lucky_4_2_str As String = "Lucky 4-Card Bonus"
    9.         Dim lucky_5_1_str As String = "Lucky 5-Card Bonus"
    10.         Dim lucky_5_2_str As String = "Lucky 5-Card Bonus"
    11.         Dim lucky3 As Boolean = False
    12.         Dim lucky11 As Boolean = False
    13.         Dim lucky_3_1_bool As Boolean = False
    14.         Dim lucky_3_2_bool As Boolean = False
    15.         Dim lucky_4_1_bool As Boolean = False
    16.         Dim lucky_4_2_bool As Boolean = False
    17.         Dim lucky_5_1_bool As Boolean = False
    18.         Dim lucky_5_2_bool As Boolean = False
    19.         Dim pinzoro_int As Integer = 0
    20.         Dim turn As Integer = 0
    21.         Dim random As Random = New Random()
    22.         Dim cardOrder() As Integer 'Called at Form1_Load
    23.     '##########END DIMS########'
    24.  
    25.  
    26.     '######ArrangeDice LOAD######
    27.     Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    28.  
    29.  
    30.         PictureBox1.AllowDrop = True
    31.         PictureBox2.AllowDrop = True
    32.         PictureBox3.AllowDrop = True
    33.         PictureBox4.AllowDrop = True
    34.         PictureBox5.AllowDrop = True
    35.         PictureBox6.AllowDrop = True
    36.         PictureBox7.AllowDrop = True
    37.         PictureBox8.AllowDrop = True
    38.         PictureBox9.AllowDrop = True
    39.         PictureBox1.Tag = 3
    40.         PictureBox2.Tag = 4
    41.         PictureBox3.Tag = 5
    42.         PictureBox4.Tag = 6
    43.         PictureBox5.Tag = 7
    44.         PictureBox6.Tag = 8
    45.         PictureBox7.Tag = 9
    46.         PictureBox8.Tag = 10
    47.         PictureBox9.Tag = 11
    48.         cardOrder = (From pb In Me.Controls.OfType(Of PictureBox)() _
    49.                     Order By pb.Left _
    50.                     Select CInt(pb.Tag)).ToArray
    51.     End Sub
    52.     '######ARRANGE DICE LOAD END'#######
    53.     '##########CARD SWAP########'
    54. #Region "Card Swap"
    55.     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
    56.         Dim target As PictureBox = DirectCast(sender, PictureBox)
    57.         If e.Data.GetDataPresent(DataFormats.Bitmap) Then
    58.             Dim sourceCardTag As Integer = CInt(source.Tag)
    59.             source.Image = target.Image
    60.             target.Image = DirectCast(e.Data.GetData(DataFormats.Bitmap), Bitmap)
    61.             target.Tag = sourceCardTag
    62.             cardOrder = (From pb In Me.Controls.OfType(Of PictureBox)() _
    63.                     Order By pb.Left _
    64.                     Select CInt(pb.Tag)).ToArray
    65.         End If
    66.     End Sub
    67.  
    68.     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
    69.         'make sure drag drop data can be used
    70.  
    71.         If e.Data.GetDataPresent(DataFormats.Bitmap) And e.AllowedEffect = DragDropEffects.Move Then
    72.             e.Effect = DragDropEffects.Move
    73.         Else
    74.             e.Effect = DragDropEffects.None
    75.  
    76.         End If
    77.  
    78.     End Sub
    79.  
    80.     Dim source As PictureBox
    81.     Dim image As Bitmap
    82.  
    83.     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
    84.         source = DirectCast(sender, PictureBox)
    85.         image = DirectCast(source.Image.Clone, Bitmap)
    86.         source.DoDragDrop(image, DragDropEffects.Move)
    87.     End Sub
    88.  
    89.     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
    90.         e.UseDefaultCursors = False
    91.         Dim EffectCursor As New Cursor(New IO.MemoryStream(My.Resources.Move))
    92.         Dim img As New Bitmap(15 + image.Width, 26 + image.Height)
    93.         Dim gr As Graphics = Graphics.FromImage(img)
    94.         gr.FillRectangle(Brushes.Magenta, img.GetBounds(Drawing.GraphicsUnit.Pixel))
    95.         EffectCursor.Draw(gr, New Rectangle(50, 50, _
    96.             EffectCursor.Size.Width, EffectCursor.Size.Height))
    97.         gr.DrawImage(image, 15, 26, image.Width, image.Height)
    98.         img.MakeTransparent(Color.Magenta)
    99.         Cursor.Current = CreateCursor(img)
    100.     End Sub
    101.  
    102. #Region "   CreateIconIndirect"
    103.  
    104.     Private Structure IconInfo
    105.         Public fIcon As Boolean
    106.         Public xHotspot As Int32
    107.         Public yHotspot As Int32
    108.         Public hbmMask As IntPtr
    109.         Public hbmColor As IntPtr
    110.     End Structure
    111.  
    112.     <DllImport("user32.dll", EntryPoint:="CreateIconIndirect")> _
    113.     Private Shared Function CreateIconIndirect(ByVal iconInfo As IntPtr) As IntPtr
    114.     End Function
    115.  
    116.     <DllImport("user32.dll", CharSet:=CharSet.Auto)> _
    117.     Public Shared Function DestroyIcon(ByVal handle As IntPtr) As Boolean
    118.     End Function
    119.  
    120.     <DllImport("gdi32.dll")> _
    121.     Public Shared Function DeleteObject(ByVal hObject As IntPtr) As Boolean
    122.     End Function
    123.  
    124.     '''<summary>
    125.     ''' CreateCursor
    126.     ''' </summary>
    127.     ''' <param name="bmp"></param>
    128.     ''' <returns>custom Cursor</returns>
    129.     '''<remarks>creates a custom cursor from a bitmap</remarks>
    130.     Public Function CreateCursor(ByVal bmp As Bitmap) As Cursor
    131.         'Setup the Cursors IconInfo
    132.         Dim tmp As New IconInfo
    133.         tmp.xHotspot = 50
    134.         tmp.yHotspot = 50
    135.         tmp.fIcon = False
    136.         tmp.hbmMask = bmp.GetHbitmap()
    137.         tmp.hbmColor = bmp.GetHbitmap()
    138.  
    139.         'Create the Pointer for the Cursor Icon
    140.         Dim pnt As IntPtr = Marshal.AllocHGlobal(Marshal.SizeOf(tmp))
    141.         Marshal.StructureToPtr(tmp, pnt, True)
    142.         Dim curPtr As IntPtr = CreateIconIndirect(pnt)
    143.  
    144.         'Clean Up
    145.         DestroyIcon(pnt)
    146.         DeleteObject(tmp.hbmMask)
    147.         DeleteObject(tmp.hbmColor)
    148.  
    149.         Return New Cursor(curPtr)
    150.     End Function
    151.  
    152. #End Region
    153.  
    154. #End Region
    155.  
    156.  
    157.  
    158.  
    159.  
    160.     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
    161.         Label3.Text = PictureBox1.Tag
    162.         Label4.Text = PictureBox2.Tag
    163.         Label5.Text = PictureBox3.Tag
    164.         Label6.Text = PictureBox4.Tag
    165.         Label7.Text = PictureBox5.Tag
    166.         Label8.Text = PictureBox6.Tag
    167.         Label9.Text = PictureBox7.Tag
    168.         Label10.Text = PictureBox8.Tag
    169.         Label11.Text = PictureBox9.Tag
    170.     End Sub
    171. 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

  14. #14
    Member rockyamyx's Avatar
    Join Date
    Nov 10
    Posts
    57

    Re: what do i use to....

    any suggestions??

  15. #15

  16. #16
    Member rockyamyx's Avatar
    Join Date
    Nov 10
    Posts
    57

    Re: what do i use to....

    no no.. i just used those to tell if the swap code was working

  17. #17

  18. #18
    Member rockyamyx's Avatar
    Join Date
    Nov 10
    Posts
    57

    Re: what do i use to....

    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:
    1. if picturebox9.tag = rollsum then
    2. 'do somthing'
    3. else if picturebox8.tag = rollsum then
    4. 'do somthing'
    5. else if picturebox7.tag = rollsum then
    6. 'do somthing'
    7. else if picturebox6.tag = rollsum then
    8. 'do somthing'
    9. else if picturebox5.tag = rollsum then
    10. 'do somthing'
    11. else if picturebox4.tag = rollsum then
    12. 'do somthing'
    13. else if picturebox3.tag = rollsum then
    14. 'do somthing'
    15. end if


    would that work??.. or cause problems down the road?

  19. #19
    New Member
    Join Date
    Jul 09
    Posts
    3

    Re: what do i use to....

    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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •