Hi Gerard,
If you add just three lines of code to the Enter handler of the subclassed textbox, I think it will work as you want. This is based on the code from my Subclassed StrataFrame TextBox article at LesPinter.com:
using System; using System.Drawing;
public class MyTextBox : MicroFour.StrataFrame.UI.Windows.Forms.Textbox
{
public MyTextBox()
{ Font = new System.Drawing.Font(
"Courier New", 10F, FontStyle.Regular, GraphicsUnit.Point, ((byte)(0)));
// New:
this.Enter += new System.EventHandler(this.myTextBox1_Enter);
this.Leave += new System.EventHandler(this.myTextBox1_Leave); }
private void myTextBox1_Enter(object sender, EventArgs e)
{ ForeColor = Color.White;
BackColor = Color.Blue;
// Add the following three lines of code:
if ( BusinessObject == null)
{ AutoAdjustMaxLength = false; }
else { AutoAdjustMaxLength = true; }
}
private void myTextBox1_Leave(object sender, EventArgs e)
{ ForeColor = Color.Black;
BackColor = Color.White; }
}
I've attached my working sample code. Use the enclosed script to create the SQL database "Pinter" used by the program.
Les