using System.ComponentModel; using System.Windows.Forms; namespace MyNamespace { public partial class MyForm : Form { // Resource manager private static readonly ComponentResourceManager resources = new ComponentResourceManager(typeof(MyForm)); public MyForm() { InitializeComponent(); this.Text = resources.GetString("$this.Text"); this.pictureBox.Image = (Image)resources.GetObject("pictureBox.Image"); } } }
using System.ComponentModel; using System.Drawing; using System.Windows.Forms; namespace MyNamespace { public partial class MyControl : UserControl { private static readonly ComponentResourceManager resources = new ComponentResourceManager(typeof(MyControl)); public MyControl() { InitializeComponent(); this.BackColor = (Color)resources.GetObject("$this.BackColor"); this.button.Text = resources.GetString("button.Text"); } } }In this example, we are using the ComponentResourceManager to retrieve the background color and a button text from the resource file. Package library: This class is part of the .NET Framework Class Library, which is included in the .NET runtime environment.