In this Article I'm going to explain how to add a Input of a Dropdown / Combo to gather more configuration from the User.
- - -
When using the Pad Text component I noticed it used a DropDown to allow a choice of options. This could be useful in a Component I was creating so I thought I'd investigate how this was configured.
If you've completed the Inspecting article you will already have this DLL ready, re-open it in your Decompiler of choice.
Find 'PadText' under 'Process'.
We need to find the PadType configuration.
First the Declaration
private PadText.PadTypeEnum _padType;
This is new, it's using an Enum. This is a much better way then an Array of Strings.
public enum PadTypeEnum { Left, Right }
ReadFromStream
public override void ReadFromStream(ObjectReadStream info) { ... this._padType = (PadText.PadTypeEnum)info.GetValue("padType", typeof(PadText.PadTypeEnum)); ... }
WriteToStream
public override void WriteToStream(ObjectWriteStream info) { ... info.AddValue("padType", this._padType); ... }
Run
public override void Run(IData data) { ... char value = (char)this._padChar.GetValue(data); switch (this._padType) { case PadText.PadTypeEnum.Left: { str1 = str1.PadLeft(this._padLength, value); break; } case PadText.PadTypeEnum.Right: { str1 = str1.PadRight(this._padLength, value); break; } } ... }
A switch statement is used to consider each choice made.
If we want to use a drop down in our own components we can create our own Enum and use that instead.