本文整理汇总了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