問題:
得知應用程式所安裝的系統OS(Win32)下~
系統字型是否存在著型某種字型~
解決:
Imports System.IO
'取得環境路徑 fonts 系統字型資料夾
'.NET Framweork 4 版本之後 才有 fonts
'Dim strAns As String = Environment.GetFolderPath(Environment.SpecialFolder.fonts)
' get parent of System folder to have Windows folder
Dim dirWinFolder As DirectoryInfo = Directory.GetParent(Environment.GetFolderPath(Environment.SpecialFolder.System))
'DirectoryInfo dirWindowsFolder = Directory.GetParent(Environment.GetFolderPath(Environment.SpecialFolder.System));
' Concatenate Fonts folder onto Windows folder.
Dim strFontsFolder As String = Path.Combine(dirWinFolder.FullName, "Fonts")
'string strFontsFolder = Path.Combine(dirWindowsFolder.FullName, "Fonts");
'Results in full path e.g. "C:\Windows\Fonts"
'MsgBox(dirWinFolder.Parent.Name) 'C:\
'MsgBox(dirWinFolder.Name) 'Windows
'MsgBox(strFontsFolder) 'C:\Windows\Fonts
'判斷是否存在字型
Dim strFullPath As String = strFontsFolder & "\dftt-b5.ttf"
If File.Exists(strFullPath) Then
'MsgBox("存在!")
Else
File.Copy(Application.StartupPath & "\dftt-b5.ttf", strFullPath)
End If
備註:
因為系統載入後,當系統無應用程式所使用字型時。
即使將字型COPY到系統字型資料夾,應用程式依然是使用預設字型。
因為應用程式字型設定在於COPY之前。
第二次開始應用程式,程式才會真正LOAD到 dftt-b5.tff 字型檔。
解決辦法:
(1)在程式中解決? 如何在應用程式設置字型之前COPY到系統字型資料夾?
(2)將字型檔直接包在應用程式安裝檔,並指定字型安裝路徑為系統字型資料夾路徑。
那路徑設定怎麼設定?
(3)解決(1)辦法...(不是很好的辦法)
在COPY完成後,將所有使用到此字型的控制項 or others...
其字型指為 dftt-b5.tff,還沒試,應該可行一 一?
參考:
VS 2008
.Net 3.5
Environment.GetFolderPath Method (Environment.SpecialFolder)
How to get the path to the Windows fonts folder?
How to get the path to the Windows fonts folder?
Finding Font Filename from Font Title
Font Installation (copying file into Fonts directory from server to user's machine)
copy a font file in my programm resources to windows fonts
How do I install a font on a user's machine in VB.NET so applications like Word can use it?
VB.NET修改host文件
获取ALL USER 的特殊目录的类
如何获取系统下字体的路径?
如何判断使用者电脑中系统字型大小?
查知目前系統字型大小?
抓系統字型設定問題
取得電腦內部所有安裝字型
程式的啟動與載入
c# 獲取相對路徑
取得目前執行程式的目錄
2012年12月7日 星期五
2012年12月5日 星期三
[技巧] 透過 Win32API 的 kernel32.dll 來讀寫ini文件(設定檔)
程式:DayActivateFormWinApp.exe
Imports System.Runtime.InteropServices
Imports System.Text
'主程式
Public Class Form1
Public Shared AppIniPath = "C:\DayActivateFormWinApp.ini"
Private Sub BtnOK_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnOK.Click
Win32API.EnumWindowsDllImport(New Win32API.EnumWindowsCallback(AddressOf FillActiveWindowsList), 0)
Exit Sub
Dim hwnd As IntPtr = Win32API.FindWindow("DayCensorWinApp.DayLigoMain", vbNullString)
If hwnd = IntPtr.Zero Then
MsgBox("Not found!")
Else
MsgBox("Found!")
Win32API.WritePrivateProfileString("DayLigoMain", "程式ID", My程式ID, AppIniPath)
Win32API.WritePrivateProfileString("DayLigoMain", "MySqlWhere", MySqlWhere, AppIniPath)
Exit Sub
End If
End Sub
End Class
----分隔線----
Imports System.Runtime.InteropServices
Imports System.Text
' 用來包裝 Windows 32 API 常式和函式的類別。
Public Class Win32API
#Region "修改INI檔中內容"
''' <summary>
''' 修改INI檔中內容
''' </summary>
''' <param name="lpApplicationName">欲在其中寫入的節點名稱</param>
''' <param name="lpKeyName">欲設置的項名</param>
''' <param name="lpString">要寫入的新字串</param>
''' <param name="lpFileName">INI檔案名</param>
''' <returns>非零表示成功,零表示失敗</returns>
<DllImport("kernel32")> _
Public Shared Function WritePrivateProfileString(ByVal lpApplicationName As String, ByVal lpKeyName As String, ByVal lpString As String, ByVal lpFileName As String) As Integer
End Function
#End Region
End Class
文件:DayActivateFormWinApp.ini
[DayLigoMain]
程式ID=19
MySqlWhere=3
參考:
VB.net INI 讀寫
VB.net GetPrivateProfileString WritePrivateProfileString 读写INI
[C#.Net]调用kernel32读写ini文件
[C++]WritePrivateProfileString function (Windows)
c# extern 关键字 和 kernel32.dll中的api:WritePrivateProfileString,GetPrivateProfileString
writeprivateprofilestring (kernel32)
getprivateprofilestring (kernel32)
啟動應用程式並且傳入參數
VB.Net 讀取 INI
VB.NET配置文件存储方案-ini文件及ini文件的读写方法
用 vb.net 读写 ini 文件
Ini 檔案的讀取與寫入類別
应用程序中使用配置档
Imports System.Runtime.InteropServices
Imports System.Text
'主程式
Public Class Form1
Public Shared AppIniPath = "C:\DayActivateFormWinApp.ini"
Private Sub BtnOK_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnOK.Click
Win32API.EnumWindowsDllImport(New Win32API.EnumWindowsCallback(AddressOf FillActiveWindowsList), 0)
Exit Sub
Dim hwnd As IntPtr = Win32API.FindWindow("DayCensorWinApp.DayLigoMain", vbNullString)
If hwnd = IntPtr.Zero Then
MsgBox("Not found!")
Else
MsgBox("Found!")
Win32API.WritePrivateProfileString("DayLigoMain", "程式ID", My程式ID, AppIniPath)
Win32API.WritePrivateProfileString("DayLigoMain", "MySqlWhere", MySqlWhere, AppIniPath)
Exit Sub
End If
End Sub
End Class
----分隔線----
Imports System.Runtime.InteropServices
Imports System.Text
' 用來包裝 Windows 32 API 常式和函式的類別。
Public Class Win32API
#Region "修改INI檔中內容"
''' <summary>
''' 修改INI檔中內容
''' </summary>
''' <param name="lpApplicationName">欲在其中寫入的節點名稱</param>
''' <param name="lpKeyName">欲設置的項名</param>
''' <param name="lpString">要寫入的新字串</param>
''' <param name="lpFileName">INI檔案名</param>
''' <returns>非零表示成功,零表示失敗</returns>
<DllImport("kernel32")> _
Public Shared Function WritePrivateProfileString(ByVal lpApplicationName As String, ByVal lpKeyName As String, ByVal lpString As String, ByVal lpFileName As String) As Integer
End Function
#End Region
End Class
文件:DayActivateFormWinApp.ini
[DayLigoMain]
程式ID=19
MySqlWhere=3
參考:
VB.net INI 讀寫
VB.net GetPrivateProfileString WritePrivateProfileString 读写INI
[C#.Net]调用kernel32读写ini文件
[C++]WritePrivateProfileString function (Windows)
c# extern 关键字 和 kernel32.dll中的api:WritePrivateProfileString,GetPrivateProfileString
writeprivateprofilestring (kernel32)
getprivateprofilestring (kernel32)
啟動應用程式並且傳入參數
VB.Net 讀取 INI
VB.NET配置文件存储方案-ini文件及ini文件的读写方法
用 vb.net 读写 ini 文件
Ini 檔案的讀取與寫入類別
应用程序中使用配置档
訂閱:
文章 (Atom)