내 프로그램이 타이머가 만료되면 임의의 임베디드 오디오 파일을 재생하므로 my.resources 파일을 배열로 참조하여 리소스의 정확한 파일 이름을 알 필요가없는 방식으로 사용할 수 있습니까? ?리소스가 있습니까?
1
A
답변
2
나는 Windows 응용 프로그램에서이 시도하지 않은,하지만 난 웹 응용 프로그램에 대해 같은 일을했고, 나는 그 달성하기 위해 다음 코드를 사용 :
VB 버전 :
' get a reference to the current assembly
Dim a = Assembly.GetExecutingAssembly()
' get a list of resource names from the manifest
Dim resNames = a.GetManifestResourceNames()
'Generate a random number
Dim randomNumber = YourRandomNumberGenerator()
'Get the file name using the randomNumber
Dim randomFileNameFromResource = resNames(randomNumber)
'Get the contents of the file:
Dim sr = New StreamReader(a.GetManifestResourceStream(randomFileNameFromResource))
Dim fileContent = sr.ReadToEnd()
을 내가 더 포함 된 리소스가 추가됩니다 경우 배열에있는 파일의 위치는하지만 시간이 지남에 따라 변경 것이라고 생각,하지만 난 그게 문제가되지 않을 거라 생각
// get a reference to the current assembly
var a = Assembly.GetExecutingAssembly();
// get a list of resource names from the manifest
var resNames = a.GetManifestResourceNames();
//Generate a random number
var randomNumber = YourRandomNumberGenerator();
//Get the file name using the randomNumber
var randomFileNameFromResource = resNames[randomNumber];
//Get the contents of the file:
var sr = new StreamReader(
a.GetManifestResourceStream(randomFileNameFromResource));
var fileContent = sr.ReadToEnd();
C# 버전 어쨌든 무작위로 선택하기 때문에 당신을 위해.
0
vb2005에서 나에 대한 정답은 Reflection.Assembly.GetExecutingAssembly.GetManifestResourceNames() 프로그래머는 GET 스트림 기능 거기에,이 웹 응용 프로그램 또는 Windows 응용 프로그램입니다
관련 문제
- 1. 새로운 TextMate 리소스가 있습니까?
- 2. 물류 관련 리소스가 있습니까?
- 3. WebService에 좋은 리소스가 있습니까?
- 4. 리소스가 많은 프로젝트의 SVN - 별도의 리포지토리에 코드 및 리소스가 있습니까?
- 5. 간략하게 ANN을 설명하는 리소스가 있습니까?
- 6. StaticResource 리소스가 외부 어셈블리에 있습니까?
- 7. 페더레이션 소프트웨어에 유용한 리소스가 있습니까?
- 8. 이 jdbc 리소스가 닫혀 있습니까?
- 9. PHP XMLWriter 기능에 대한 리소스가 있습니까?
- 10. Cygwin "고급 사용자"가되기위한 리소스가 있습니까?
- 11. 코드가 어떻게 Restful을위한 리소스가 될 수 있습니까?
- 12. Windows 메모리를 철저히 설명하는 단일 리소스가 있습니까?
- 13. microsoft multipoint sdk 개발에 유용한 리소스가 있습니까?
- 14. 도/주를 도시로 매핑하기위한 온라인 리소스가 있습니까?
- 15. RegisterWindowMessage를 남용하면 리소스가 고갈 될 수 있습니까?
- 16. Direct Compute를 배우기에 좋은 웹 리소스가 있습니까?
- 17. 멋진 실버 이미지 애니메이션을위한 리소스가 있습니까?
- 18. ASP.NET AXD 리소스가 클라이언트 측에서 차단되고 있습니까?
- 19. Android 리소스가 부족한 작업
- 20. ResourceManager에 리소스가 있는지 확인하십시오.
- 21. Catalyst에 mod_perl을 이식하는 데 유용한 리소스가 있습니까? 그만한 가치가 있습니까?
- 22. Vaadin 리소스가 OSGI에로드되지 않았습니다
- 23. 리소스가 수정되면 문제가 발생합니까?
- 24. MonoTouch에서 어셈블리 리소스가 누락되었습니다.
- 25. 리소스가 있는지 확인하십시오.
- 26. SSL 인증서 '리소스가 안전하지 않습니다.'
- 27. 리소스가 필요한 문제 PHP Codeigniter
- 28. iphone 시뮬레이터 리소스가 업데이트되지 않습니다.
- 29. Java CUP 리소스가 여전히 사용됩니까?
- 30. Android 라이브러리 : 리소스가 병합되었습니다. 코드가
당신에게 로베르토 감사입니까? – 7wp
윈도우 응용 프로그램, 기본적으로 화면 보호기 및 소리가 포함 된 eggtimer – Jim