Results 1 to 25 of 25

Thread: is my text box visible?

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Nov 2001
    Posts
    120

    Angry is my text box visible?

    i am using a MDI application how can i find the if a componetn ie a text box i am focusing is visible or not?..
    If it is not visible i want to scroll the form.

  2. #2
    Conquistador
    Join Date
    Dec 1999
    Location
    Australia
    Posts
    4,527
    If Text1.Visible = True Then
    'Scroll

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Nov 2001
    Posts
    120
    Originally posted by da_silvy
    If Text1.Visible = True Then
    'Scroll

    Thanks da_silvy,

    It works, but it keep scrolling enven if the text box is visible, could you please tell me how can go about scrolling the form only when the text box which got focus is bewlow...or out of visibility....i used the folliwng code

    Private Sub Text1_GotFocus(Index As Integer)
    Dim NewTopValue As Long
    NewTopValue = Me.Top - 400
    If (Text1(Index).Visible = True) Then
    Me.Move Form1.Left, NewTopValue
    End If

    End Sub

  4. #4
    I'm about to be a PowerPoster! Joacim Andersson's Avatar
    Join Date
    Jan 1999
    Location
    Sweden
    Posts
    14,649
    Originally posted by manzoor
    It works, but it keep scrolling enven if the text box is visible, could you please tell me how can go about scrolling the form only when the text box which got focus is bewlow...or out of visibility....i used the folliwng code

    VB Code:
    1. Private Sub Text1_GotFocus(Index As Integer)
    2.     Dim NewTopValue As Long
    3.     NewTopValue = Me.Top - 400
    4.     If (Text1(Index).Visible = True) Then
    5.         Me.Move Form1.Left, NewTopValue
    6.     End If
    7. End Sub
    ??????????
    The GotFocus event can't be raised for a TextBox that isn't visible!

  5. #5

    Thread Starter
    Lively Member
    Join Date
    Nov 2001
    Posts
    120
    Originally posted by Joacim Andersson
    ??????????
    The GotFocus event can't be raised for a TextBox that isn't visible!
    How do i go about finding if a textbox/combobox is visible or not?...

  6. #6
    I'm about to be a PowerPoster! Joacim Andersson's Avatar
    Join Date
    Jan 1999
    Location
    Sweden
    Posts
    14,649
    Well you just check the controls Visible property as posted earlier. But checking it in the GotFocus event has no point since a control that isn't visible can't get the focus.

  7. #7

    Thread Starter
    Lively Member
    Join Date
    Nov 2001
    Posts
    120
    Originally posted by Joacim Andersson
    Well you just check the controls Visible property as posted earlier. But checking it in the GotFocus event has no point since a control that isn't visible can't get the focus.
    Yes ofcourse you can focus non visible control when one is using "Tab" to navigate the controles of the form...
    Now, when i hit TAB the conrol does get focused when it is not visible...

    I mean technically the component is visible...but practically it is not visible to the user...he has to scrolldown to see the component
    Last edited by manzoor; Nov 7th, 2001 at 09:19 AM.

  8. #8
    I'm about to be a PowerPoster! Joacim Andersson's Avatar
    Join Date
    Jan 1999
    Location
    Sweden
    Posts
    14,649
    Originally posted by manzoor


    Yes ofcourse you can focus non visible control when one is using "Tab" to navigate the controles of the form...
    Now, when i hit TAB the conrol does get focused when it is not visible...
    No! It doesn't! You can't set focus to a control which Visible property is set to False.
    But are you referring to a control that isn't visible on the form itself because it's outside the forms boundery?
    In that case you'll use code simular to this:
    VB Code:
    1. If (Text1.Top <= -Text1.Height Or Text1.Top > Me.ScaleHeight) Or (Text1.Left <= -Text1.Width Or Text1.Left > Me.ScaleWidth) Then
    2.     '... move the control
    3. End If
    Best regards

  9. #9

    Thread Starter
    Lively Member
    Join Date
    Nov 2001
    Posts
    120
    Originally posted by Joacim Andersson
    No! It doesn't! You can't set focus to a control which Visible property is set to False.
    But are you referring to a control that isn't visible on the form itself because it's outside the forms boundery?
    In that case you'll use code simular to this:
    VB Code:
    1. If (Text1.Top <= -Text1.Height Or Text1.Top > Me.ScaleHeight) Or (Text1.Left <= -Text1.Width Or Text1.Left > Me.ScaleWidth) Then
    2.     '... move the control
    3. End If
    Best regards
    Oh yes this works but my controles are put in differnt Frames, how can i reffer them?..
    And my the me.ScaleHeight always returns smame number..ie 3912, how can i find out if the contorl is within boundry of the wondow

  10. #10
    Conquistador
    Join Date
    Dec 1999
    Location
    Australia
    Posts
    4,527
    Originally posted by Joacim Andersson
    No! It doesn't! You can't set focus to a control which Visible property is set to False.
    But are you referring to a control that isn't visible on the form itself because it's outside the forms boundery?
    In that case you'll use code simular to this:
    VB Code:
    1. If (Text1.Top <= -Text1.Height Or Text1.Top > Me.ScaleHeight) Or (Text1.Left <= -Text1.Width Or Text1.Left > Me.ScaleWidth) Then
    2.     '... move the control
    3. End If
    Best regards
    I think he means when the user can't see it...

  11. #11

    Thread Starter
    Lively Member
    Join Date
    Nov 2001
    Posts
    120
    Originally posted by da_silvy

    I think he means when the user can't see it...
    Yes you are right Da_silvy, I mean when the user cant see the component, since it is out of boundry. but is visiblity value is set to trure.
    But the above code is not working !

  12. #12
    Conquistador
    Join Date
    Dec 1999
    Location
    Australia
    Posts
    4,527
    I don't know what to do about this, sorry

  13. #13
    I'm about to be a PowerPoster! Joacim Andersson's Avatar
    Join Date
    Jan 1999
    Location
    Sweden
    Posts
    14,649
    Originally posted by manzoor


    Oh yes this works but my controles are put in differnt Frames, how can i reffer them?..
    And my the me.ScaleHeight always returns smame number..ie 3912, how can i find out if the contorl is within boundry of the wondow
    The Me keyword refers to the form. The ScaleHeight is the client height of the form (i.e the height of the area where you can put controls. Not counting the TitleBar or any MenuBar).
    So Me.ScaleHeight should produce the same number if you haven't resized the form.
    If your textboxes are in frames you should move the frame instead of the textbox.
    Simply replace Text1 with the name of the frame in the code I previously posted.

    Best regards

  14. #14

    Thread Starter
    Lively Member
    Join Date
    Nov 2001
    Posts
    120
    Originally posted by Joacim Andersson
    The Me keyword refers to the form. The ScaleHeight is the client height of the form (i.e the height of the area where you can put controls. Not counting the TitleBar or any MenuBar).
    So Me.ScaleHeight should produce the same number if you haven't resized the form.
    If your textboxes are in frames you should move the frame instead of the textbox.
    Simply replace Text1 with the name of the frame in the code I previously posted.

    Best regards
    If (Text1.Top <= -Text1.Height Or Text1.Top > Me.ScaleHeight) Or (Text1.Left <= -Text1.Width Or Text1.Left > Me.ScaleWidth) Then
    '... move the control
    End If

    Ok, after replaceing Text1 by Frame
    In the above code, the condition Frame1(1).Top > Me.ScaleHeight is never met, even when the Frame1(1) is out of boundry of the window..
    Because my Me.scaleHeighe is always 31200 and the Frame1(i) values are always less than 31200.
    So the above code is not helping me find out if the component is within the boundry or not!!!.
    I wonder if i change scaleHeight value (in the property window ) of my form nothing happens!..i am not clear what is the use of scaleHeight.

    Thanks

  15. #15
    I'm about to be a PowerPoster! Joacim Andersson's Avatar
    Join Date
    Jan 1999
    Location
    Sweden
    Posts
    14,649
    Is the frame itself in an other container (like an other frame or picturebox) or is it placed directly on the form?
    Where is the code itself placed?
    Is it placed in the form that owns the frame or is it placed in another form or module?
    If it's in an other form or module you have to change the Me keyword to the name of the form.
    If the code is placed in the MDI form you can also use the ActiveForm method instead of the Me keyword (if the form that owns the frame is a MDIChild form that is).

    Best regards

  16. #16

    Thread Starter
    Lively Member
    Join Date
    Nov 2001
    Posts
    120
    Originally posted by Joacim Andersson
    Is the frame itself in an other container (like an other frame or picturebox) or is it placed directly on the form?
    Where is the code itself placed?
    Is it placed in the form that owns the frame or is it placed in another form or module?
    If it's in an other form or module you have to change the Me keyword to the name of the form.
    If the code is placed in the MDI form you can also use the ActiveForm method instead of the Me keyword (if the form that owns the frame is a MDIChild form that is).

    Best regards
    Here the scale down version of my project
    1.MDIForm
    2.Form1 which is the child to MDIForm
    3.Form1 has two frames it Frame1 and Frame2, these two frames have some text boxes.
    This is the code i have included
    Private Sub Text1_GotFocus(Index As Integer)
    If (Frame2.Top <= -Frame2.Height Or Frame2.Top > Me.ScaleHeight) Or (Frame2.Left <= -Frame2.Width Or Frame2.Left > Me.ScaleWidth) Then
    MsgBox "Iam out of bound"
    End If
    End Sub

    When the Frame2 is out of boundary and the Tab has foucsed the textbox in Frame2, i am expecting the messagebox pop up.
    Please have a look at the attached project in zip format.

  17. #17
    Fanatic Member JPicasso's Avatar
    Join Date
    Aug 2001
    Location
    Kalamazoo, MI
    Posts
    843
    Man,

    This is giving me a headache.

    I get it to work if you're tabbed control is BELOW or to the
    RIGHT of visible area, but if the scroll bars are not
    at the top and left, the code craps out....

    we need a way to get the scroll position from an mdi scrollbar.

    I know its available on a bmp...

    anyway, I'm going home. and I'm gonna drink a lot.

    The key is getting the scroll position on a MDI form.

    remember the tooth... the tooth..


    Merry Christmas

  18. #18
    I'm about to be a PowerPoster! Joacim Andersson's Avatar
    Join Date
    Jan 1999
    Location
    Sweden
    Posts
    14,649
    If the frames themself isn't moved but the textboxes in the frames are then use the following code (which assumes that all TextBoxes named Text1(x) are placed on Frame2)
    VB Code:
    1. Private Sub Text1_GotFocus(Index As Integer)
    2.     With Text1(Index)
    3.     If (.Top <= -.Height Or .Top > Frame2.Height) Or (.Left <= -.Width Or .Left > Frame2.Width) Then
    4.         MsgBox "Iam out of bound"
    5.     End If
    6. End Sub
    Best regards

  19. #19

    Thread Starter
    Lively Member
    Join Date
    Nov 2001
    Posts
    120
    Originally posted by Joacim Andersson
    If the frames themself isn't moved but the textboxes in the frames are then use the following code (which assumes that all TextBoxes named Text1(x) are placed on Frame2)
    VB Code:
    1. Private Sub Text1_GotFocus(Index As Integer)
    2.     With Text1(Index)
    3.     If (.Top <= -.Height Or .Top > Frame2.Height) Or (.Left <= -.Width Or .Left > Frame2.Width) Then
    4.         MsgBox "Iam out of bound"
    5.     End If
    6. End Sub
    Best regards
    I used the above code.....it is not working!...any other way out please?

  20. #20
    I'm about to be a PowerPoster! Joacim Andersson's Avatar
    Join Date
    Jan 1999
    Location
    Sweden
    Posts
    14,649
    Could you attach the form here so I can have a look at it.

  21. #21

    Thread Starter
    Lively Member
    Join Date
    Nov 2001
    Posts
    120
    Originally posted by Joacim Andersson
    Could you attach the form here so I can have a look at it.
    Please find the attached zip file.

  22. #22
    I'm about to be a PowerPoster! Joacim Andersson's Avatar
    Join Date
    Jan 1999
    Location
    Sweden
    Posts
    14,649
    OK! Now I understand what you want to do.
    The MDI child form might be partly outside the MDI form so a textbox might not be seen.
    I've changed the code a bit and used the GetWindowRect API function.
    This function will get the bounding rectangle of any Window or control relative to the upper-left corner of the screen.
    Then I used almost the same code as before but used the rectangle of the TextBox and the MDI form instead.
    VB Code:
    1. Private Declare Function GetWindowRect _
    2.  Lib "user32" ( _
    3.  ByVal hwnd As Long, _
    4.  lpRect As RECT) As Long
    5.  
    6. Private Type RECT
    7.     Left As Long
    8.     Top As Long
    9.     Right As Long
    10.     Bottom As Long
    11. End Type
    12.  
    13. Private Sub Text1_GotFocus(Index As Integer)
    14.     Dim rTextBox As RECT
    15.     Dim rMDI As RECT
    16.    
    17.     GetWindowRect Text1(Index).hwnd, rTextBox
    18.     GetWindowRect MDIForm1.hwnd, rMDI
    19.     With rTextBox
    20.         If (.Bottom <= rMDI.Top Or .Top >= rMDI.Bottom) Or (.Right <= rMDI.Left Or .Left >= rMDI.Right) Then
    21.             MsgBox "I'am out of bound"
    22.         End If
    23.     End With
    24. End Sub
    Best regards

  23. #23
    Fanatic Member JPicasso's Avatar
    Join Date
    Aug 2001
    Location
    Kalamazoo, MI
    Posts
    843

    I love it when a plan comes together.

    Joacim Andersson,

    Nice.
    Merry Christmas

  24. #24

    Thread Starter
    Lively Member
    Join Date
    Nov 2001
    Posts
    120
    [QUOTE]Originally posted by Joacim Andersson
    [B]OK! Now I understand what you want to do.
    The MDI child form might be partly outside the MDI form so a textbox might not be seen.
    I've changed the code a bit and used the GetWindowRect API function.
    This function will get the bounding rectangle of any Window or control relative to the upper-left corner of the screen.
    Then I used almost the same code as before but used the rectangle of the TextBox and the MDI form instead.

    Wow it works !!..Thanks a lot Joacim Andersson .
    I modified your code to scroll the form Vertically and horizontally,
    but i am unable to scroll the from exactly to the hidden component.
    Please look at the code and suggest any changes.

    Private Sub Text1_GotFocus(Index As Integer)
    Dim rTextBox As RECT
    Dim rMDI As RECT

    GetWindowRect Text1(Index).hwnd, rTextBox
    GetWindowRect MDIForm1.hwnd, rMDI


    With rTextBox
    If (.Bottom <= rMDI.Top Or .Top >= rMDI.Bottom) Then
    MsgBox "I'am out of bound vertivally " & Index
    Me.Move 0, -(.Top + .Bottom) * 6, Me.Width, Me.height
    Text1(Index).SetFocus

    End If
    If (.Right <= rMDI.Left Or .Left >= rMDI.Right) Then
    MsgBox "I'am out of bound horizotally " & Index
    Me.Move -(.Left + .Right), 0, Me.Width + (rMDI.Left + rMDI.Right), Me.height
    Text1(Index).SetFocus
    End If


    End With
    End Sub

  25. #25
    I'm about to be a PowerPoster! Joacim Andersson's Avatar
    Join Date
    Jan 1999
    Location
    Sweden
    Posts
    14,649
    The bounding rectangle in rTextBox and rMDI are mesured in pixels not twips.
    The Move method of the form will do the movement in Twips mesurment.
    You have to recalculate the rectangles by using Screen.TwipsPerPixelsX and Screen.TwipsPerPixelsY.

    Best regards

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