|
-
Nov 7th, 2001, 08:12 AM
#1
Thread Starter
Lively Member
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.
-
Nov 7th, 2001, 08:13 AM
#2
Conquistador
If Text1.Visible = True Then
'Scroll
-
Nov 7th, 2001, 08:42 AM
#3
Thread Starter
Lively Member
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
-
Nov 7th, 2001, 08:45 AM
#4
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:
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
??????????
The GotFocus event can't be raised for a TextBox that isn't visible!
-
Nov 7th, 2001, 08:56 AM
#5
Thread Starter
Lively Member
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?...
-
Nov 7th, 2001, 09:05 AM
#6
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.
-
Nov 7th, 2001, 09:15 AM
#7
Thread Starter
Lively Member
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.
-
Nov 7th, 2001, 09:21 AM
#8
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:
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
Best regards
-
Nov 7th, 2001, 01:59 PM
#9
Thread Starter
Lively Member
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:
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
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
-
Nov 7th, 2001, 03:07 PM
#10
Conquistador
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:
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
Best regards
I think he means when the user can't see it...
-
Nov 7th, 2001, 10:38 PM
#11
Thread Starter
Lively Member
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 !
-
Nov 8th, 2001, 02:00 AM
#12
Conquistador
I don't know what to do about this, sorry
-
Nov 8th, 2001, 04:17 AM
#13
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
-
Nov 9th, 2001, 07:45 AM
#14
Thread Starter
Lively Member
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
-
Nov 9th, 2001, 08:17 AM
#15
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
-
Nov 9th, 2001, 12:24 PM
#16
Thread Starter
Lively Member
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.
-
Nov 9th, 2001, 04:39 PM
#17
Fanatic Member
-
Nov 12th, 2001, 04:19 AM
#18
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:
Private Sub Text1_GotFocus(Index As Integer)
With Text1(Index)
If (.Top <= -.Height Or .Top > Frame2.Height) Or (.Left <= -.Width Or .Left > Frame2.Width) Then
MsgBox "Iam out of bound"
End If
End Sub
Best regards
-
Nov 12th, 2001, 09:56 AM
#19
Thread Starter
Lively Member
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:
Private Sub Text1_GotFocus(Index As Integer)
With Text1(Index)
If (.Top <= -.Height Or .Top > Frame2.Height) Or (.Left <= -.Width Or .Left > Frame2.Width) Then
MsgBox "Iam out of bound"
End If
End Sub
Best regards
I used the above code.....it is not working!...any other way out please?
-
Nov 12th, 2001, 10:02 AM
#20
Could you attach the form here so I can have a look at it.
-
Nov 12th, 2001, 12:30 PM
#21
Thread Starter
Lively Member
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.
-
Nov 13th, 2001, 05:45 AM
#22
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:
Private Declare Function GetWindowRect _
Lib "user32" ( _
ByVal hwnd As Long, _
lpRect As RECT) As Long
Private Type RECT
Left As Long
Top As Long
Right As Long
Bottom As Long
End Type
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) Or (.Right <= rMDI.Left Or .Left >= rMDI.Right) Then
MsgBox "I'am out of bound"
End If
End With
End Sub
Best regards
-
Nov 13th, 2001, 08:10 AM
#23
Fanatic Member
I love it when a plan comes together.
-
Nov 13th, 2001, 12:18 PM
#24
Thread Starter
Lively Member
[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
-
Nov 13th, 2001, 12:25 PM
#25
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|