c winfrom資源檔案的呼叫和路徑全解

2021-06-17 00:32:52 字數 1773 閱讀 9792

system.diagnostics命名空間 :

string str1 =process.getcurrentprocess().mainmodule.filename;//可獲得當前執行的exe的檔名。 

system 命名空間:

string str2=environment.currentdirectory;//獲取和設定當前目錄(即該程序從中啟動的目錄)的完全限定路徑。

system.io命名空間:

string str3=directory.getcurrentdirectory();//獲取應用程式的當前工作目錄。

其他方法介紹:

1. system.diagnostics.process.getcurrentprocess().mainmodule.filename 獲取模組的完整路徑。

2. system.environment.currentdirectory 獲取和設定當前目錄(該程序從中啟動的目錄)的完全限定目錄。

3. system.io.directory.getcurrentdirectory()  獲取應用程式的當前工作目錄。這個不一定是程式從中啟動的目錄啊,有可能程式放在c:"www裡,這個函式有可能返回c:"documents and settings"zyb",或者c:"program files"adobe",有時不一定返回什麼東東,我也搞不懂了。

eg1.獲取專案資源檔案中的:

= global::工程名.properties.resources.名(沒有字尾);

另附一種方法: ?

//獲取專案中「資源檔案」的資料

assembly asm = assembly.getexecutingassembly();

resourcemanager rm =newresourcemanager("testcustomform.properties.resources", asm);

string str = rm.getstring();//新增到資源檔案的字串

image img = rm.getobject("bamboo")asimage;//新增到資源檔案的

eg2.獲取專案新增項資料夾下的htm檔案(注意:檔案屬性中生成操作得改為(嵌入的資源))不包括具體呼叫htm中具體位元組方法:

呼叫方法: 

string abouthtml = this.getstringresource("htmlpage1.htm");

messagebox.show(abouthtml);?

privatestringgetstringresource(string name)

呼叫:image.fromstream(assembly.getexecutingassembly().getmanifestresourcestream(@"testcustomform.res.button.b***own.bmp"));

其中:testcustomform為專案名稱,res為專案下的資料夾,button為res的子資料夾,b***own.bmp是檔名稱。

資源檔案的使用

學習pyqt推薦大家看這本書 第一步 new file qt resource file 第二步 add prefix建乙個字首 prefix 相當於建立乙個資料夾嘛,可以分類圖示。新增具體圖示就是add files就可以了。這裡的images這個子資料夾,你在命名的加上 images就可以了。su...

C 資源檔案

獲取資源檔案 using system using system.collections.generic using system.componentmodel using system.data using system.drawing using system.text using system...

rc資源檔案

resource complier 中詳細描述了資源檔案的編寫與使用.包括巨集的使用.舉例 在debug模式下包含乙個debugdll,在release 模式下包含另乙個releasedll ifdef debug dictionaryonlinedll.dll data debug diction...