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;否则为 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.

适用于

另请参阅