Control.Focus Метод
Определение
Устанавливает фокус ввода на элемент управления.Sets input focus to the control.
public:
bool Focus();
public bool Focus ();
member this.Focus : unit -> bool
Public Function Focus () As Boolean
Возвраты
Значение true
, если запрос фокуса ввода был успешным; в противном случае — значение false
.true
if the input focus request was successful; otherwise, false
.
Примеры
В следующем примере кода фокус устанавливается на указанный Control, если он может получить фокус.The following code example sets focus to the specified Control, if it can receive focus.
public:
void ControlSetFocus( Control^ control )
{
// Set focus to the control, if it can receive focus.
if ( control->CanFocus )
{
control->Focus();
}
}
public void ControlSetFocus(Control control)
{
// Set focus to the control, if it can receive focus.
if(control.CanFocus)
{
control.Focus();
}
}
Public Sub ControlSetFocus(control As Control)
' Set focus to the control, if it can receive focus.
If control.CanFocus Then
control.Focus()
End If
End Sub
Комментарии
Метод Focus возвращает true
, если элемент управления успешно получил фокус ввода.The Focus method returns true
if the control successfully received input focus. Элемент управления может иметь фокус ввода, не отображая никаких визуальных подсказок в фокусе.The control can have the input focus while not displaying any visual cues of having the focus. Это поведение в основном наблюдалось для невыбираемых элементов управления, перечисленных ниже, или любых элементов управления, производных от них.This behavior is primarily observed by the nonselectable controls listed below, or any controls derived from them.
Элемент управления может быть выбран и получать фокус ввода, если выполняются следующие условия: значение Selectable
ControlStyles равно true
, оно содержится в другом элементе управления, и все его родительские элементы управления видимы и включены.A control can be selected and receive input focus if all the following are true: the Selectable
value of ControlStyles is set to true
, it is contained in another control, and all its parent controls are both visible and enabled.
Элементы управления Windows Forms в следующем списке недоступны для выбора.The Windows Forms controls in the following list are not selectable. Элементы управления, производные от этих элементов управления, также не могут быть выбраны.Controls derived from these controls are also not selectable.
LinkLabel (если в элементе управления отсутствует ссылка)LinkLabel (when there is no link present in the control)
Примечание
Focus — это метод низкого уровня, предназначенный в основном для авторов пользовательских элементов управления.Focus is a low-level method intended primarily for custom control authors. Вместо этого программисты приложений должны использовать метод Select или свойство ActiveControl для дочерних элементов управления или метод Activate для форм.Instead, application programmers should use the Select method or the ActiveControl property for child controls, or the Activate method for forms.
Безопасность
UIPermission
для всех окон, вызывающих этот метод.for all windows to call this method. Связанное перечисление: значение AllWindows
для UIPermissionWindow.Associated enumeration: AllWindows
value of UIPermissionWindow.