Results 1 to 9 of 9

Thread: move a button w/ just a click

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Jun 2000
    Posts
    537
    I asked this in another area and did not get a response.
    but it IS a game question so I will ask it here.

    I have some command buttons on my form and they are inside picture box's. one of the picture box's is empty(no button) and I want to be able to detect what one is empty, then put the command button that was clicked inside the empty picture box.

    does that make sense?

    there is more to it than that but right now i'm just trying to figure this part out.

    i hope you can make sense of that
    thanks
    pnj

  2. #2
    Guest
    Im not sure how to move a command button from one picture box to another, but you can move the picture box itself. Just switch the empty box with the box with the button.

    Z.

  3. #3

    Thread Starter
    Fanatic Member
    Join Date
    Jun 2000
    Posts
    537
    your right you can't move an object that is inside a picture box but you can move the picture box itself.(i just read that in the help files)

    but with my situation I have 16 picture box's and 15 have command buttons in them. the box's w/ buttons can only trade places with the the empty box if it is directly above ,below or to the left or right.

    the box's are laid out in a 4 by 4 grid.
    what i thought i could to is have a function that works somewhat like this:

    function Checker(index as integer)
    dim i
    i = index
    for i = i step 5
    if [the fifth box is empty] then
    command(i).move left[wherever the emtpy box is]
    emtpybox.move [wherever the button was]
    next

    end function

    I would need a function to check forward one box and also forward 5 box's
    then one to check back one box and back 5 box's

    I know the syntax is incorrect in that function and that is kind of my question.
    how do i tell the computer to check the fifth, or first box(starting from the right of the botton clicked) and see if the box is empty?

    I know I am not explaining this very well, sorry.

    thanks
    pnj

  4. #4
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    are you making some kind of puzzle game where you switch boxes until you have them all in order from 1 to 16? In that case why do you have both pictureboxes and command buttons?
    Use
    writing software in C++ is like driving rivets into steel beam with a toothpick.
    writing haskell makes your life easier:
    reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
    To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.

  5. #5

    Thread Starter
    Fanatic Member
    Join Date
    Jun 2000
    Posts
    537

    yes!

    I am doing that.
    what i have is 16 picture box's and 15 have buttons in them.I know I can write a bunch of code that checks
    for each possible movement and then i would have 16 different else/if statements but I thought
    i could write a function that would run some simple math.(see my crappy attemt in the other post in this
    thread)

    becouse the button pushed can only move if the empty button is directly to the left or right or if it is
    five to the left or right. if the picture box's are numbered 1 to 16.

    i think..... my problem is i'm not exactly sure of the syntax.
    i've looked in the books i have and in the help files but i'm not getting it....

    any suggestions kedaman?

    thanks
    pnj

  6. #6
    Guest
    Create a second array in the program, of Boolean
    values. This array should be 2 dimensional (a grid).
    every one of these elements should have a true value,
    except for the empty box. Then, you can use this code:
    Code:
    '// Direction values: 1 = Up, 2 = Down, 3 = Left, 4 = Right
    '// this code assumes there is a 2 dimensional array
    '// called locations defined as public, with rows from 0 -
    '// 3, and columns from 0 - 3.  It wont check if you
    '// are on an edge.  
    function checker(Boxindex as integer, direction as integer) as boolean
    Dim x as integer
    Dim y as integer
    '// get x and y values of the box
    if boxindex < 4 then
       y = 0: x = boxindex - 1
    else
       boxindex = boxindex - 4
       if boxindex > 4 then
             boxindex = boxindex - 4
             if boxindex > 4 then
                boxindex = boxindex - 4
                y = 3: x = boxindex - 1
             else
                y = 2: x = boxindex - 1
             end if
        else
           y = 1: x = boxindex - 1
        end if
    end if
    '// thats horrid code, but it works
    select case direction
    case 1:
    if Locations(x, y - 1) = true then
    checker = false
    exit function
    end if
    case 2:
    if Locations(x, y + 1) = true then
    checker = false
    exit function
    end if
    case 3:
    if Locations(x - 1, y) = true then
    checker = false
    exit function
    end if       
    case 4:
    if Locations(x + 1, y) = true then
    checker = false
    exit function
    end if
    end select
    '// if we got here, the box in the direction specified is empty
    checker = true
    end function
    that should work, but its all from the top of my head, so
    i dont know =).

    Z.

  7. #7

    Thread Starter
    Fanatic Member
    Join Date
    Jun 2000
    Posts
    537

    cool

    i'll give this a try when i get home from work....

    thanks a bunch.
    pnj

  8. #8
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    Skip the commandbuttons and stick to 16 pictureboxes, of a control array indexed from 0 to 15. you could for instance place a picture in each indicating their number.

    you should have a byte array indicating each number placed in the pictureboxes, let the pictureboxes stay while the numbers swaps when you click on them. Second you need a byte number indicating the empty picturebox index so that you can determine if a click should lead to a swap and if so with this index.
    Use
    writing software in C++ is like driving rivets into steel beam with a toothpick.
    writing haskell makes your life easier:
    reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
    To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.

  9. #9

    Thread Starter
    Fanatic Member
    Join Date
    Jun 2000
    Posts
    537
    ok kedaman i'll give it a try

    thanks
    pnj

Posting Permissions

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



Click Here to Expand Forum to Full Width