Control.CanFocus Control.CanFocus Control.CanFocus Control.CanFocus Property

定義

取得指示控制項是否能取得焦點的值。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,否則為 falsetrue 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

備註

為了讓接收輸入的焦點的控制項,控制項必須有控制代碼指派給它,而VisibleEnabled屬性必須同時設定為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.

適用於

另請參閱