Important: please see "... edit 1 ..." below.
... note: please check in your post: did you mean to use 'text' instead of 'Text' in your sample code ?
... comment: delightful if someone will post a simpler way of doing this ! ...
Yes, you can do this. You are going to need to :
1. make sure your Form or Class inherits INotifyPropertyChanged
public partial class Form1 : Form, INotifyPropertyChanged
2. implement an EventHandler for INotifyPropertyChanged
public event PropertyChangedEventHandler PropertyChanged;
private void NotifyPropertyChanged(String pName)
{
if (PropertyChanged != null)
{
PropertyChanged(this, new PropertyChangedEventArgs(pName));
}
}
3. in the 'setter of your property: invoke the EventHandler that implements INotifyPropertyChanged
set
{
if (value != this.strColor)
{
this.strColor = value;
NotifyPropertyChanged("ptyColor");
}
}
4. then your binding call (perhaps in the Form 'Load' event ?) might look like:
this.DataBindings.Add("ptyColor", this, "strColor");
Check out:[
^],[
^]
... edit #1 ...
I looked up the code where I'd done something similar: my usage was to add a binding to a TextBox so that any change in a public property 'TheBackColor' automatically set the BackColor of the TextBox.
In that case the binding call looked like this:
textBox1.DataBindings.Add("BackColor", this, "TheBackColor");
So I am now have concerned that the binding call I have shown here based on your example, may need to be
this.DataBindings.Add("ptyColor", this, "ptyColor")
If both those types of calls don't help you achieve what you are after: I stand ready to be down-voted into outer-darkness (I decline the blindfold, thank you).
... end edit #1 ...
Note: this specific code has not been tested, but is based on what I hope is a clear memory of implementing this a few months ago. Caveat emptor.