从“添加现有项”对话框中选择上一小节编译出来的resource.dll,
窗口设计界面:
具体代码:
2、建立两个窗体级的变量用来记录使用的字符串和图片的编号:
Dim picIndex As Integer Dim strIndex As Integer
3、当窗体载入的时候,使编号为1
Private Sub Form1_Load(sender As Object,e As EventArgs) Handles MyBase.Load picIndex = 1 strIndex = 1 End Sub
Private Sub Button1_Click(sender As Object,e As EventArgs) Handles Button1.Click Dim myResource As Assembly myResource = Assembly.LoadFile(Application.StartupPath & "\" & "resource.dll") Dim myResourceManager As System.Resources.ResourceManager myResourceManager = New System.Resources.ResourceManager("resource.Resource1",myResource) Dim myPic As Bitmap Dim resourceName As String resourceName = "Pic" & picIndex If picIndex = 1 Then picIndex = 2 Else picIndex = 1 myPic = myResourceManager.Getobject(resourceName) PictureBox1.Image = myPic End Sub
5、字符串资源的调用
Private Sub Button2_Click(sender As Object,e As EventArgs) Handles Button2.Click Dim myResource As Assembly myResource = Assembly.LoadFile(Application.StartupPath & "\" & "resource.dll") Dim myResourceManager As System.Resources.ResourceManager myResourceManager = New System.Resources.ResourceManager("resource.Resource1",myResource) Dim myString As String Dim resourceName As String resourceName = "String" & strIndex If strIndex = 1 Then strIndex = 2 Else strIndex = 1 myString = myResourceManager.GetString(resourceName) TextBox1.Text = myString End Sub
运行结果如图:
由于.net平台下C#和vb.NET很相似,本文也可以为C#爱好者提供参考。
学习更多vb.net知识,请参看vb.net 教程 目录
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。