Called by the framework when the combo box gets or loses focus.

Namespace:  ESRI.ArcGIS.Desktop.AddIns

Assembly:  ESRI.ArcGIS.Desktop.Addins (in ESRI.ArcGIS.Desktop.Addins.dll) Version: 10.0.0.0 (10.0.0.0)

Syntax

C#
protected virtual void OnFocus(
	bool set
)
Visual Basic (Declaration)
Protected Overridable Sub OnFocus ( _
	set As Boolean _
)
Visual C++
protected:
virtual void OnFocus(
	bool set
)

Parameters

set
Type: System..::.Boolean

if set to trueTruetruetrue (True in Visual Basic) [set].

Remarks

When getting focus, parameter set is true; when losing focus, parameter set is false. By checking the value of parameter set, the combo box can respond to either getting or losing focus or both.

Examples

The code below shows the implementation of a simple combo box.
CopyC#
public class Combo1 : ESRI.ArcGIS.Desktop.AddIns.ComboBox
{
  public Combo1()
  {
    //Add two items to the combo box.
    Point o1 = new Point();
    o1.PutCoords(0, 0);
    int c1 = this.Add("Item1", o1);

    Point o2 = new Point();
    o2.PutCoords(1, 1);
    int c2 = this.Add("Item2", o2);

    //Add the application's caption.
    ESRI.ArcGIS.Framework.IApplication app = this.Hook as ESRI.ArcGIS.Framework.IApplication;
    this.Add(app.Caption);

    //Add one item then remove
    int c3 = this.Add("Item3");
    this.Remove(c3);

    //Select the second item.
    this.Select(c2);
  }

  protected override void OnSelChange(int cookie)
  {
    if (cookie == -1)
      return;

    //Get the associated object.
    Point tag = this.GetItem(cookie).Tag as Point;
    if (tag != null)
    {
      System.Windows.Forms.MessageBox.Show(tag.X + ", " + tag.Y);
    }
  }

  protected override void OnEnter()
  {
    //Loop through the item collection.
    foreach (ESRI.ArcGIS.Desktop.AddIns.ComboBox.Item item in this.items)
    {
      if (this.Value == item.Caption)
        return;
    }
    this.Add(this.Value);
  }

  protected override void OnEditChange(string editString)
  {
    if (string.Compare(editString, "ABC", true) == 0)
    {
      System.Windows.Forms.MessageBox.Show("editString is " + this.Value);
    }
  }

  protected override void OnFocus(bool set)
  {
    if (set)
      System.Diagnostics.Debug.WriteLine("Get focus.");

    if (!set)
      System.Diagnostics.Debug.WriteLine("Lose focus.");
  }

  protected override void OnUpdate()
  {
    this.Enabled = ArcMap.Application != null;
  }
}
CopyVB.NET
Public Class Combo1
  Inherits ESRI.ArcGIS.Desktop.AddIns.ComboBox
  Public Sub New()
    'Add two items to the combo box. 
    Dim o1 As New Point()
    o1.PutCoords(0, 0)
    Dim c1 As Integer = Me.Add("Item1", o1)

    Dim o2 As New Point()
    o2.PutCoords(1, 1)
    Dim c2 As Integer = Me.Add("Item2", o2)

    'Add the application's caption. 
    Dim app As ESRI.ArcGIS.Framework.IApplication = TryCast(Me.Hook, ESRI.ArcGIS.Framework.IApplication)
    Me.Add(app.Caption)

    'Add one item then remove 
    Dim c3 As Integer = Me.Add("Item3")
    Me.Remove(c3)

    'Select the second item. 
    Me.[Select](c2)
  End Sub

  Protected Overloads Overrides Sub OnSelChange(ByVal cookie As Integer)
    If cookie = -1 Then
      Exit Sub
    End If

    'Get the associated object. 
    Dim tag As Point = TryCast(Me.GetItem(cookie).Tag, Point)
    If tag IsNot Nothing Then
      System.Windows.Forms.MessageBox.Show((tag.X & ", ") + tag.Y)
    End If
  End Sub

  Protected Overloads Overrides Sub OnEnter()
    'Loop through the item collection. 
    For Each item As ESRI.ArcGIS.Desktop.AddIns.ComboBox.Item In Me.items
      If Me.Value = item.Caption Then
        Exit Sub
      End If
    Next
    Me.Add(Me.Value)
  End Sub

  Protected Overloads Overrides Sub OnEditChange(ByVal editString As String)
    If String.Compare(editString, "ABC", True) = 0 Then
      System.Windows.Forms.MessageBox.Show("editString is " & Me.Value)
    End If
  End Sub

  Protected Overloads Overrides Sub OnFocus(ByVal [set] As Boolean)
    If [set] Then
      System.Diagnostics.Debug.WriteLine("Get focus.")
    End If

    If Not [set] Then
      System.Diagnostics.Debug.WriteLine("Lose focus.")
    End If
  End Sub

  Protected Overloads Overrides Sub OnUpdate()
    Me.Enabled = ArcMap.Application IsNot Nothing
  End Sub
End Class

See Also