Reputation: 1391
I have a winForms with textboxes
. Each textbox
will show setting values from an .ini file. Some of the .ini file values are encrypted and will require the values to be decrypted before placing the value inside the textbox
. I already created a function:
storeIniValueToVar(string iniSection, string iniKey, bool? encrypt)
Is it possible to extend the textbox
properties with a custom argument such as boolean? encrypt? My thinking was to pass the custom argument boolean? encrypt value to the storeIniValueToVar
function.
Upvotes: 0
Views: 1655
Reputation: 164
There's a generic property called Tag. You can store any kind of strings in it. The disadvantage is that the return type is Object, but you don't have to derive from your UI control.
Example:
private void OnTextBoxChanged(object sender, EventArgs e)
{
var updatedTextBox = sender as TextBox;
object tagObject = updatedTextBox.Tag;
// Further converting of the tag here...
}
Set the events of your textboxes (here TextChanged) to one single EventHandler and you can get the TextBox instance and the tag as well.
Upvotes: 3
Reputation: 6026
I believe you are asking to add an additional property to the TextBox
class which will indicate whether the text contained within it it should encrypted/decrypted when it is stored/loaded from the ini file.
What you could do is subclass TextBox
and add your own properties:
class MyTextBox : TextBox
{
public bool Encrypt { get; set; }
}
Then, you use MyTextBox
instead of TextBox
on your forms.
Upvotes: 3