check if one control top edge is = another controls bottom edge

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

hi, i want to check each time a control, in this case a picturebox, moves to
see if its top edge is = another controls bottom edge, but the problem is i
dont kno what the second control will be. how can i achieve this? thanks
 
Create a function that checks, i.e.

Function chk_TopBot(pic as control, other as control)
if pic.Top = other.Top + other.Height then return True else return False
End Function

Note that you might want to convert the tops of both controls to screen
coordinates before checking if they don't have the same parent.
 
sorry if i didnt state my question clear enough...i dont kno exactly what the
other contorl will be, so i didnt kno if there was something that was like
"if control hits another control" or soemthing like that...like im moving a
picturebox according to a user and i wont kno if somehting will be above it
or not, so if there is, then i want it to stop when it hits the bottom, but i
dont kno exactly what the control will be
 
You can look at each control in your form for the control position.
Unfortunately, you do need to know what type of controls are on the
form so that you can access their properties. You can chaeck the
properties for top and height to find the bottom on a control.

This is untested, but the code should be something similar.

Dim Ctrl As Object
For Each Ctrl In Me.Controls
If Ctrl.GetType Is GetType(TextBox) Then
If CType(Ctrl, TextBox).Top + CType(Ctrl,TextBox).Height = somevalue
Then
CType(Ctrl, TextBox).Focus()
DoSomething
Exit For
End If
End If
If Ctrl.GetType Is GetType(Button) Then
If CType(Ctrl, Button).Top + CType(Ctrl,Button).Height = somevalue
Then
CType(Ctrl, Button).Focus()
DoSomething
Exit For
End If
End If
Next
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top