WinForms strings in resource files, wired up in designer

后端 未结 5 2055
星月不相逢
星月不相逢 2021-02-05 12:58

I\'m trying to localise a WinForms app for multiple languages. I\'m trying to find a way to set my form labels/buttons text properties to read from the resources file in the des

5条回答
  •  暖寄归人
    2021-02-05 13:22

    I have just been looking at this very thing.
    If you own the control, ie it is your own custom control, you can use CodeDOM

    Read this article for some background and download this example to see how it's done.

    In our app we need to replace placeholders with "DisplayText" form the database.
    So we have Text properties like "Order {Product}" and we want to replace with GetDisplayText("Order {Product}")`.

    So in order to do this I have added the following code:

                    statements.OfType()
                        .Where(s => s.Left is CodePropertyReferenceExpression && ((CodePropertyReferenceExpression)s.Left).PropertyName == "Text")
                        .ToList().ForEach(s =>
                        {
                            s.Right = new CodeMethodInvokeExpression(
                                new CodeMethodReferenceExpression(new CodeTypeReferenceExpression("Core.DisplayText"), "GetDisplayText"),
                                s.Right);
                        });
    

    However I am still experimenting with it and I haven't created a working solution yet... But it may help you.

    :-)

提交回复
热议问题