How does the VS2005 designer environment work?

M

mehdi

Hi folks,
Consider a custom class that's being derived from the TextBox and has
got the following propert:

public override string Text
{
get { return "get"; }
set {base.Text = "set";}
}

This new control, say, myTextBox is placed on a form. In this
scenario, the textbox shows the "set" text while at the same time the
Text property in the properties panel of the visual studio says that
the text is equal to "get". The question is that what's happening on
the designer?

The second problem is that when some properties of the myTextBox
control is changed, say, the ScrollBars property and the like. As soon
as this property is changed (I guess those that ends up in refreshing
the control in designer), the text shown in the textbox will change to
"get".

Any help to solve the problem would be highly appreciated,

Cheers,
Mehdi
 
S

Stoitcho Goutsev \(100\)

mehdi,

Here is the problem. When you drop the control on the form the designer
serializes the control and it correctly serializes setting the Text
property to the "get" string. Next step is to create the control and the
designer executes the serialized code in the InitializeComponent it executes
the set accessor and there you just write "set" the the base text property
that's why you get "set" ot the screen. On the other hand when the property
browser wants to show the value of the Text property it uses the *get*
accessor which always returns "get" and that is what you see on the property
browser. If you want to fix that just write correct *get* and *set*
accessors that in the simple case will use the base class Text property.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top