locked
Values from resx files in design view RRS feed

  • Question

  • I'm using Microsoft Visual Studio 2010 Windows Forms.
    I will use resx files for text.

    I'm adding a value into my resx file. Name: bth_Add. Value: My add.

    How can this value be shown in my design view? (Before I compile my solution).

    It will make the design process so much easier.

    Thanks in advance.

    Tuesday, November 1, 2011 1:13 PM

Answers

  • I'm using Microsoft Visual Studio 2010 Windows Forms.
    I will use resx files for text.

    I'm adding a value into my resx file. Name: bth_Add. Value: My add.

    How can this value be shown in my design view? (Before I compile my solution).

    It will make the design process so much easier.

    Thanks in advance.


    What kind of control do you need to develop?

    On the other hand, whatever you add the code into the resx file or the code behind file, it is the same. both of them are the partical class.

    If you want to add some of the settings to the design view, such as add a property, and you want to set the property in the Properties Grid in the Visual Studio, you can do like:

    [Browsable(true)]
    Public string MyProperty
    {

        get{.....}
        set{.....}

    }

    You can also develop custom control by using the EditorAttribute:

    http://msdn.microsoft.com/en-us/library/system.componentmodel.editorattribute.aspx 

    Here are some examples on how to develop a newer design custom control:

    Creating Custom Controls-Providing Design Time Support 1:
    http://www.codeproject.com/KB/cs/propertyeditor.aspx

    'Inheriting' from an Internal WinForms Designer:
    http://www.codeproject.com/KB/miscctrl/EncapsulatedDesigner.aspx

    Best Regards


    Neddy Ren [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    • Marked as answer by Neddy Ren Thursday, November 24, 2011 8:55 AM
    Friday, November 4, 2011 7:07 AM
  • The question is not about controls and forms. It's a question about resx files. I drag a custom control e.g a Button controln into my Form. I want the value the Text attribute on my button to get a value from the resx file.

    To read a value from you resx file you can use this code:

    ResourceManager resourceManager = new ResourceManager ("MyCompany.MyProject.SomeResources", GetType ().Assembly);

    myButton.Text =resourceManager .GetString("hello",culture);

    However, then you have to compile your project everytime you want to see how a text appears on the screen. I want the value from the resx file to be visible in design view. Do you know how to do that?


    For the first, the ResourceManager works at run time. Here is the specification:

    Provides convenient access to culture-specific resources at run time.

    If you change the ResourceManager, you must compile it.

    For the second, suppose you want to add a property MyText and you want to set it at design time and save it in the resx file, you can use ResXResourceWriter/ResXResourceReader in its set/get method. And set the attribute [Browsable(true)].

    ResXResourceWriter Class:
    http://msdn.microsoft.com/en-us/library/system.resources.resxresourcewriter.aspx

    ResXResourceReader Class:
    http://msdn.microsoft.com/en-us/library/system.resources.resxresourcereader.aspx

    Best Regards

     


    Neddy Ren [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    • Proposed as answer by Neddy Ren Tuesday, November 15, 2011 7:03 AM
    • Marked as answer by Neddy Ren Thursday, November 24, 2011 8:55 AM
    Wednesday, November 9, 2011 2:48 AM

All replies

  • I'm using Microsoft Visual Studio 2010 Windows Forms.
    I will use resx files for text.

    I'm adding a value into my resx file. Name: bth_Add. Value: My add.

    How can this value be shown in my design view? (Before I compile my solution).

    It will make the design process so much easier.

    Thanks in advance.


    What kind of control do you need to develop?

    On the other hand, whatever you add the code into the resx file or the code behind file, it is the same. both of them are the partical class.

    If you want to add some of the settings to the design view, such as add a property, and you want to set the property in the Properties Grid in the Visual Studio, you can do like:

    [Browsable(true)]
    Public string MyProperty
    {

        get{.....}
        set{.....}

    }

    You can also develop custom control by using the EditorAttribute:

    http://msdn.microsoft.com/en-us/library/system.componentmodel.editorattribute.aspx 

    Here are some examples on how to develop a newer design custom control:

    Creating Custom Controls-Providing Design Time Support 1:
    http://www.codeproject.com/KB/cs/propertyeditor.aspx

    'Inheriting' from an Internal WinForms Designer:
    http://www.codeproject.com/KB/miscctrl/EncapsulatedDesigner.aspx

    Best Regards


    Neddy Ren [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    • Marked as answer by Neddy Ren Thursday, November 24, 2011 8:55 AM
    Friday, November 4, 2011 7:07 AM
  • It's not related to a spesific kind of control. It's a general question about resx files. I'm sorry that I wasn't clear on that.

    It could e.g be a regular System.Windows.Forms.Label control or a System.Windows.Forms.Button control.

    Both of these has an attribute Text. And in design view the Text attribute is shown on the control and makes it easier to design a Form.

    But I want to use resx files to handle visible texts in gui. I know how to use the ResourceManager class and change the values when you compile the form/solution. The question is: How can values from my resx files be used in the Text attribute of my controls before I compile my solution? And by that be visible in the design view?

    Monday, November 7, 2011 2:43 PM
  • It's not related to a spesific kind of control. It's a general question about resx files. I'm sorry that I wasn't clear on that.

    It could e.g be a regular System.Windows.Forms.Label control or a System.Windows.Forms.Button control.

    Both of these has an attribute Text. And in design view the Text attribute is shown on the control and makes it easier to design a Form.

    But I want to use resx files to handle visible texts in gui. I know how to use the ResourceManager class and change the values when you compile the form/solution. The question is: How can values from my resx files be used in the Text attribute of my controls before I compile my solution? And by that be visible in the design view?


    Sorry, I am confused now. You can design a userControl / custom control and after you compile it, you can drag it into your form.

    But I have never heard you can changed the resx file through a form to the userControl/custom control. It is impossible.

    The standard steps are:

    1. design your cusotm/user control
    2. compile your projects which the control in
    3. add the custom/user control to the form through VS designer/code behind at runtime.

    But you can not develop a control through a form.

    Best Regards

     


    Neddy Ren [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Tuesday, November 8, 2011 6:35 AM
  • The question is not about controls and forms. It's a question about resx files. I drag a custom control e.g a Button controln into my Form. I want the value the Text attribute on my button to get a value from the resx file.

    To read a value from you resx file you can use this code:

    ResourceManager resourceManager = new ResourceManager ("MyCompany.MyProject.SomeResources", GetType ().Assembly);

    myButton.Text =resourceManager .GetString("hello",culture);

    However, then you have to compile your project everytime you want to see how a text appears on the screen. I want the value from the resx file to be visible in design view. Do you know how to do that?

    Tuesday, November 8, 2011 12:35 PM
  • The question is not about controls and forms. It's a question about resx files. I drag a custom control e.g a Button controln into my Form. I want the value the Text attribute on my button to get a value from the resx file.

    To read a value from you resx file you can use this code:

    ResourceManager resourceManager = new ResourceManager ("MyCompany.MyProject.SomeResources", GetType ().Assembly);

    myButton.Text =resourceManager .GetString("hello",culture);

    However, then you have to compile your project everytime you want to see how a text appears on the screen. I want the value from the resx file to be visible in design view. Do you know how to do that?


    For the first, the ResourceManager works at run time. Here is the specification:

    Provides convenient access to culture-specific resources at run time.

    If you change the ResourceManager, you must compile it.

    For the second, suppose you want to add a property MyText and you want to set it at design time and save it in the resx file, you can use ResXResourceWriter/ResXResourceReader in its set/get method. And set the attribute [Browsable(true)].

    ResXResourceWriter Class:
    http://msdn.microsoft.com/en-us/library/system.resources.resxresourcewriter.aspx

    ResXResourceReader Class:
    http://msdn.microsoft.com/en-us/library/system.resources.resxresourcereader.aspx

    Best Regards

     


    Neddy Ren [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    • Proposed as answer by Neddy Ren Tuesday, November 15, 2011 7:03 AM
    • Marked as answer by Neddy Ren Thursday, November 24, 2011 8:55 AM
    Wednesday, November 9, 2011 2:48 AM