Jump to content

moving button question, help

- - - - -

This topic has been archived. This means that you cannot reply to this topic.
3 replies to this topic

#1
Paulo_Jorge

Paulo_Jorge

    Learning Programmer

  • Members
  • PipPipPip
  • 54 posts
hi, i'm new in this forum and i need help

i created a button in a vb form, and a make a simple code when pressing keys; like: when i press A , the button moves the left; when I press W the button moves up. like that, up, down, left and right. it works fine, i can move the button all around the form.

but the button also moves beyond the form borders. HOW I CAN I PREVENT THAT. if the buttons reach a border, it will stop move.

if you know anything please help. i'm using visual basic 2010

sorry for my english !!

#2
CommittedC0der

CommittedC0der

    Speaks fluent binary

  • Members
  • PipPipPipPipPipPipPipPip
  • 1,565 posts
Hi, paulo. Im no expert with VB, but you should be able to use a if statement, something to the effect of:
if button1.Location.X >= 1 Then
//Move button code here
ElseIf button1.Location.X <= 0 Then
button1.Location.X = 0
EndIf
Im not sure that syntax is working, but you probably get it. You would place that in your key event, then do the same for the other sides of you form.

Hope you understand. ~ Committed. :)
A man can be defined by what he does when no one is looking.
Science is only an educated theory, which we cannot disprove.

#3
Paulo_Jorge

Paulo_Jorge

    Learning Programmer

  • Members
  • PipPipPip
  • 54 posts
thanks man,thats what i needed

just this : if button1.Location.X >= 1

i putted the code in here and it only works and X > 1. and of course with the others keys and positions.

thanks again

#4
Paulo_Jorge

Paulo_Jorge

    Learning Programmer

  • Members
  • PipPipPip
  • 54 posts
i have another program now with the my moving button. please read my 1st thread to understand my problem

when the button reach the left and the top border it stop, like i wanted. but i cant do the same with bottom and rigth border, AND I CANT UNDERSTAND WHY.

You can check my project here: "http://www.mediafire.com/?dh48gjeytvpf56a" PLEASE HELP, I NEED THIS