Greg Finzer
Greg Finzer

Reputation: 7074

How do I localize strings in a custom control in WinForms?

I have a custom wizard control that I am modifying with a Title and a SubTitle. How do I save and localize strings in the control? Here is the SubTitle property:

[Category("Appearance"), DefaultValue("Description for the new page."), Description("The subtitle of the page."), Editor(typeof(MultilineStringEditor), typeof(UITypeEditor))]
public string Subtitle
{
    get { return subtitle; }
    set
    {
        if (subtitle != value)
        {
            Region regionToInvalidate = GetTextRegionToInvalidate();
            subtitle = value;
            regionToInvalidate.Union(GetTextRegionToInvalidate());

            Invalidate(regionToInvalidate);
        }
    }
}

Upvotes: 2

Views: 771

Answers (1)

Vedran
Vedran

Reputation: 11059

Just add the Localizable attribute

[Category("Appearance"), DefaultValue("Description for the new page."), Description("The subtitle of the page."), Editor(typeof(MultilineStringEditor), typeof(UITypeEditor))]
[Localizable(true)]
public string Subtitle
{
    get { return subtitle; }
    set
    {
        if (subtitle != value)
        {
            Region regionToInvalidate = GetTextRegionToInvalidate();
            subtitle = value;
            regionToInvalidate.Union(GetTextRegionToInvalidate());

            Invalidate(regionToInvalidate);
        }
    }
}

Upvotes: 3

Related Questions