Click or drag to resize
ProfileOptionsExtension Class
Inheritance Hierarchy
SystemObject
  CTExtensions.InterfacesProfileOptionsExtension

Namespace: CTExtensions.Interfaces
Assembly: CTInterface (in CTInterface.dll)
Syntax
public abstract class ProfileOptionsExtension : IExtensionInterface

The ProfileOptionsExtension type exposes the following members.

Methods
  NameDescription
Public methodCreateControl
Provide the control for your options page. This is called in lazy-load manner, when the user selects this profile options extension from the tree.
Public methodCreateSettingsControl
Create and return window handle for custom options page. Default implementation handles control lifetime and inheritant may just enjoy from CreateControl.
Public methodDispose
Called when the settings page is closed. Disposes the control if not disposed already. Inheriants can ignore this if also CreateSettingsControl is left in default implementation.
Public methodGetParent
Return parent CTExtension of this options extension.
Public methodGetSaveData
Public methodLoadData
Called after CreateControl. Setup the control you created with this stored data.
Public methodPageName
Name that is shown in profile options tree. By default this is parents FriendlyName.
Public methodReadProfileData
Helper function to read parent extension's data from given profile.
Public methodRefresh
Notification that occurs when user re-enters to this extension's options page.
Public methodSave
Called when user clicks OK at export profile settings and all pages have returned true on Validate. Inheriants can ignore this and just return data at GetSaveData(Boolean) when called.
Public methodStoreProfileData
Helper function to store parent extension's data to given profile.
Public methodValidate
Validate settings use has mede to your control. Show error message if needed.
Top
Examples
Example extension that provides its own profile options page. This example creates an item to profile options tree with the extension's name 'MyAddin'. The settings page contains one textbox -control and requires user to type either 'hello' or 'world' to it before letting user to successfully exit the options. The value is also stored to and retrieved from DB.
C#
// @AUTO-REFERENCE { [CT_INSTALL_PATH]\CTInterface.dll }
// @AUTO-REFERENCE { [CT_INSTALL_PATH]\Interop.CTEngineLib.dll }
// @AUTO-REFERENCE { C:\Windows\Microsoft.NET\Framework\v4.0.30319\System.Windows.Forms.dll }

using ATR.CT.CTInterface;
using CTExtensions;
using CTEngineLib;
using CTExtensions.Interfaces;
using System;
using System.Windows.Forms;

public class MyAddin : CTExtension
{

  private MyProfileSettingsPage moProfileSettingsPage;

  public override bool Hook(CTInterface oCTInterface)
  {
    return false; // We don't care about events.
  }

  public override void UnHook(CTInterface oCTInterface)
  {

  }

  /// <summary>
  /// Return the custom interface on request.
  /// </summary>
  public override IExtensionInterface GetInterface(ctExtensionInterface eType)
  {
    if (eType == ctExtensionInterface.ctExtensionInterfaceProfileSettings)
    {
      if (moProfileSettingsPage == null)
        moProfileSettingsPage = new MyProfileSettingsPage(this);
      return moProfileSettingsPage;
    }

    return null;
  }

  /// <summary>
  /// Create custom implementation for ProfileOptionsExtension.
  /// </summary>
  class MyProfileSettingsPage : ProfileOptionsExtension
  {

    private MyAddin moParent;
    private Panel moMyControl;
    private TextBox MyTextBox;

    public MyProfileSettingsPage(MyAddin oParent)
    {
      moParent = oParent;
    }

    public override ICTExtension GetParent()
    {
      return moParent;
    }

    /// <summary>
    /// Create panel with label and text field.
    /// </summary>
    /// <returns></returns>
    public override Control CreateControl()
    {
      moMyControl = new Panel();
      MyTextBox = new TextBox() { Dock = DockStyle.Top };

      moMyControl.Controls.Add(MyTextBox);
      moMyControl.Controls.Add(new Label() { Text = "My control", Dock = DockStyle.Top });
      return moMyControl;
    }

    /// <summary>
    /// Return the data we want to save.
    /// </summary>
    /// <param name="bCancelSave">Return false here.</param>
    public override byte[] GetSaveData(out bool bCancelSave)
    {
      bCancelSave = false;
      return System.Text.Encoding.UTF8.GetBytes(MyTextBox.Text);
    }

    /// <summary>
    /// Load the previously saved data for the control if any.
    /// </summary>
    /// <param name="storedData"></param>
    public override void LoadData(byte[] storedData)
    {
      try
      {
        MyTextBox.Text = System.Text.Encoding.UTF8.GetString(storedData);
      }
      catch
      {
        MyTextBox.Text = "";
      }
    }

    /// <summary>
    /// Must implement, but we can just return true here.
    /// </summary>
    /// <returns></returns>
    public override bool Refresh()
    {
      return true;
    }

    /// <summary>
    /// Validate the values before allowing user to exit. This function requires that the text box value must be either 'hello' or 'world'.
    /// </summary>
    /// <returns>True if data is valid, false otherwise.</returns>
    public override bool Validate()
    {
      if (String.Compare(MyTextBox.Text, "hello", true) != 0 && String.Compare(MyTextBox.Text, "world", true) != 0)
      {
        MessageBox.Show("You should type either 'hello' or 'world' to My control", "Error", MessageBoxButtons.OK, MessageBoxIcon.Hand);
        return false;
      }

      return true;
    }
  }

}
Availability

CUSTOMTOOLS 2017 SP2


See Also