UserControl Text property

  • Thread starter Thread starter Lance Johnson
  • Start date Start date
L

Lance Johnson

I have a control that derives from UserControl. In addition, I have
overriden the Text property and put the attributes on it so it shows up int
the designer. However, it will not save the value no matter what I do.
I've applied every attribute I can think of. Any help in this matter is
appreciated.

Lance Johnson
 
Are you just trying to extend the functionality of an existing control? If
so, maybe you can try adding a new component to your project and derive it
from another (e.g. public class SomeLabel: System.Windows.Forms.Label).
This will expose all the properties that were in the Label class at design
time.

I had the same problem as you before and never figured it out ...
 
That doesn't quite work for me. Although the user control only contains 1
control, I want to give my own properties etc to use. Also, this component
requires a certain DLL, and I'd rather not have to reference this other DLL
in all of my projects that use this component.

Lance Johnson
 
By extending the component, you can add custom properties and methods ...

public class SomeLabel: System.Windows.Forms.Label
{
private bool required = false;

private System.ComponentModel.Container components = null;
public SomeLabel() { ... }

...

[Browsable(true)]
public bool Required
{
get { return required; }
set { required = value; }
}

...
}
 
Have you tried the DesignerSerializationVisibility attribute?

[DesignerSerializationVisibility(DesignerSerializationVisibility.Visible)]

UserControl uses
[DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] on
the text property, so your override needs to specify it as visible.

Hope that helps.

Regards,
Matt
 
I have tried visible and content. It's not that it's not showing up. It's
that it won't save out the property value. This is real annoying because I
can't understand why. Maybe there's some kind of flaw in how these
attributes are being handled with VS.Net.

Lance Johnson


Matt Garven said:
Have you tried the DesignerSerializationVisibility attribute?

[DesignerSerializationVisibility(DesignerSerializationVisibility.Visible)]

UserControl uses
[DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
on
the text property, so your override needs to specify it as visible.

Hope that helps.

Regards,
Matt


Lance Johnson said:
I have a control that derives from UserControl. In addition, I have
overriden the Text property and put the attributes on it so it shows up
int
the designer. However, it will not save the value no matter what I do.
I've applied every attribute I can think of. Any help in this matter is
appreciated.

Lance Johnson
 
Back
Top