banner



How To Create Resx File In Visual Studio

Programmatically Creating a resx File

As mentioned, a *.resx file is a block of XML data that assigns name/value pairs for each resource in your application. The ResXResourceWriter class provides a set of members that allow you to create the *.resx file, add binary and string-based resources, and commit them to storage. To illustrate, let's create a simple Windows Forms application (ResXWriter) that will generate a *.resx file containing an entry for the happyDude.bmp file (first seen in the Dragginglmages example) and a single string resource. The GUI consists of a single Button type as shown in Figure 28-22.

Figure 28-22. The ResXWriter application

The Click event handler for the Button adds the happyDude.bmp and string resource to the *.resx file, which is saved on the local C drive:

Imports System.Resources

Public Class MainForm Private Sub btnGenResX_Click(ByVal sender As System.Object, _ ByVal e As System.EventArgs) Handles btnGenResX.Click ' Make a resx writer and specify the file to write to. Dim w As New ResXResourceWriter("C:\ResXForm.resx") ' Add happy dude and string. Dim bMap As New Bitmap("happyDude.bmp") w.AddResource("happyDude", bMap)

w.AddResource("welcomeString", "Hello new resource format!") ' Commit it. w.Generate() w.Close() End Sub End Class

The member of interest is ResXResourceWriter.AddResource(). This method has been overloaded a few times to allow you to insert binary data (as you did with the happyDude.bmp image), as well as textual data (as you have done for your test string). Notice that each version takes two parameters: the name of a given resource in the *.resx file and the data itself. The Generate() method commits the information to file. At this point, you have an XML description of the image and string resources. To verify, open the new ResXForm.resx file using a text editor (see Figure 28-23).

C:\ResXForm,resx - Notepad+

File Edit Search View Format Language Settings Macro Run TextFX Plugins Window ?

-aas qgniBsnEBBim^ugn^ia

IH ResXForm.resx |

104 </xsd:choice>

105 </xsd:coraplexType> </xsd: elemeno

10S <re3header name="re3mimetype">

109 <value>text/microsoft-resx</value>-

110 </resheader>

111 Cresheader name="version">

113 </resh.eader>

114 <resheader name=rreader">

<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyTolc

116 </resheader>

117 <resheader name="writer">

<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyTolc

119 </resh.eader>

120 <assembly alias="Systeia. Drawing" name="System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f!!■

121 <data name^happyDude"1 type="5ystem. Drawing.Bitmap, System. Drawing" mimetype="application/x-microsoft.net.object.b

122 <value>

123 Q k 12 A gAAAAAAAH YAAAAaAAAAIAAAA CAAAAABAAQAAAAAAAAAAADE D gAAxA4 AABAAAAAQAAAAAAAA/ wAA

124 gP8AgAD/AICA/4AAAP+AAID/glAA/4CAgP/AwMD/AAD//wD/AP8A/////wAA//8A/////wD//////wAA

125 AAAAAAAAAAAAAAAAAAAAAAAAAAC7u7u7AAAAAAAAAAAAAAu7u7u7u7uwAAAAAAAAAAC7u7u7u7u7uwAA AAAAAAC7u7u7u7u7u7u7AAAAAAALu7u7uwAAu7u7u7AAAAAAu7u7u7CZmQu7u7u7AAAAALu7u7sJmZmQ

127 u7u7uwAAAAu7u7uwkAAACQu7u7uwAAC7u7u7AAu7u7AAu7u7uwAAu7u7sAu7u7u7sAu7u7sAALu7u7C7

128 u7u7u73Lu7u7AAu7u73Lu7u7u7u73Lu7u7ALuwAAu7u7u7u7u73AALuwC7u75Lu7u7u7u7u7C7u73Au7

129 u7sLu7u7u7u7sLu7u7ALu7u7C7u7u7u7u7C7u7uwC7u7u7uwC7u7sAu7u7u7sAu7u7u7AAC7uwAAu7u7

130 u7Alu7u7uwAAu7sAALu7u7uwAiu7u7sAAlu7AAC7u7u7AAC7u7u7AAC7uwAAu7u7uwAAu7u7uwAAu7sA

131 ALu7 u 7 sAAAu 7 u7uwC 7 u7 sAu 7 u7uwAAAAu 7 u 7u7u 7 u 7u7u 7 u 7AAAAAL u7u7u7u7u7u7u7uwAAAAALu7u7

132 u7u7u7u7u7AAAAAAALu7u7u7u7u7u73AAAAAAAAAu7u7u7u7u7sAAAAAAAAAAAu7u7u7u7uwAAAAAAAA

133 AAAAALu7u7sAAAAAAAAAAAAAAAAAAAAAAAAAAAAA

136 <data narae="welcome5tring" xml: space="preserve"'>

<value>Hello new resource format!</value>

Continue reading here: Building the resources File

Was this article helpful?

How To Create Resx File In Visual Studio

Source: https://www.visualbasicplanet.info/visual-studio-2/programmatically-creating-a-resx-file.html

Posted by: vanburenenced1969.blogspot.com

0 Response to "How To Create Resx File In Visual Studio"

Post a Comment

Iklan Atas Artikel

Iklan Tengah Artikel 1

Iklan Tengah Artikel 2

Iklan Bawah Artikel