本文整理匯總了VB.NET中System.Resources.ResourceManager類的典型用法代碼示例。如果您正苦於以下問題:VB.NET ResourceManager類的具體用法?VB.NET ResourceManager怎麽用?VB.NET ResourceManager使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
在下文中一共展示了ResourceManager類的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的VB.NET代碼示例。
示例1: Example
' 導入命名空間
Imports System.Resources
Imports System.Reflection
Imports System.Threading
Imports System.Globalization
Class Example
Public Shared Sub Main()
Dim day As String
Dim year As String
Dim holiday As String
Dim celebrate As String = "{0} will occur on {1} in {2}." & vbCrLf
' Create a resource manager.
Dim rm As New ResourceManager("rmc", GetType(Example).Assembly)
Console.WriteLine("Obtain resources using the current UI culture.")
' Get the resource strings for the day, year, and holiday
' using the current UI culture.
day = rm.GetString("day")
year = rm.GetString("year")
holiday = rm.GetString("holiday")
Console.WriteLine(celebrate, holiday, day, year)
' Obtain the es-MX culture.
Dim ci As New CultureInfo("es-MX")
Console.WriteLine("Obtain resources using the es-MX culture.")
' Get the resource strings for the day, year, and holiday
' using the es-MX culture.
day = rm.GetString("day", ci)
year = rm.GetString("year", ci)
holiday = rm.GetString("holiday", ci)
' ---------------------------------------------------------------
' Alternatively, comment the preceding 3 code statements and
' uncomment the following 4 code statements:
' ----------------------------------------------------------------
' Set the current UI culture to "es-MX" (Spanish-Mexico).
' Thread.CurrentThread.CurrentUICulture = ci
' Get the resource strings for the day, year, and holiday
' using the current UI culture.
' day = rm.GetString("day")
' year = rm.GetString("year")
' holiday = rm.GetString("holiday")
' ---------------------------------------------------------------
' Regardless of the alternative that you choose, display a message
' using the retrieved resource strings.
Console.WriteLine(celebrate, holiday, day, year)
End Sub
End Class
輸出:
Obtain resources using the current UI culture. "5th of May" will occur on Friday in 2006. Obtain resources using the es-MX culture. "Cinco de Mayo" will occur on Viernes in 2006.
示例2: Example
' 導入命名空間
Imports System.Resources
Module Example
Public Sub Main()
Dim rm As New ResourceManager("Strings", GetType(Example).Assembly)
Dim timeString As String = rm.GetString("TimeHeader")
Console.WriteLine("{0} {1:T}", timeString, Date.Now)
End Sub
End Module
輸出:
The current time is 2:03:14 PM
示例3: Example
' 導入命名空間
Imports System.Globalization
Imports System.Resources
Imports System.Threading
Module Example
Sub Main()
' Create array of supported cultures
Dim cultures() As String = {"en-CA", "en-US", "fr-FR", "ru-RU" }
Dim rnd As New Random()
Dim cultureNdx As Integer = rnd.Next(0, cultures.Length)
Dim originalCulture As CultureInfo = Thread.CurrentThread.CurrentCulture
Dim rm As New ResourceManager("Greetings", GetType(Example).Assembly)
Try
Dim newCulture As New CultureInfo(cultures(cultureNdx))
Thread.CurrentThread.CurrentCulture = newCulture
Thread.CurrentThread.CurrentUICulture = newCulture
Dim greeting As String = String.Format("The current culture is {0}.{1}{2}",
Thread.CurrentThread.CurrentUICulture.Name,
vbCrLf, rm.GetString("HelloString"))
Console.WriteLine(greeting)
Catch e As CultureNotFoundException
Console.WriteLine("Unable to instantiate culture {0}", e.InvalidCultureName)
Finally
Thread.CurrentThread.CurrentCulture = originalCulture
Thread.CurrentThread.CurrentUICulture = originalCulture
End Try
End Sub
End Module
輸出:
The current culture is ru-RU. Всем привет!
示例4: Example
' 導入命名空間
Imports System.Globalization
Imports System.Resources
Imports System.Threading
<Assembly:NeutralResourcesLanguage("en")>
Module Example
Public Sub Main()
Dim cultureNames() As String = { "en-US", "fr-FR", "ru-RU", "sv-SE" }
Dim rm As New ResourceManager("DateStrings",
GetType(Example).Assembly)
For Each cultureName In cultureNames
Dim culture As CultureInfo = CultureInfo.CreateSpecificCulture(cultureName)
Thread.CurrentThread.CurrentCulture = culture
Thread.CurrentThread.CurrentUICulture = culture
Console.WriteLine("Current UI Culture: {0}",
CultureInfo.CurrentUICulture.Name)
Dim dateString As String = rm.GetString("DateStart")
Console.WriteLine("{0} {1:M}.", dateString, Date.Now)
Console.WriteLine()
Next
End Sub
End Module
輸出:
Current UI Culture: en-US Today is February 03. Current UI Culture: fr-FR Aujourd'hui, c'est le 3 février Current UI Culture: ru-RU Сегодня февраля 03. Current UI Culture: sv-SE Today is den 3 februari.
示例5: Main
' 導入命名空間
Imports System.IO
Imports System.Reflection
Imports System.Resources
Module Example
Public Sub Main()
If Environment.GetCommandLineArgs.Length = 1 Then
Console.WriteLine("No filename.")
Exit Sub
End If
Dim filename As String = Environment.GetCommandLineArgs(1).Trim()
' Check whether the file exists.
If Not File.Exists(filename) Then
Console.WriteLine("{0} does not exist.", filename)
Exit Sub
End If
' Try to load the assembly.
Dim assem As Assembly = Assembly.LoadFrom(filename)
Console.WriteLine("File: {0}", filename)
' Enumerate the resource files.
Dim resNames() As String = assem.GetManifestResourceNames()
If resNames.Length = 0 Then
Console.WriteLine(" No resources found.")
End If
For Each resName In resNames
Console.WriteLine(" Resource: {0}", resName.Replace(".resources", ""))
Next
Console.WriteLine()
End Sub
End Module