can you help

Keep in mind that i named my label to box

 

1.                  If we want to keep the box within the boundaries, then we must have a way to test whether the box is moving out of the boundaries.

 

a.      Which properties of the box would you use to check

b.      Which properties of the boundaries would you use to check

 

2.                  If the box is detected to be outside of the boundaries, what possible corrective actions could you take

 

And the most important Question is. --

How do you make the box 'Bounce'/ move to the opposite  side of the panel when it touched the boundary.

 example when it touched to the left most side..it automaticly goes right.

 

But i know its something to do with          if condition then bla bla bla end 

 

help will be greatly appreciated !!!€



Answer this question

can you help

  • silkkeng

    Okay thx i've solved the problem already !!!

    and now i have another problem lol. okay ive made 2 panels now each X and Y values how do i put in the values of my box coordinates

    Private Sub LabelX_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles LabelX.Click

    End Sub

    And

    Private Sub LabelY_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles LabelY.Click

    End Sub

    and my box coordinate is (134, 129).


  • Quirk

    Who are you asking Renee was pointing out that there's a sticky post on the top of the forum with advice on how to give better info in your questions. If you're asking me for more info, I would recommend you read the post Renee is talking about, you've not given me much info to use to help you. Which bit are you stuck on Do you need to know how to write the code Do you need to know where to put the code



  • flinxperbil

    box.Left will set the controls position on the form, relative to the far left.



  • bennykfc

    Hi Haran,

    Welcome to the MSDN forums. I hope you take a minute and read the suggestions at the top of the forum for how to get an Optimal answer.



  • IvanP

    1. You would be using the top, left, width and height properties to calculate the space the textbox is occupying. You would be using these properties on both controls.

    2. Move it back into within the boundaries of the containing control.

    3. Your logic for you application which moves the textbox within a containing control would have some logic to determine whether it is incrementing the left and top properties of the texbox control. To determine the direction of movement. When it reaches the boundary then it will reverse direction by reversing the action on these properties so instead of incrementing the left and top properties it will decrement them.

    The best way to get a response is to write some code and then show us what youve done and we'll try and help.


  • BMONSTER

    i need help.
    i have assigned a direction to a button "e"box.text = east
    and need to move it to the right with another button.but i cant seem to be able to figure out the command.
    can you help

  • Chris Clements

    thank you but could u please explain a little further


  • Mark Tomlinson - MSFT

    ok i see. im really sorry. its my first time using this forum. i dun know what is the code that i have to use to make the box react to one button which tells it to change the text on it. After that use another button to move the box.
    ok for example, an four arrow buttons are placed but these arrow buttons do nothing but change the text in the box, then there is another button, named move. so this button is the one that has to move the box but the arrow buttons determine the direction. im sorry that its so long but i didnt know any other way to explain.

  • Mr pinchy

    i got that far as you've said.
    i got another question,i set a box in a panel and i want it to be bounded by the panel so that it does not go over it and sort of "bounces" backand move to the other direction

  • Latso

    That's fine, I could see you were new, and that's no crime :-) Welcome to the forums, BTW.

    OK, the first step is to add a button, you do that in the designer. You can now double click on the button in the designer, and it will add code that will be called when the button is pressed. This is called an event handler.

    Inside this code, you can set the Text property to change the text on your control, or the Left or Top properties to change it's position.

    In order to move the control with the arrow keys, you'd need to catch keyboard events on the form. The properties for your selected control or form have a page which lists events, you get to that by clicking on the lighting flash at the top. Then, you can enter a function name next to the event you want to catch. In this case, it's one of the Key events you want. Then you can check the key value passed in the event args to respond to key presses to set the same properties I mention above.



  • holthaus

    Public Class Form1

    Protected Friend WithEvents cbLeft As New Button

    Protected Friend WithEvents cbright As New Button

    Protected tb As New TextBox

    Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

    cbLeft.Name = "cbleft" : cbright.Name = "cbright"

    Me.Controls.Add(cbLeft)

    Me.Controls.Add(cbright)

    Me.Controls.Add(tb)

    tb.Size = New Size(20, 20)

    tb.Location = New Point((Me.Width - 20) / 2, ((Me.Height - 20) / 2) - 20)

    cbLeft.Location = New Point(200, 200) : cbLeft.Text = "<"

    cbright.Location = New Point(300, 200) : cbright.Text = ">"

    End Sub

    Private Sub cbLeft_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles cbLeft.Click, cbright.Click

    Select Case sender.name

    Case "cbleft"

    If tb.Left > 0 Then tb.Left -= 20

    Case "cbright"

    If ((tb.Left + tb.Width) < Me.Width) Then tb.Left += 20

    End Select

    End Sub

    End Class



  • Luke B

    Bounces in what way By itself, or as you move it I would have expected if it's inside the panel, it's Left and Top would be relative to the panel, so you need to make sure it doesn't go past 0. Otherwise, use the Panel's left and top to check.



  • Render

    i have diffculity in my VB. i do not know the VB code for the boundaries. what is the VB code to control the moving box to "rebounce"
  • Lino

    can someone help me i really dunno what to do.

    i wanna know the VB code for making the movingbox not to hit the side of the panel


  • can you help