How to scroll to text box when keyboard is displayed

T

The Mad Ape

I have code in the GotFocus event that will display the virtual
keyboard when the focused object is a textbox. Not a problem, works
like a charm.

However if the next box is obscured by the keyboard I can not get the
autoscroll to work.

Here is the code to scroll to the textbox:

Private Sub txt1_LostFocus (ByVal sender As Objectm ByVal e As
System.EventArgs) Handles txt1.LostFocus

'This section just closes the Keyboard upon losing focus to this text
box. It works fine
If not InputPanel1 is Nothing Then
If InputPanel1.Enabled = True Then
InputPanel1.Enabled = False
End If
End If

'This does not work
If txt2.Visible = True Then
txt2.Focus()
txt2.ScrollToCaret()
End If

Also For your info I have this code in the GotFocus for txt2
If not InputPanel1 is Nothing Then
If InputPanel1.Enabled = False Then
InputPanel1.Enabled = True
End If
End If

Any ideas? There are other objects above these textboxes so by the
time the use gets to them, they have to enter data, scroll down to the
next one and enter data. It does set the focus on txt2 but it does not
scroll to it.

How can I fix this?

Thanks

TMA
 
T

The Mad Ape

I have code in the GotFocus event that will display the virtual
keyboard when the focused object is a textbox. Not a problem, works
like a charm.

However if the next box is obscured by the keyboard I can not get the
autoscroll to work.

Here is the code to scroll to the textbox:

Private Sub txt1_LostFocus (ByVal sender As Objectm ByVal e As
System.EventArgs) Handles txt1.LostFocus

'This section just closes the Keyboard upon losing focus to this text
box. It works fine
    If not InputPanel1 is Nothing Then
       If InputPanel1.Enabled = True Then
          InputPanel1.Enabled = False
       End If
   End If

'This does not work
   If txt2.Visible = True Then
     txt2.Focus()
     txt2.ScrollToCaret()
   End If

Also For your info I have this code in the GotFocus for txt2
    If not InputPanel1 is Nothing Then
       If InputPanel1.Enabled = False Then
          InputPanel1.Enabled = True
       End If
   End If

Any ideas? There are other objects above these textboxes so by the
time the use gets to them, they have to enter data, scroll down to the
next one and enter data. It does set the focus on txt2 but it does not
scroll to it.

How can I fix this?

Thanks

TMA

I should also point out that the textboxes exist in a tab in Form 2.
I have used the EnabledChanged feature of the InputPanel to adjust
form size and scrolling.



Private Sub InputPanel1_EnabledChanged(ByVal sender As
System.Object, ByVal e As System.EventArgs) Handles
InputPanel1.EnabledChanged
If InputPanel1.Enabled = False Then
For Each tbPge In tabCruise.TabPages
tbPge.AutoScroll = False
Next

tabCruise.Height = 267
tabCruise.Width = 240
Else
' The SIP is enabled, so the height of the tab control
' is set to the height of the visible desktop area.
For Each tbPge In tabCruise.TabPages
tbPge.AutoScroll = True
tbPge.AutoScrollMargin = New Size(5, 5)
Next

tabCruise.Height = InputPanel1.VisibleDesktop.Height
tabCruise.Width = InputPanel1.VisibleDesktop.Width
End If
End Sub
 
P

Paul G. Tobey [eMVP]

Wait, you want to tab to the next text box or move the text in a given text
box? Windows on Windows CE work basically just like they do on the desktop
(Tab to the next one, use the Down arrow to scroll).

Paul T.

I have code in the GotFocus event that will display the virtual
keyboard when the focused object is a textbox. Not a problem, works
like a charm.

However if the next box is obscured by the keyboard I can not get the
autoscroll to work.

Here is the code to scroll to the textbox:

Private Sub txt1_LostFocus (ByVal sender As Objectm ByVal e As
System.EventArgs) Handles txt1.LostFocus

'This section just closes the Keyboard upon losing focus to this text
box. It works fine
If not InputPanel1 is Nothing Then
If InputPanel1.Enabled = True Then
InputPanel1.Enabled = False
End If
End If

'This does not work
If txt2.Visible = True Then
txt2.Focus()
txt2.ScrollToCaret()
End If

Also For your info I have this code in the GotFocus for txt2
If not InputPanel1 is Nothing Then
If InputPanel1.Enabled = False Then
InputPanel1.Enabled = True
End If
End If

Any ideas? There are other objects above these textboxes so by the
time the use gets to them, they have to enter data, scroll down to the
next one and enter data. It does set the focus on txt2 but it does not
scroll to it.

How can I fix this?

Thanks

TMA

I should also point out that the textboxes exist in a tab in Form 2.
I have used the EnabledChanged feature of the InputPanel to adjust
form size and scrolling.



Private Sub InputPanel1_EnabledChanged(ByVal sender As
System.Object, ByVal e As System.EventArgs) Handles
InputPanel1.EnabledChanged
If InputPanel1.Enabled = False Then
For Each tbPge In tabCruise.TabPages
tbPge.AutoScroll = False
Next

tabCruise.Height = 267
tabCruise.Width = 240
Else
' The SIP is enabled, so the height of the tab control
' is set to the height of the visible desktop area.
For Each tbPge In tabCruise.TabPages
tbPge.AutoScroll = True
tbPge.AutoScrollMargin = New Size(5, 5)
Next

tabCruise.Height = InputPanel1.VisibleDesktop.Height
tabCruise.Width = InputPanel1.VisibleDesktop.Width
End If
End Sub
 
T

The Mad Ape

Paul said:
Wait, you want to tab to the next text box or move the text in a given text
box? Windows on Windows CE work basically just like they do on the desktop
(Tab to the next one, use the Down arrow to scroll).

When the input panel is enabled and there is a textbox that has focus
hidden behind the input panel, I have to manually scroll to that textbox
to enter data.

In my quest to make user input as efficient as possible, I want code
that detects when a textbox is obscured by the input panel. When
detected I want the textbox to show its ugly head automatically, without
manually scrolling to it.

Just saves a step but when a user does it a hundred times per day or
more it is time that adds up.

Thanks

TMA
 
C

Chris Tacke, MVP

You can use the InputPanel control to get an event when the user
opens/closes the SIP. Use that event to either scroll the form or move your
controls accordingly.

--

Chris Tacke, Embedded MVP
OpenNETCF Consulting
Giving back to the embedded community
http://community.OpenNETCF.com
 
P

Paul G. Tobey [eMVP]

Well, basically, you want to adjust the autoscroll position so that the
control is in the right place. There are an infinite number of special
cases (where is the input panel? on a wide screen device, the input panel
might be right in the middle of the screen; how do I make a given control
visible in that situation, etc.), but something basically like this will
probably show up:

int pos = focusedControl.Location.Y;

currentTabPage.AutoScrollPosition =

new Point( 0, pos - currentTabPage.AutoScrollPosition.Y );



Paul T.
 
T

The Mad Ape

Paul said:
Well, basically, you want to adjust the autoscroll position so that the
control is in the right place. There are an infinite number of special
cases (where is the input panel? on a wide screen device, the input panel
might be right in the middle of the screen; how do I make a given control
visible in that situation, etc.), but something basically like this will
probably show up:

int pos = focusedControl.Location.Y;

currentTabPage.AutoScrollPosition =

new Point( 0, pos - currentTabPage.AutoScrollPosition.Y );



Paul T.

Razzle Dazzle - Perfect dude. Simple perfect. Thank you for this tidbit.
You made my day!

TMA
 

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

Top