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 !!
moving button question, help
Started by Paulo_Jorge, Feb 05 2011 10:10 AM
3 replies to this topic
#1
Posted 05 February 2011 - 10:10 AM
|
|
|
#2
Posted 05 February 2011 - 11:30 AM
Hi, paulo. Im no expert with VB, but you should be able to use a if statement, something to the effect of:
Hope you understand. ~ Committed. :)
if button1.Location.X >= 1 Then //Move button code here ElseIf button1.Location.X <= 0 Then button1.Location.X = 0 EndIfIm 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.
Science is only an educated theory, which we cannot disprove.
#3
Posted 05 February 2011 - 11:39 AM
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
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
Posted 05 February 2011 - 04:10 PM
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
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


Sign In
Create Account


Back to top









