Windows Develop Bookmark and Share   
 index > Windows Forms General > Accessing Form Caption in Subclass
 

Accessing Form Caption in Subclass

I'm using .NET 1.1

I have a form class called BaseForm, and I create a subclass of BaseForm called SubclassForm.

In the constructor of Baseform, I add text to the end of the Text property:

public class BaseForm:Form
{
   public BaseForm(string sSuffix)
   {
      this.Text+=sSuffix;
   }
}

public class SubclassForm:BaseForm
{
   public SubclassForm(string sSuffix):base(sSuffix)
   {
      
   }
}

In the designer, I change the Text property of SubclassForm to "SubclassForm", but when I instantiate SubclassForm, it uses the Text property of BaseForm rather than SubclassForm (IOW, it adds the passed string to the value from BaseForm.Text rather than SubclassForm.Text)
Rick Hodder  Monday, November 14, 2005 3:25 PM
I would override the Text property in your form and see who is setting it to what and why. 

public override string Text { 
   get { return base.Text; }
   set { base.Text = value; } // <-- put a breakpoint here or MessageBox.Show(new StackTrace().ToString());
}
JFo - MSFT  Tuesday, November 15, 2005 9:30 PM

When you change something in the designer it is done after the object constructor. When doing this.Text += sSuffix; the this.Text is always = to "";

ThE_lOtUs  Monday, November 14, 2005 6:58 PM
But the problem is that it is using the inherited value of BaseForm.Text ("BaseForm") rather than the overriden Text ("SubclassForm") property in SubclassForm.

I've even moved the code to the Load of BaseForm, but the same thing happens.
Rick Hodder  Monday, November 14, 2005 7:33 PM
I would override the Text property in your form and see who is setting it to what and why. 

public override string Text { 
   get { return base.Text; }
   set { base.Text = value; } // <-- put a breakpoint here or MessageBox.Show(new StackTrace().ToString());
}
JFo - MSFT  Tuesday, November 15, 2005 9:30 PM

You can use google to search for other answers

Custom Search

More Threads

• How to access another forms members
• Ideas Appreciated
• Any consultants out there know what 'Normal' terms are to a client?
• ID Number for Rich Text Format?
• PictureBox locking access to an image?
• Changing web service location at runtime
• Snmp support in .NET?
• Moving a hidden form to a second monitor
• The Operation has timed out Exception
• bitmaps in forms