Visual Basic, .NET, ASP, VBScript
 

   
   
     

Форум - Общий форум

Страница: 1 |

 

  Вопрос: Переход по контролам формы Добавлено: 16.04.04 09:59  

Автор вопроса:  Оллл
На форме есть несколько текстовых полей и кнопок. Подскажите пожалуйста, как сделать, чтобы по нажатию "Enter" (после ввода значения в текстовое поле) курсор перемещался в другое поле. И как задать порядок перемещения? 

Ответить

  Ответы Всего ответов: 5  

Номер ответа: 1
Автор ответа:
 Ra$cal



ICQ: 8068014 

Вопросов: 18
Ответов: 817
 Web-сайт: www.rascalspb.narod.ru
 Профиль | | #1
Добавлено: 16.04.04 10:28

Option Explicit

Private Sub Text1_KeyUp(KeyCode As Integer, Shift As Integer)

If KeyCode = 13 Then Text2.SetFocus

End Sub

Private Sub Text2_KeyUp(KeyCode As Integer, Shift As Integer)

If KeyCode = 13 Then Text1.SetFocus

End Sub

Ответить

Номер ответа: 2
Автор ответа:
 Sur



ICQ: 1249088 

Вопросов: 10
Ответов: 304
 Web-сайт: sur.hotbox.ru/
 Профиль | | #2
Добавлено: 16.04.04 14:51

А если есть кнопка с .Default=True ?

Типа можно проще - путь перемещения задать в TabIndex текстовых полей

Private Sub Form_Load()

Form1.KeyPreview = True

End Sub

Private Sub Command1_Click()

If Command1 Is ActiveControl Then

'код дефолтной кнопки

Else

SendKeys "{Tab}"

End If

End Sub

Private Sub Form_KeyUp(KeyCode As Integer, Shift As Integer)

If KeyCode = 13 Then SendKeys "{Tab}"

End Sub

Ответить

Номер ответа: 3
Автор ответа:
 LamerOnLine



ICQ: 334781088 

Вопросов: 108
Ответов: 2822
 Профиль | | #3 Добавлено: 16.04.04 17:08
Knowledge Base Articles HOWTO: Make ENTER Key Move Focus Like TAB Key for VB ControlsQ142816--------------------------------------------------------------------------------The information in this article applies to:Microsoft Visual Basic Learning Edition for Windows, versions 5.0, 6.0 Microsoft Visual Basic Professional Edition for Windows, versions 5.0, 6.0 Microsoft Visual Basic Enterprise Edition for Windows, versions 5.0, 6.0 Microsoft Visual Basic Professional Edition, 16-bit, for Windows, version 4.0 Microsoft Visual Basic Professional Edition, 32-bit, for Windows, version 4.0 Microsoft Visual Basic Enterprise Edition, 16-bit, for Windows, version 4.0 Microsoft Visual Basic Enterprise Edition, 32-bit, for Windows, version 4.0--------------------------------------------------------------------------------SUMMARYYou can cause the ENTER key to move the focus to the control with the next higher TabIndex property value, as the TAB key does. However, using the ENTER key to move the focus does not follow recommended Microsoft Windows-based application design guidelines. The ENTER key should be used to process the default command or to process entered information, not to move the focus. MORE INFORMATIONYou can detect when the user presses the ENTER key from the KeyPress event procedure by checking to see if the KeyAscii parameter is the character code for the ENTER key (13). Then you can move the focus to the next control in the TabIndex order with SendKeys "{tab}." You can move the focus to the previous control with SendKeys "+{tab}." This technique works with most kinds of controls. It does not work with command button controls, because command buttons do not receive the KeyPress event when you press the ENTER key. Step-by-Step ExampleStart a new project in Visual Basic. Form1 is created by default. Add two text boxes (Text1 and Text2) to Form1. Add the following code to the Text1 KeyPress procedure: Private Sub Text1_KeyPress (KeyAscii As Integer) If KeyAscii = 13 Then ' The ENTER key. SendKeys "{tab}" ' Set the focus to the next control. KeyAscii = 0 ' Ignore this key. End If End Sub Add the following code to the Text2 KeyPress procedure: Private Sub Text2_KeyPress (KeyAscii As Integer) If KeyAscii = 13 Then ' The ENTER key. SendKeys "{tab}" ' Set the focus to the next control. KeyAscii = 0 ' Ignore this key. End If End Sub Press the F5 key to run the program. When you press the ENTER key, the focus moves between the two controls. Additional query words: kbVBp400 kbVBp500 kbVBp600 kbControl kbVBp kbdsd kbDSupport Keywords : kbGrpDSVB Issue type : kbhowto Technology : kbVBSearch kbAudDeveloper kbZNotKeyword6 kbZNotKeyword2 kbVB500Search kbVB600Search kbVBA500 kbVBA600 kbVB500 kbVB600 kbVB400Search kbVB400 kbVB16bitSearch Last Reviewed: January 11, 2001--------------------------------------------------------------------------------Send feedback to Microsoft© 2002 Microsoft Corporation. All rights reserved.

Ответить

Номер ответа: 4
Автор ответа:
 LamerOnLine



ICQ: 334781088 

Вопросов: 108
Ответов: 2822
 Профиль | | #4 Добавлено: 16.04.04 17:33

Извиняюсь за хлам, дюжа стремно он страничку вставил. Из оперы пишу...

Ответить

Номер ответа: 5
Автор ответа:
 Оллл



Вопросов: 41
Ответов: 43
 Профиль | | #5 Добавлено: 19.04.04 09:54

Спасибо за исчерпывающую информацию!!!

Ответить

Страница: 1 |

Поиск по форуму



© Copyright 2002-2011 VBNet.RU | Пишите нам