Control.CanFocus 屬性
定義
取得指示控制項是否能取得焦點的值。Gets a value indicating whether the control can receive focus.
public:
property bool CanFocus { bool get(); };
[System.ComponentModel.Browsable(false)]
public bool CanFocus { get; }
member this.CanFocus : bool
Public ReadOnly Property CanFocus As Boolean
屬性值
如果控制項可以取得焦點,則為 true
,否則為 false
。true
if the control can receive focus; 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
備註
為了讓控制項接收輸入焦點,控制項必須有指派的控制碼,而且 Visible 和 Enabled 屬性必須同時設為控制項和其所有父控制項的 true
,而且控制項必須是表單,而控制項的最外層父系必須是表單。In order for a control to receive input focus, the control must have a handle assigned to it, and the Visible and Enabled properties must both be set to true
for both the control and all its parent controls, and the control must be a form or the control's outermost parent must be a form.