캬캬캬
엄청나게 무식하다고 욕하지 마시라...
기존 Resources 에 포함되어 있는 Resource 들을 보면 아래 와 같은 이미지들이 포함되어 있습니다.
번호로되어있는 파일들이 보일텐데요...
그 Resource 들을 파일 이름으로 조회를 해야할 일이 발생했습니다.
xml 데이터를 이용해서 imageList 객체를 만들려고 하는데 먼저 imageList 객체에 image 를 어떻게 추가할 수 있는지 MSDN Document 를 찾아보면...
Paramenter 를 보면 string 형의 Key 값과 Bitmap 형의 image 가 필요한데...
Key 는 XML 파일에서 가져오고... XML 에 있는 데이터를 바탕으로 Resource 에 등록되어 있는 이미지를 가져올 계획이었다.
참고로 XML 파일에는 이런식으로 되어 있다.
15 <PlayerTypes>
16 <PlayerType category="Default" value ="0" enable="True" Default="True">Transparent</PlayerType>
17 <PlayerType category="Normal" value ="10" enable="True">일반-검정</PlayerType>
18 <PlayerType category="Normal" value ="11" enable="True">일반-파랑</PlayerType>
19 <PlayerType category="Normal" value ="12" enable="True">일반-빨강</PlayerType>
20 <PlayerType category="Normal" value ="13" enable="True">일반-초록</PlayerType>
21 <PlayerType category="Normal" value ="14" enable="True">일반-하늘색</PlayerType>
22 <PlayerType category="PopUp" value ="20" enable="False">팝업-검정</PlayerType>
23 <PlayerType category="PopUp" value ="21" enable="False">팝업-파랑</PlayerType>
24 <PlayerType category="PopUp" value ="22" enable="False">팝업-빨강</PlayerType>
25 <PlayerType category="PopUp" value ="23" enable="False">팝업-초록</PlayerType>
26 <PlayerType category="PopUp" value ="24" enable="False">팝업-하늘색</PlayerType>
27 <PlayerType category="SimpleCircle" value ="30" enable="True">단순 원형-파랑</PlayerType>
28 <PlayerType category="SimpleCircle" value ="31" enable="True">단순 원형-빨강</PlayerType>
29 <PlayerType category="SimpleCircle" value ="32" enable="True">단순 원형-검정</PlayerType>
30 <PlayerType category="SimpleSquare" value ="40" enable="True">단순 사각-파랑</PlayerType>
31 <PlayerType category="SimpleSquare" value ="41" enable="True">단순 사각-빨강</PlayerType>
32 <PlayerType category="SimpleSquare" value ="42" enable="True">단순 사각-검정</PlayerType>
33 </PlayerTypes>
그렇다면 이제 Assembly 에 있는 Resource 에 접근하는 방법을 알아봐야 할텐데...
"Show All Files" 아이콘을 클릭하면 숨겨져 있는 파일을 모두 볼수 있는데.. Assembly 전체에서 사용하는 Resources.resx 의 Designer code 파일을 보도록 하자...(Resources.Designer.vb)
이 파일을 열어보면... 아래와 같이 Resource 들을 접근하기위한 Property 가 주~~욱 나열되어 있는 것을 확인할 수 있다.
63 Friend ReadOnly Property _10() As System.Drawing.Bitmap
64 Get
65 Dim obj As Object = ResourceManager.GetObject("_10", resourceCulture)
66 Return CType(obj,System.Drawing.Bitmap)
67 End Get
68 End Property
69
70 Friend ReadOnly Property _11() As System.Drawing.Bitmap
71 Get
72 Dim obj As Object = ResourceManager.GetObject("_11", resourceCulture)
73 Return CType(obj,System.Drawing.Bitmap)
74 End Get
75 End Property
76
77 Friend ReadOnly Property _12() As System.Drawing.Bitmap
78 Get
79 Dim obj As Object = ResourceManager.GetObject("_12", resourceCulture)
80 Return CType(obj,System.Drawing.Bitmap)
81 End Get
82 End Property
83
84 Friend ReadOnly Property _13() As System.Drawing.Bitmap
85 Get
86 Dim obj As Object = ResourceManager.GetObject("_13", resourceCulture)
87 Return CType(obj,System.Drawing.Bitmap)
88 End Get
89 End Property
이 파일은 어떤 녀석이 만들어 주느냐?
위 그림처럼... Resources.resx 파일을 클릭해보면 아래 Properties 창에 "Custom Tool" 이라는 항목이 나오는데...
값을 보면... VbMyResourcesResXFileCodeGenerator 라는 녀석이 있는데...
바로 이녀석이 자동적으로 Generating 해주는 역할을 한다.
이 녀석이 Resource 의 이름. 즉, String 을 건네주면 값을 반환하는 Function 같은 것을 지원해주면 좋으련만...
그런 함수를 지원하지 않기 때문에...
내가 손으로 직접 만들어 주려고 한다. ㅋㅋㅋ
그럴려면...
VisualBasic.NET 의 경우 Resource 에 어떻게 접근할까?
위에서 봤듯이... Custome Tool 에 의해서 쉽게 접근 할 수 있다..
VisualBasic.Net 의 경우 My Namespace 를 사용하면 쉽게? 접근할 수 있는데...
Dim img As System.Drawing.Image = My.Resources._10
이런식으로 하면 바로 이미지를 가져올 수 있다.
하지만 나는 XML 파일의 String 값을 기반으로 실행을 하려고 했으므로...
VbMyResourcesResXFileCodeGenerator 라는 녀석이 만들어낸 "Resources.Designer.vb" 파일을 참고삼아..
모듈을 만들고 몸뚱이에... 함수를 추가하여 엇비슷하게 사용할까 한다. ㅋㅋㅋ
(완전 단순 무식... ^^')
그 단순무식의 실체는 아래와 같다...
ㅋㅋㅋ
1 Option Strict On
2 Option Explicit On
3
4 Imports System
5
6 Namespace My.Resources
7
8 <Global.System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0"), _
9 Global.System.Diagnostics.DebuggerNonUserCodeAttribute(), _
10 Global.System.Runtime.CompilerServices.CompilerGeneratedAttribute(), _
11 Global.Microsoft.VisualBasic.HideModuleNameAttribute()> _
12 Module Resources_Partial
13
14 Private resourceMan As Global.System.Resources.ResourceManager
15
16 Private resourceCulture As Global.System.Globalization.CultureInfo
17
18 '''<summary>
19 ''' Returns the cached ResourceManager instance used by this class.
20 '''</summary>
21 <Global.System.ComponentModel.EditorBrowsableAttribute(Global.System.ComponentModel.EditorBrowsableState.Advanced)> _
22 Friend ReadOnly Property ResourceManager() As Global.System.Resources.ResourceManager
23 Get
24 If Object.ReferenceEquals(resourceMan, Nothing) Then
25 Dim temp As Global.System.Resources.ResourceManager = New Global.System.Resources.ResourceManager("woojjaApplication.Resources", GetType(Resources).Assembly)
26 resourceMan = temp
27 End If
28 Return resourceMan
29 End Get
30 End Property
31
32 '''<summary>
33 ''' Overrides the current thread's CurrentUICulture property for all
34 ''' resource lookups using this strongly typed resource class.
35 '''</summary>
36 <Global.System.ComponentModel.EditorBrowsableAttribute(Global.System.ComponentModel.EditorBrowsableState.Advanced)> _
37 Friend Property Culture() As Global.System.Globalization.CultureInfo
38 Get
39 Return resourceCulture
40 End Get
41 Set(ByVal value As Global.System.Globalization.CultureInfo)
42 resourceCulture = value
43 End Set
44 End Property
45
46 Public Function GetBitmapByName(ByVal strName As String) As System.Drawing.Bitmap
47
48 Dim obj As Object = ResourceManager.GetObject(strName, resourceCulture)
49 Return CType(obj, System.Drawing.Bitmap)
50
51 End Function
52
53 Public Function GetStringByName(ByVal strName As String) As String
54
55 Dim obj As Object = ResourceManager.GetObject(strName, resourceCulture)
56 Return CType(obj, String)
57
58 End Function
59
60 End Module
61 End Namespace
62
GetBitmapByName() 과 GetStringByName() 이라는 함수가 추가된 것을 볼 수 있을 것이다.
함수의 Parameter에 strName 과 Type 을 던지는 것도 한가지 방법일 것이다.
그건 여러분이 선택할 사항이고... ㅋㅋ
Reflection 을 사용하여 원하는 값을 가져올 수도 있겠지만...
그 정도로 값을 동적으로 가져와야 할 사항은 아닌 까닭에 한번 만들어 보았다. ^^;
행복한 고수되십시요...
woojja ))*
\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
'.NET > VB.NET' 카테고리의 다른 글
[VB.NET] Embedded Resource 로 포함된 image 를 imageList Control 에 넣기 (2) | 2011.06.01 |
---|---|
[VB.NET] Application UAC 상승시키기. (4) | 2011.05.24 |
[VB.NET] XML File 을 Embedded Resource 로 등록해 사용하는 방법 (0) | 2011.03.30 |
[VB.NET] Visual Basic for Windows Phone Developer Tools - RTW (0) | 2010.12.17 |
[VB.NET] 2010 WorldCup Pass Counter (2) | 2010.06.17 |