I have an inherited form and use it as a setting form. I ask user to input name to store, I want to change form title (text property of forms) dynamically according to the input data. but if I change base form title, overflow occur. also I create FormTitle property in base form to save current form name.
for example my application name is SerenaIR and I want to show below style for all of my forms.
SerenaIR | storename | formname
ex: SerenaIR | SuperMarket | Sale
FormTitle Property
private string _frmTitle;
/// <summary>
/// current form title for showing on title bar.
/// </summary>
[Category("JSCustomizer"),
Description("The text that is displayed on form title bar.")]
public string FormTitle
{
get { return _frmTitle; }
set
{
try
{
_frmTitle = value;
Invalidate();
var appPreName = Properties.Settings.Default.AppNamePre + @" " + Properties.Settings.Default.AppName;
if(_frmTitle.Length < 3)
{
base.Text = appPreName;
}
else
{
base.Text = appPreName + @" | " + _frmTitle;
}
}
catch
{
return;
}
}
}
in setting form i save setting about store name and on the base form when i want change the title by below code, all of Inherited form raise error!
private void JSfrmBaseLoad(object sender, EventArgs e)
{
Text = Properties.Settings.Default.AppNamePre + @" " + Properties.Settings.Default.AppName;
}
My guess is that you are creating and endless loop that causes the overflow. But I think the real problem is that you are misunderstanding how inheritance works in this scenario. Changing a non-static property value on a base form will not update the value for inheriting forms because each form is a new instance.
My suggestion is to use a property in Program.cs to store the form title. In this example I am changing the form title on a button click. All forms that inherit Form1 will set the new form title in OnLoad.
Program.cs:
Form1: