How to add culture support in a property with a user control.

Ok, I have created a user control that is basicly a label and an image. In my user control class, I have added a property called

private string labelText;

[Browsable(true)]

public string LabelText

{

get

{

return labelText;

}

set

{

labelText = value;

}

}

But when I set a value in the LabelText field in the form designer, instead of creating a new ressource entry in the resource file, it is "hardcoding" the direct value in the back-end (in the initializecomponent):

this.eC2ISLabel1.LabelText = "myText";

For this reason, I can't use culture because culture is based on resource file. What I would like to do is set different text based on the language. (basicly, save info in the resource file instead of the initializeComponent.

How this can be possible



Answer this question

How to add culture support in a property with a user control.

  • feel

    Howesome, Worked, thanks.

    Another problem as related to the culture...

    It seems that we can't override of a properties.... There is no value of Text in either the localization or in the initializeComponent... So I am always losing my value, what should I do in order to keep the Text value in my properties I have tried:

    [Browsable(true)]
    public override string Text
    {
    get
    {
    return myTextBox.Text;
    }
    set
    {
    myTextBox.Text = value;
    }
    }

    Or

    [Browsable(true)]
    public new string Text
    {
    get
    {
    return myTextBox.Text;
    }
    set
    {
    myTextBox.Text = value;
    }
    }

    with or without the [Localization(true)]....

    thanks again.


  • Gavin T.D. Greig

    Use the override and add to following to it:

    [DesignerSerializationVisibility(DesignerSerializationVisibility.Visible)]



  • abhivyas

    Apply the Localizable(true) attribute to the property.

  • How to add culture support in a property with a user control.