ចំពោះអ្នកសរសេរកម្មវិធីទាំងឡាយ ដែលប្រើប្រាស់ខ្មែរយូនីកូដ នៅពេលដែលចង់ប្តូរពី Keyboard Layout english ot khmer Unicode នោះ លោកអ្នកតំរូវអោយអ្នកប្រើប្រាស់កម្មវិធីចុច alt + Shift ដើម្បីប្តូរ។ សកម្មភាពបែបនេះ វាអាចបណ្តាលអោយមានកំហុសកើតឡើងក្នុងកម្មវិធី ឧទាហរណ៍ Text box ដែលត្រូវតំរូវអោយអ្នកប្រើប្រាស់បញ្ចូលទិន្នជាលេខជាដើម ប្រសិនបើ Keyboard Layout ស្ថិតក្នុងស្ថានភាព khmer (CA or KH) នោះវាបណ្តាលអោយមានកំហុសកើតឡើង។ ដើម្បីដោះស្រាយបញ្ហានេះលោកអ្នកត្រូវប្តូរ Keyboard Layout តាមរយៈការសរសេរកូដ នៅត្រង់ព្រឹត្តិការណ៍ got Focus ទៅលើ object មួយ ។ ខាងក្រោមនេះ គឺជាគំរូកូដសំរាប់ផ្លាស់ប្តូរ Keyboard Layout ទៅជាភាសាខ្មែរ រី ជាភាសាអង់គ្លេស។
Module Module1
Public Declare Function GetKeyboardLayoutName Lib “user32″ _
Alias “GetKeyboardLayoutNameA” _
(ByVal pwszKLID As String) As Long
Public Declare Function LoadKeyboardLayout Lib “user32″ _
Alias “LoadKeyboardLayoutA” _
(ByVal pwszKLID As String, ByVal flags As Long) As Long
Const KLF_ACTIVATE = &H1
‘ some languages code
Public Const LANG_ENGLISH As String = “00000409″
Public Const LANG_FRENCH As String = “0000040C”
Public Const LANG_ARABIC As String = “00000401″
Public Const LANG_GREEK As String = “00000408″
Public Const Lang_kh As String = “a0000403″
Public Const LANG_ITALIAN As String = “00000400″
Public Const LANG_GERMAN As String = “00000407″
Public Function SwitchKeyboardLang(ByVal strLangID As String) As Boolean
‘Returns TRUE when the KeyboardLayout was set properly, FALSE otherwise
Dim strRet As String
On Error Resume Next
strRet = New String(“0″, 9)
GetKeyboardLayoutName(strRet)
If strRet = (strLangID & Chr(0)) Then
‘ you are try to switch to the already selected language
‘ so return without doing anything
SwitchKeyboardLang = True
Exit Function
Else
strRet = New String(“0″, 9)
strRet = LoadKeyboardLayout((strLangID & Chr(0)), KLF_ACTIVATE)
End If
GetKeyboardLayoutName(strRet) ‘ Test if switch successed
If strRet = (strLangID) Then
SwitchKeyboardLang = True
End If
End Function
End Module
Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Me.Text = SwitchKeyboardLang(LANG_ENGLISH)
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Me.Text = SwitchKeyboardLang(Lang_kh)
End Sub
End Class
Source: http://laingmoam.wordpress.com/2010/01/11/%E1%9E%9A%E1%9E%94%E1%9F%80%E1%9E%94%E1%9E%94%E1%9F%92%E1%9E%8F%E1%9E%BC%E1%9E%9A-keyboard-layout-%E1%9E%80%E1%9F%92%E1%9E%93%E1%9E%BB%E1%9E%84-vb-net/
No comments:
Post a Comment