Spread Windows Forms 11.0 Product Documentation
Focus(Boolean) Method
Example 


FarPoint.Win Assembly > FarPoint.Win Namespace > ElementControl Class > Focus Method : Focus(Boolean) Method
Whether to move focus to the control
Moves the focus to the control.
Syntax
'Declaration
 
Public Overloads Overridable Sub Focus( _
   ByVal giveFocus As Boolean _
) 
'Usage
 
Dim instance As ElementControl
Dim giveFocus As Boolean
 
instance.Focus(giveFocus)
public virtual void Focus( 
   bool giveFocus
)

Parameters

giveFocus
Whether to move focus to the control
Remarks

Use this method to move the focus to or remove the focus from the control. Use the Focus method if you want to move the focus to the control and receive a return value whether moving the focus was successful.

If you try to move the focus to the control by using this method, but the CanFocus property or the Enabled property is set to false, the focus will not move to the control.

You can check whether the control already has the focus using the Focused property.

For some controls, when the control receives the focus, if it can, the control can display a focus rectangle. Specify whether and how the focus rectangle appears by setting the DrawFocusRectangle property.

Some controls display a cursor when they receive the focus. Specify the position of the cursor by setting the EditModeCursorPosition property, if supported.

Example
This example shows the use of this member.
control.Text = "NO SMOKING";
control.ForeColor = Color.Red;
control.TextOrientation = FarPoint.Win.TextOrientation.TextVertical;
control.Picture = Image.FromFile(Application.StartupPath + "\\smokes.bmp", true)
control.AlignText = FarPoint.Win.TextAlign.TextLeftPictRight;
control.AlignHorz = FarPoint.Win.HorizontalAlignment.Center;
Rectangle rect = new Rectangle(10,50,200,150);
control.SetBounds(rect);
control.Focus();
control.Text = "NO SMOKING"
control.ForeColor = Color.Red
control.TextOrientation = FarPoint.Win.TextOrientation.TextVertical
control.Picture = Image.FromFile(Application.StartupPath & "\smokes.bmp", True)
control.AlignText = FarPoint.Win.TextAlign.TextLeftPictRight
control.AlignHorz = FarPoint.Win.HorizontalAlignment.Center
Dim rect As New Rectangle(10, 50, 200, 150)
control.SetBounds(rect)
control.Focus()
See Also

Reference

ElementControl Class
ElementControl Members
Overload List
CanFocus Property
Enabled Property
DrawFocusRectangle Property
EditModeCursorPosition Property
Focused Property